added load-... scripts

This commit is contained in:
Lockszmith (kateryna) 2024-09-19 10:42:59 -04:00
parent 88252d2c29
commit 42280c01b9
2 changed files with 97 additions and 0 deletions

View File

@ -0,0 +1,38 @@
#! /usr/bin/env bash
# Helper function
is_sourced() {
if [ -n "$ZSH_VERSION" ]; then
case $ZSH_EVAL_CONTEXT in *:file:*) return 0;; esac
else # Add additional POSIX-compatible shell names here, if needed.
case ${0##*/} in dash|-dash|bash|-bash|ksh|-ksh|sh|-sh) return 0;; esac
fi
return 1; # NOT sourced.
}
BASE_0=${BASE_0:-$0}
BASE_SHELL=$(basename "$SHELL")
if is_sourced; then
starship() {
if [[ ! -x "$HOME/bin/starship" ]]; then
curl -sS https://starship.rs/install.sh | FORCE=1 BIN_DIR="$HOME/bin" sh > /dev/null
fi
"$HOME/bin/starship" "${@}"
}
# shellcheck disable=SC1090
. <( starship init "$BASE_SHELL" ) 2> /dev/null
. <( starship completions ${BASE_SHELL} ) 2> /dev/null
elif [[ "$1" == '-' ]]; then
echo "BASE_0=${BASE_0}"
cat "${0}"
else
SCRIPT_NAME="$BASE_0"
printf '%s\n' \
"It seems $SCRIPT_NAME was invoked as a script. It should be sourced instead." \
'The easiest way is to call it like this:' \
" $ . <( $SCRIPT_NAME - ) # Note the '-' after the script's name" \
''
fi

View File

@ -0,0 +1,59 @@
#! /usr/bin/env bash
# Helper function
is_sourced() {
if [ -n "$ZSH_VERSION" ]; then
case $ZSH_EVAL_CONTEXT in *:file:*) return 0;; esac
else # Add additional POSIX-compatible shell names here, if needed.
case ${0##*/} in dash|-dash|bash|-bash|ksh|-ksh|sh|-sh) return 0;; esac
fi
return 1; # NOT sourced.
}
BASE_0=${BASE_0:-$0}
BASE_SHELL=$(basename "$SHELL")
if is_sourced; then
zellij-cleanup() {
[[ -r "$HOME/bin/zellij" ]] && rm "$HOME/bin/zellij"
[[ -d "$HOME/.cache/zellij" ]] && rm -fR "$HOME/.cache/zellij"
[[ -d /tmp/zellij ]] && rm -fR /tmp/zellij
printf 'Zellij has been cleaned up, you can now reinstall it.\n'
}
zellij() {
if [[ ! -x ~/bin/zellij ]]; then
if [[ ! -x /tmp/zellij/bootstrap/zellij ]]; then
bash <(curl -sL zellij.dev/launch) "${@}" && return
fi
fi
if [[ -e /tmp/zellij/bootstrap/zellij ]]; then
mv /tmp/zellij/bootstrap/zellij ~/bin/zellij
rm -fR /tmp/zellij
fi
if [[ -x ~/bin/zellij ]]; then
~/bin/zellij "${@}"
fi
}
if [[ "${BASE_SHELL}" == "zsh" ]]; then
. <( zellij setup --generate-completion zsh | sed -Ee 's/^(_(zellij) ).*/compdef \1\2/' )
else
. <( zellij setup --generate-completion "$BASE_SHELL" )
fi
# Was needed when zsh would load
# . <( zellij setup --generate-completion "$BASE_SHELL" | sed -ne '/^function/,$p' )
if [[ -z "$ZELLIJ_SESSION_NAME" ]]; then
zellij attach -c $USER@$(hostname)
fi
elif [[ "$1" == '-' ]]; then
cat "${BASH_SOURCE[0]}"
else
SCRIPT_NAME="$BASE_0"
printf '%s\n' \
"It seems $SCRIPT_NAME was invoked as a script. It should be sourced instead." \
'The easiest way is to call it like this:' \
" $ . <( $SCRIPT_NAME - ) # Note the '-' after the script's name" \
''
fi