revamped load-fzf and load-zellij
This commit is contained in:
parent
a18b8506a4
commit
367e634527
24
load-fzf
24
load-fzf
|
@ -1,7 +1,21 @@
|
||||||
#! /usr/bin/env bash
|
#! /usr/bin/env bash
|
||||||
|
# shellcheck disable=SC2034,SC1090
|
||||||
|
# SC2034 variables appear unsued. export if used externally
|
||||||
|
# - uneeded, as this checked whether script is sourced
|
||||||
|
# SC1090 Can't follow non-constant source
|
||||||
|
|
||||||
BASE_0="$(basename ${0#-})"
|
# Helper function
|
||||||
BASE_SHELL="$(basename "$SHELL")"
|
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 [[ "$1" == "--force" ]]; then
|
if [[ "$1" == "--force" ]]; then
|
||||||
[[ -e ~/.local/bin/fzf ]] && rm ~/.local/bin/fzf
|
[[ -e ~/.local/bin/fzf ]] && rm ~/.local/bin/fzf
|
||||||
|
@ -12,11 +26,12 @@ fi
|
||||||
if [[ -z "$(type -t fzf)" || ! -e "$(type -p fzf)" ]]; then
|
if [[ -z "$(type -t fzf)" || ! -e "$(type -p fzf)" ]]; then
|
||||||
curl -sS https://webi.sh/fzf | bash >&2
|
curl -sS https://webi.sh/fzf | bash >&2
|
||||||
|
|
||||||
|
# shellcheck disable=SC2016 # $ inside single quotes is intentional
|
||||||
printf '%s\n' \
|
printf '%s\n' \
|
||||||
'Run the following and then try again:' \
|
'Run the following and then try again:' \
|
||||||
' exec $SHELL -l' \
|
' exec $SHELL -l' \
|
||||||
'' >&2
|
'' >&2
|
||||||
elif [[ -z "${BASE_0}" || "${BASE_0}" == "$BASE_SHELL" ]]; then
|
elif is_sourced; then
|
||||||
|
|
||||||
FZF_CTRL_T_COMMAND="command find -L . -xdev -mindepth 1 \\( \
|
FZF_CTRL_T_COMMAND="command find -L . -xdev -mindepth 1 \\( \
|
||||||
-path '*/\\.*' \
|
-path '*/\\.*' \
|
||||||
|
@ -28,6 +43,9 @@ elif [[ -z "${BASE_0}" || "${BASE_0}" == "$BASE_SHELL" ]]; then
|
||||||
-o -type l -print 2> /dev/null | cut -b3- \
|
-o -type l -print 2> /dev/null | cut -b3- \
|
||||||
"
|
"
|
||||||
|
|
||||||
|
# shellcheck disable=SC2034
|
||||||
|
# variable appears unsued. export if used externally
|
||||||
|
# - uneeded, as script is sourced
|
||||||
FZF_ALT_C_COMMAND="command find -L . -xdev -mindepth 1 \\( \
|
FZF_ALT_C_COMMAND="command find -L . -xdev -mindepth 1 \\( \
|
||||||
-path '*/\\.*' \
|
-path '*/\\.*' \
|
||||||
-xdev \
|
-xdev \
|
||||||
|
|
31
load-zellij
31
load-zellij
|
@ -1,9 +1,19 @@
|
||||||
#! /usr/bin/env bash
|
#! /usr/bin/env bash
|
||||||
|
|
||||||
BASE_0="$(basename ${0#-})"
|
# Helper function
|
||||||
BASE_SHELL="$(basename "$SHELL")"
|
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() {
|
zellij() {
|
||||||
if [[ -x /tmp/zellij/bootstrap/zellij ]]; then
|
if [[ -x /tmp/zellij/bootstrap/zellij ]]; then
|
||||||
/tmp/zellij/bootstrap/zellij "${@}"
|
/tmp/zellij/bootstrap/zellij "${@}"
|
||||||
|
@ -11,13 +21,22 @@ if [[ -z "${BASE_0}" || "${BASE_0}" == "$BASE_SHELL" ]]; then
|
||||||
bash <(curl -sL zellij.dev/launch) "${@}"
|
bash <(curl -sL zellij.dev/launch) "${@}"
|
||||||
fi
|
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' \
|
||||||
|
|
Loading…
Reference in New Issue