mirror of
https://github.com/eth-p/bat-extras.git
synced 2026-09-10 15:26:20 -04:00
Compare commits
No commits in common. "master" and "v2024.08.24" have entirely different histories.
master
...
v2024.08.2
|
|
@ -39,11 +39,8 @@ parent_shell() {
|
|||
break
|
||||
fi
|
||||
|
||||
# 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
|
||||
# If the parent process has "*sh " followed by "-l", it's probably a login shell.
|
||||
if [[ "$target_name" =~ sh\ .*-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 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
|
||||
# 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
|
||||
|
||||
# Print the commands required to add `batpipe` to the environment variables.
|
||||
case "$(basename -- "${detected_shell:bash}")" in
|
||||
|
|
@ -81,12 +81,6 @@ 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"
|
||||
|
|
@ -105,10 +99,6 @@ 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"
|
||||
|
|
|
|||
|
|
@ -1,4 +1,14 @@
|
|||
#!/usr/bin/env bash
|
||||
# Run bash, but with executable name as `fish`.
|
||||
exec -a "${SHIM_ARGV0:-fish}" bash "$@"
|
||||
exit $?
|
||||
# Find the real fish.
|
||||
HERE="$(cd "$(dirname "$0")" && pwd)"
|
||||
while read -d ':' -r dir; do
|
||||
if [[ "$dir" == "$HERE" || -z "$dir" ]]; then continue; fi
|
||||
if [[ -f "${dir}/fish" ]]; then
|
||||
TMPDIR='' "${dir}/fish" "$@"
|
||||
exit $?
|
||||
fi
|
||||
done <<<"$PATH:"
|
||||
|
||||
# Print error and exit.
|
||||
echo "fish was not found on \$PATH" 1>&2
|
||||
exit 127
|
||||
|
|
|
|||
|
|
@ -1,7 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
# Run bash, but with executable name as `nu`.
|
||||
#
|
||||
# Spawn the process in the background and wait on it to ensure we keep
|
||||
# the fake shell as a parent process.
|
||||
exec -a "${SHIM_ARGV0:-nu}" bash "$@"
|
||||
exit $?
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
[2m────────────────────────────────────────────────────────────────────────────────[0m
|
||||
File: [1mfile.txt[0m
|
||||
[38;5;246m 1[0m [48;5;236;38;5;231mcat[0m[48;5;236m [0m
|
||||
[38;5;246m 2[0m [38;5;231mdog[0m
|
||||
[38;5;246m 3[0m [48;5;236;38;5;231mcar[0m[48;5;236m [0m
|
||||
[38;5;246m 4[0m [38;5;231mfrog[0m
|
||||
[38;5;246m 5[0m [38;5;231mfox[0m
|
||||
[38;5;238m 1[0m [48;5;236;38;5;231mcat[0m[48;5;236m [0m
|
||||
[38;5;238m 2[0m [38;5;231mdog[0m
|
||||
[38;5;238m 3[0m [48;5;236;38;5;231mcar[0m[48;5;236m [0m
|
||||
[38;5;238m 4[0m [38;5;231mfrog[0m
|
||||
[38;5;238m 5[0m [38;5;231mfox[0m
|
||||
[2m────────────────────────────────────────────────────────────────────────────────[0m
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
File: [1mfile.txt[0m
|
||||
[38;5;246m 1[0m [48;5;236;38;5;231mcat[0m[48;5;236m [0m
|
||||
[38;5;246m 2[0m [38;5;231mdog[0m
|
||||
[38;5;246m 3[0m [48;5;236;38;5;231mcar[0m[48;5;236m [0m
|
||||
[38;5;246m 4[0m [38;5;231mfrog[0m
|
||||
[38;5;246m 5[0m [38;5;231mfox[0m
|
||||
[38;5;238m 1[0m [48;5;236;38;5;231mcat[0m[48;5;236m [0m
|
||||
[38;5;238m 2[0m [38;5;231mdog[0m
|
||||
[38;5;238m 3[0m [48;5;236;38;5;231mcar[0m[48;5;236m [0m
|
||||
[38;5;238m 4[0m [38;5;231mfrog[0m
|
||||
[38;5;238m 5[0m [38;5;231mfox[0m
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
[38;5;246m────────────────────────────────────────────────────────────────────────────────[0m
|
||||
[38;5;238m────────────────────────────────────────────────────────────────────────────────[0m
|
||||
[48;5;236;38;5;231mcat[0m[48;5;236m [0m
|
||||
[38;5;231mdog[0m
|
||||
[48;5;236;38;5;231mcar[0m[48;5;236m [0m
|
||||
[38;5;231mfrog[0m
|
||||
[38;5;231mfox[0m
|
||||
[38;5;246m────────────────────────────────────────────────────────────────────────────────[0m
|
||||
[38;5;238m────────────────────────────────────────────────────────────────────────────────[0m
|
||||
|
|
|
|||
|
|
@ -1,26 +1,26 @@
|
|||
[38;5;246m───────┬────────────────────────────────[0m
|
||||
[38;5;246m│ [0mFile: [1mfile.txt[0m
|
||||
[38;5;246m───────┼────────────────────────────────[0m
|
||||
[38;5;246m 1[0m [38;5;246m│[0m [38;5;231mcat[0m
|
||||
[38;5;246m 2[0m [38;5;246m│[0m [38;5;231mdog[0m
|
||||
[38;5;246m 3[0m [38;5;246m│[0m [38;5;231mcar[0m
|
||||
[38;5;246m 4[0m [38;5;246m│[0m [38;5;231mfrog[0m
|
||||
[38;5;246m 5[0m [38;5;246m│[0m [38;5;231mfox[0m
|
||||
[38;5;246m 6[0m [38;5;246m│[0m [38;5;231mclocks[0m
|
||||
[38;5;246m 7[0m [38;5;246m│[0m [38;5;231mbash[0m
|
||||
[38;5;246m 8[0m [38;5;246m│[0m [38;5;231m$300[0m
|
||||
[38;5;246m 9[0m [38;5;246m│[0m [38;5;231m^$!@[0m
|
||||
[38;5;246m───────┴────────────────────────────────[0m
|
||||
[38;5;246m───────┬────────────────────────────────────────────────────[0m
|
||||
[38;5;246m│ [0mFile: [1mfile.txt[0m
|
||||
[38;5;246m───────┼────────────────────────────────────────────────────[0m
|
||||
[38;5;246m 1[0m [38;5;246m│[0m [38;5;231mcat[0m
|
||||
[38;5;246m 2[0m [38;5;246m│[0m [38;5;231mdog[0m
|
||||
[38;5;246m 3[0m [38;5;246m│[0m [38;5;231mcar[0m
|
||||
[38;5;246m 4[0m [38;5;246m│[0m [38;5;231mfrog[0m
|
||||
[38;5;246m 5[0m [38;5;246m│[0m [38;5;231mfox[0m
|
||||
[38;5;246m 6[0m [38;5;246m│[0m [38;5;231mclocks[0m
|
||||
[38;5;246m 7[0m [38;5;246m│[0m [38;5;231mbash[0m
|
||||
[38;5;246m 8[0m [38;5;246m│[0m [38;5;231m$300[0m
|
||||
[38;5;246m 9[0m [38;5;246m│[0m [38;5;231m^$!@[0m
|
||||
[38;5;246m───────┴────────────────────────────────────────────────────[0m
|
||||
[38;5;238m───────┬────────────────────────────────[0m
|
||||
[38;5;238m│ [0mFile: [1mfile.txt[0m
|
||||
[38;5;238m───────┼────────────────────────────────[0m
|
||||
[38;5;238m 1[0m [38;5;238m│[0m [38;5;231mcat[0m
|
||||
[38;5;238m 2[0m [38;5;238m│[0m [38;5;231mdog[0m
|
||||
[38;5;238m 3[0m [38;5;238m│[0m [38;5;231mcar[0m
|
||||
[38;5;238m 4[0m [38;5;238m│[0m [38;5;231mfrog[0m
|
||||
[38;5;238m 5[0m [38;5;238m│[0m [38;5;231mfox[0m
|
||||
[38;5;238m 6[0m [38;5;238m│[0m [38;5;231mclocks[0m
|
||||
[38;5;238m 7[0m [38;5;238m│[0m [38;5;231mbash[0m
|
||||
[38;5;238m 8[0m [38;5;238m│[0m [38;5;231m$300[0m
|
||||
[38;5;238m 9[0m [38;5;238m│[0m [38;5;231m^$!@[0m
|
||||
[38;5;238m───────┴────────────────────────────────[0m
|
||||
[38;5;238m───────┬────────────────────────────────────────────────────[0m
|
||||
[38;5;238m│ [0mFile: [1mfile.txt[0m
|
||||
[38;5;238m───────┼────────────────────────────────────────────────────[0m
|
||||
[38;5;238m 1[0m [38;5;238m│[0m [38;5;231mcat[0m
|
||||
[38;5;238m 2[0m [38;5;238m│[0m [38;5;231mdog[0m
|
||||
[38;5;238m 3[0m [38;5;238m│[0m [38;5;231mcar[0m
|
||||
[38;5;238m 4[0m [38;5;238m│[0m [38;5;231mfrog[0m
|
||||
[38;5;238m 5[0m [38;5;238m│[0m [38;5;231mfox[0m
|
||||
[38;5;238m 6[0m [38;5;238m│[0m [38;5;231mclocks[0m
|
||||
[38;5;238m 7[0m [38;5;238m│[0m [38;5;231mbash[0m
|
||||
[38;5;238m 8[0m [38;5;238m│[0m [38;5;231m$300[0m
|
||||
[38;5;238m 9[0m [38;5;238m│[0m [38;5;231m^$!@[0m
|
||||
[38;5;238m───────┴────────────────────────────────────────────────────[0m
|
||||
|
|
|
|||
|
|
@ -11,35 +11,12 @@ test:detected_bash_shell() {
|
|||
}
|
||||
|
||||
test:detected_fish_shell() {
|
||||
description "Test it can detect a fish shell."
|
||||
|
||||
# Note: We don't use bash's `-c` option when testing with a fake fish shell.
|
||||
# Bash `-c` will automatically exec() into the last process, which loses the
|
||||
# argv0 we intentionally named after a different shell.
|
||||
|
||||
# Test detection via `*sh -l` parent process.
|
||||
output="$(printf "%q" "$(batpipe_path)" | fish -l)"
|
||||
grep '^set -x' <<< "$output" >/dev/null || fail 'Detected wrong shell when checking parent process args.'
|
||||
|
||||
# Test detection via hypen-prefixed parent process.
|
||||
output="$(printf "%q" "$(batpipe_path)" | SHIM_ARGV0='-fish' fish)"
|
||||
grep '^set -x' <<< "$output" >/dev/null || fail 'Detected wrong shell when checking parent process.'
|
||||
}
|
||||
|
||||
test:detected_nu_shell() {
|
||||
description "Test it can detect a nushell shell."
|
||||
|
||||
# Note: We don't use bash's `-c` option when testing with a fake nu shell.
|
||||
# Bash `-c` will automatically exec() into the last process, which loses the
|
||||
# argv0 we intentionally named after a different shell.
|
||||
|
||||
# Test detection via `*sh -l` parent process.
|
||||
output="$(printf "%q" "$(batpipe_path)" | nu -l)"
|
||||
grep '^\$env' <<< "$output" >/dev/null || fail 'Detected wrong shell when checking parent process args.'
|
||||
|
||||
# Test detection via hypen-prefixed parent process.
|
||||
output="$(printf "%q" "$(batpipe_path)" | SHIM_ARGV0='-nu' nu -l)"
|
||||
grep '^\$env' <<< "$output" >/dev/null || fail 'Detected wrong shell when checking parent process.'
|
||||
description "Test it can detect a bash shell."
|
||||
command -v "fish" &>/dev/null || skip "Test requires fish shell."
|
||||
fish -c 'exit 0' &>/dev/null || skip "Test requires fish shell." # This is in case it finds "fish" in shimexec dir.
|
||||
|
||||
output="$(SHELL="fish" fish --login -c "$(batpipe_path)")"
|
||||
grep '^set -x' <<< "$output" >/dev/null || fail "Detected the wrong shell for fish."
|
||||
}
|
||||
|
||||
test:viewer_gzip() {
|
||||
|
|
|
|||
Loading…
Reference in a new issue