Compare commits

..

No commits in common. "b243ed34ff4e1e99cd8486a0d2c0ebf24810d5cd" and "59c4f003a53ca600afe5eba99ae47c5074cb6676" have entirely different histories.

2 changed files with 24 additions and 27 deletions

View File

@ -4,25 +4,21 @@
# - uneeded, as this checked whether script is sourced # - uneeded, as this checked whether script is sourced
# SC1090 Can't follow non-constant source # SC1090 Can't follow non-constant source
# User basename instead of ${0:##*/} to be POSIX compliant
BASE_0=${BASE_0:-$(basename $0)}
SCRIPT_DIR=${SCRIPT_DIR:-"$( cd -- "$( dirname -- "$0" )" &> /dev/null && pwd )"}
BASE_SHELL=$(basename "$SHELL")
# Helper function # Helper function
is_sourced() { is_sourced() {
if [ -n "$ZSH_VERSION" ]; then if [ -n "$ZSH_VERSION" ]; then
case $ZSH_EVAL_CONTEXT in *:file:*) return 0;; esac case $ZSH_EVAL_CONTEXT in *:file:*) return 0;; esac
else else # Add additional POSIX-compatible shell names here, if needed.
# case ${0##*/} in dash|-dash|bash|-bash|ksh|-ksh|sh|-sh) return 0;; esac case ${0##*/} in dash|-dash|bash|-bash|ksh|-ksh|sh|-sh) return 0;; esac
case "$(basename $0)" in $BASE_SHELL|-$BASE_SHELL) return 0;; esac
fi fi
return 1; # NOT sourced. return 1; # NOT sourced.
} }
BASE_0=${BASE_0:-$0}
BASE_SHELL=$(basename "$SHELL")
if is_sourced; then if is_sourced; then
# This part is sourced, and might run in a non-bash shell
DBG_="Is Sourced" DBG_="Is Sourced"
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASE_0}" )" &> /dev/null && pwd )
USER_HOME=$HOME USER_HOME=$HOME
[[ -n "${SUDO_USER}" ]] && USER_HOME="$(eval "echo ~${SUDO_USER}")" [[ -n "${SUDO_USER}" ]] && USER_HOME="$(eval "echo ~${SUDO_USER}")"
@ -105,7 +101,7 @@ if is_sourced; then
} }
fi fi
elif [[ "$1" == '-' ]]; then elif [[ "$1" == '-' ]]; then
printf 'BASE_0="%s"\nSCRIPT_DIR=%s\n' "${BASE_0}" "${SCRIPT_DIR}" printf 'BASE_0="%s"\n' "${BASE_0}"
cat "${BASH_SOURCE[0]}" cat "${BASH_SOURCE[0]}"
else else
SCRIPT_NAME="$BASE_0" SCRIPT_NAME="$BASE_0"

View File

@ -15,26 +15,28 @@ BASE_SHELL=$(basename "$SHELL")
if is_sourced; then if is_sourced; then
zellij() { zellij() {
if [[ ! -x ~/bin/zellij ]]; then if [[ -x /tmp/zellij/bootstrap/zellij ]]; then
if [[ ! -x /tmp/zellij/bootstrap/zellij ]]; then /tmp/zellij/bootstrap/zellij "${@}"
bash <(curl -sL zellij.dev/launch) "${@}" && return else
bash <(curl -sL zellij.dev/launch) "${@}"
fi fi
fi
if [[ -e /tmp/zellij/bootstrap/zellij ]]; then
mv /tmp/zellij/bootstrap/zellij ~/bin/zellij
fi
if [[ -x ~/bin/zellij ]]; then
~/bin/zellij "${@}"
fi
} }
. <( zellij setup --generate-completion "$BASE_SHELL" )
if [[ -z "$ZELLIJ_SESSION_NAME" ]]; then if [[ -z "$ZELLIJ_SESSION_NAME" ]]; then
(zellij list-sessions 2&>1) > /dev/null || zellij attach -c $USER@$(hostname) # shellcheck disable=SC2210
#(zellij list-sessions 2&>1) > /dev/null || zellij attach -c "$USER@$(hostname)"
zellij attach -c "$USER@$(hostname)" || EXITCODE=$?
# shellcheck disable=SC2086 # EXITCODE might be empty
return $EXITCODE
fi
if [[ -z "$ZSH_VERSION" ]] || (type compdef > /dev/null 2>&1); then
# shellcheck disable=SC1090
. <( zellij setup --generate-completion "$BASE_SHELL" ) 2> /dev/null
fi fi
elif [[ "$1" == '-' ]]; then elif [[ "$1" == '-' ]]; then
cat "${BASH_SOURCE[0]}" echo "BASE_0=${BASE_0}"
cat "${0}"
else else
SCRIPT_NAME="$BASE_0" SCRIPT_NAME="$BASE_0"
printf '%s\n' \ printf '%s\n' \
@ -43,4 +45,3 @@ else
" $ . <( $SCRIPT_NAME - ) # Note the '-' after the script's name" \ " $ . <( $SCRIPT_NAME - ) # Note the '-' after the script's name" \
'' ''
fi fi