2023-11-08 23:47:13 +00:00
|
|
|
#! /usr/bin/env bash
|
|
|
|
|
2024-04-30 03:23:19 +00:00
|
|
|
# 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")
|
2023-11-08 23:47:13 +00:00
|
|
|
|
2024-04-30 03:23:19 +00:00
|
|
|
if is_sourced; then
|
2023-11-08 23:47:13 +00:00
|
|
|
zellij() {
|
2024-05-20 11:10:58 +00:00
|
|
|
if [[ ! -x ~/bin/zellij ]]; then
|
|
|
|
if [[ ! -x /tmp/zellij/bootstrap/zellij ]]; then
|
|
|
|
bash <(curl -sL zellij.dev/launch) "${@}" && return
|
|
|
|
fi
|
2023-11-08 23:47:13 +00:00
|
|
|
fi
|
2024-05-20 11:10:58 +00:00
|
|
|
if [[ -e /tmp/zellij/bootstrap/zellij ]]; then
|
|
|
|
mv /tmp/zellij/bootstrap/zellij ~/bin/zellij
|
|
|
|
fi
|
|
|
|
if [[ -x ~/bin/zellij ]]; then
|
|
|
|
~/bin/zellij "${@}"
|
|
|
|
fi
|
|
|
|
|
2023-11-08 23:47:13 +00:00
|
|
|
}
|
2024-05-20 11:10:58 +00:00
|
|
|
. <( zellij setup --generate-completion "$BASE_SHELL" )
|
2023-11-08 23:47:13 +00:00
|
|
|
if [[ -z "$ZELLIJ_SESSION_NAME" ]]; then
|
2024-05-20 11:10:58 +00:00
|
|
|
(zellij list-sessions 2&>1) > /dev/null || zellij attach -c $USER@$(hostname)
|
2023-11-08 23:47:13 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
elif [[ "$1" == '-' ]]; then
|
2024-05-20 11:10:58 +00:00
|
|
|
cat "${BASH_SOURCE[0]}"
|
2023-11-08 23:47:13 +00:00
|
|
|
else
|
|
|
|
SCRIPT_NAME="$BASE_0"
|
|
|
|
printf '%s\n' \
|
|
|
|
"It seems $SCRIPT_NAME was invoked as a script. It should be sourced instead." \
|
2024-05-20 11:10:58 +00:00
|
|
|
'The easiest way is to call it like this:' \
|
|
|
|
" $ . <( $SCRIPT_NAME - ) # Note the '-' after the script's name" \
|
2023-11-08 23:47:13 +00:00
|
|
|
''
|
|
|
|
fi
|
2024-05-20 11:10:58 +00:00
|
|
|
|