diff --git a/lib/proc.sh b/lib/proc.sh index dd47443..1dadd0c 100644 --- a/lib/proc.sh +++ b/lib/proc.sh @@ -39,8 +39,11 @@ parent_shell() { break fi - # If the parent process has "*sh " followed by "-l", it's probably a login shell. - if [[ "$target_name" =~ sh\ .*-l ]]; then + # If the parent process is one of: + # - `*sh`; or + # - `nu` + # Followed by "-l", it's probably a login shell. + if [[ "$target_name" =~ ^(.*sh|nu)\ .*-l ]]; then target_name="$(cut -f1 -d' ' <<< "${target_name}")" break fi diff --git a/src/batpipe.sh b/src/batpipe.sh index 8d439cd..5b7b2e6 100755 --- a/src/batpipe.sh +++ b/src/batpipe.sh @@ -67,13 +67,13 @@ if [[ "$#" -eq 0 ]]; then # Detect the shell. # - # This will directly check if the parent is fish, since there's a - # good chance that `bash` or `sh` will be invoking fish. - if [[ "$(basename -- "$(parent_executable | cut -f1 -d' ')")" == "fish" ]]; then - detected_shell="fish" - else - detected_shell="$(parent_shell)" - fi + # This will directly check if the parent is a non-sh/bash shell, since + # there's a good chance that `bash` or `sh` will be invoking it. + case "$(basename -- "$(parent_executable | cut -f1 -d' ')")" in + fish) detected_shell="fish" ;; + nu) detected_shell="nu" ;; + *) detected_shell="$(parent_shell)" ;; + esac # Print the commands required to add `batpipe` to the environment variables. case "$(basename -- "${detected_shell:bash}")" in @@ -81,6 +81,12 @@ if [[ "$#" -eq 0 ]]; then printc '%{YELLOW}set -x %{CLEAR}LESSOPEN %{CYAN}"|%q %%s"%{CLEAR};\n' "$SELF" printc '%{YELLOW}set -e %{CLEAR}LESSCLOSE;\n' ;; + nu) # Nushell + printc '%{BLUE}$env%{CLEAR}.LESSOPEN = %{CYAN}"|%q %%s"%{CLEAR}\n' "$SELF" + if [[ "${LESSCLOSE:-}" != "" ]]; then + printc '%{BLUE}hide-env%{CLEAR} LESSCLOSE\n' "$SELF" + fi + ;; *) # Bash-like printc '%{MAGENTA}LESSOPEN%{CLEAR}=%{CYAN}"|%s %%s"%{CLEAR};\n' "$SELF" printc '%{YELLOW}export%{CLEAR} LESSOPEN;\n' "$SELF" @@ -99,6 +105,10 @@ if [[ "$#" -eq 0 ]]; then printc '%{YELLOW}set -x %{CLEAR}LESS %{CYAN}"%{MAGENTA}$LESS%{CYAN} -R"%{CLEAR};\n' "$SELF" printc '%{YELLOW}set -x %{CLEAR}BATPIPE %{CYAN}"color"%{CLEAR};\n' ;; + nu) # Nushell + printc '%{BLUE}$env%{CLEAR}.LESS = %{CYAN}$"%{MAGENTA}($env.LESS)%{CYAN} -R"%{CLEAR}\n' "$SELF" + printc '%{BLUE}$env%{CLEAR}.BATPIPE = %{CYAN}"color"%{CLEAR}\n' "$SELF" + ;; *) # Bash-like printc '%{MAGENTA}LESS%{CLEAR}=%{CYAN}"%{MAGENTA}$LESS%{CYAN} -R"%{CLEAR};\n' "$SELF" printc '%{MAGENTA}BATPIPE%{CLEAR}=%{CYAN}"color"%{CLEAR};\n' "$SELF"