revamped load-fzf and load-zellij

This commit is contained in:
Lockszmith 2024-04-29 23:23:19 -04:00
parent a18b8506a4
commit 367e634527
2 changed files with 46 additions and 9 deletions

View file

@ -1,9 +1,19 @@
#! /usr/bin/env bash
BASE_0="$(basename ${0#-})"
BASE_SHELL="$(basename "$SHELL")"
# 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.
}
if [[ -z "${BASE_0}" || "${BASE_0}" == "$BASE_SHELL" ]]; then
BASE_0=${BASE_0:-$0}
BASE_SHELL=$(basename "$SHELL")
if is_sourced; then
zellij() {
if [[ -x /tmp/zellij/bootstrap/zellij ]]; then
/tmp/zellij/bootstrap/zellij "${@}"
@ -11,13 +21,22 @@ if [[ -z "${BASE_0}" || "${BASE_0}" == "$BASE_SHELL" ]]; then
bash <(curl -sL zellij.dev/launch) "${@}"
fi
}
. <( zellij setup --generate-completion "$BASE_SHELL" )
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
elif [[ "$1" == '-' ]]; then
cat "${BASH_SOURCE[0]}"
echo "BASE_0=${BASE_0}"
cat "${0}"
else
SCRIPT_NAME="$BASE_0"
printf '%s\n' \