From c386ab3ef721009a05e43be8b4f4af7bcd359fc6 Mon Sep 17 00:00:00 2001 From: "Lockszmith (kateryna)" Date: Mon, 20 May 2024 07:10:42 -0400 Subject: [PATCH 1/2] corrected fix-kubectl path math --- fix-kubectl | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/fix-kubectl b/fix-kubectl index 18ce27e..7ed8440 100755 --- a/fix-kubectl +++ b/fix-kubectl @@ -4,21 +4,25 @@ # - uneeded, as this checked whether script is sourced # 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 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 + else + # 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 return 1; # NOT sourced. } -BASE_0=${BASE_0:-$0} -BASE_SHELL=$(basename "$SHELL") if is_sourced; then + # This part is sourced, and might run in a non-bash shell DBG_="Is Sourced" - SCRIPT_DIR=$( cd -- "$( dirname -- "${BASE_0}" )" &> /dev/null && pwd ) USER_HOME=$HOME [[ -n "${SUDO_USER}" ]] && USER_HOME="$(eval "echo ~${SUDO_USER}")" @@ -101,7 +105,7 @@ if is_sourced; then } fi elif [[ "$1" == '-' ]]; then - printf 'BASE_0="%s"\n' "${BASE_0}" + printf 'BASE_0="%s"\nSCRIPT_DIR=%s\n' "${BASE_0}" "${SCRIPT_DIR}" cat "${BASH_SOURCE[0]}" else SCRIPT_NAME="$BASE_0" From b243ed34ff4e1e99cd8486a0d2c0ebf24810d5cd Mon Sep 17 00:00:00 2001 From: "Lockszmith (kateryna)" Date: Mon, 20 May 2024 07:10:58 -0400 Subject: [PATCH 2/2] load-zellij works with noexec /tmp --- load-zellij | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/load-zellij b/load-zellij index a46e394..c18f35b 100755 --- a/load-zellij +++ b/load-zellij @@ -15,33 +15,32 @@ BASE_SHELL=$(basename "$SHELL") if is_sourced; then zellij() { - if [[ -x /tmp/zellij/bootstrap/zellij ]]; then - /tmp/zellij/bootstrap/zellij "${@}" - else - bash <(curl -sL zellij.dev/launch) "${@}" + 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 + fi + if [[ -x ~/bin/zellij ]]; then + ~/bin/zellij "${@}" fi - } - if [[ -z "$ZELLIJ_SESSION_NAME" ]]; then - # 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 + } + . <( zellij setup --generate-completion "$BASE_SHELL" ) + if [[ -z "$ZELLIJ_SESSION_NAME" ]]; then + (zellij list-sessions 2&>1) > /dev/null || zellij attach -c $USER@$(hostname) fi elif [[ "$1" == '-' ]]; then - echo "BASE_0=${BASE_0}" - cat "${0}" + 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" \ + 'The easiest way is to call it like this:' \ + " $ . <( $SCRIPT_NAME - ) # Note the '-' after the script's name" \ '' fi +