mirror of
https://github.com/eth-p/bat-extras.git
synced 2025-06-19 19:27:42 +02:00
batpipe: Add detection for nushell
This commit is contained in:
parent
b977dffc54
commit
a0d3a9bd63
@ -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
|
||||
|
@ -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"
|
||||
|
Loading…
x
Reference in New Issue
Block a user