#! /usr/bin/env bash # 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") if is_sourced; then zellij() { if [[ -x /tmp/zellij/bootstrap/zellij ]]; then /tmp/zellij/bootstrap/zellij "${@}" else bash <(curl -sL zellij.dev/launch) "${@}" 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 fi elif [[ "$1" == '-' ]]; then echo "BASE_0=${BASE_0}" cat "${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" \ '' fi