mirror of
https://github.com/eth-p/bat-extras.git
synced 2026-09-10 07:16:25 -04:00
Compare commits
22 commits
v2024.02.1
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3860f0f148 | ||
|
|
58e7f52717 | ||
|
|
86fd93e47e | ||
|
|
a0d3a9bd63 | ||
|
|
b977dffc54 | ||
|
|
36c77c171c | ||
|
|
6092fa5bad | ||
|
|
1cffc910d5 | ||
|
|
47cfb9ec73 | ||
|
|
32706dd581 | ||
|
|
01c2f9bb94 | ||
|
|
0acf65edde | ||
|
|
92dcb78765 | ||
|
|
ac4f8710ba | ||
|
|
aef5a424b4 | ||
|
|
3b3a8923a1 | ||
|
|
eb7ad6b21b | ||
|
|
f5b8cfb5d7 | ||
|
|
38bacab368 | ||
|
|
043d2da964 | ||
|
|
75c757817f | ||
|
|
c9e917e43a |
|
|
@ -1,5 +1,5 @@
|
|||
# -----------------------------------------------------------------------------
|
||||
# bat-extras | Copyright (C) 2020 eth-p and contributors | MIT License
|
||||
# bat-extras | Copyright (C) 2020-2024 eth-p and contributors | MIT License
|
||||
#
|
||||
# Repository: https://github.com/eth-p/bat-extras
|
||||
# Issues: https://github.com/eth-p/bat-extras/issues
|
||||
|
|
|
|||
|
|
@ -11,7 +11,19 @@ If you have `fzf` installed, you can even use `batman` to search through manual
|
|||
|
||||
batman [SECTION] [ENTRY]
|
||||
|
||||
### As a Replacement for Man
|
||||
|
||||
With bash:
|
||||
|
||||
```bash
|
||||
eval "$(batman --export-env)"
|
||||
```
|
||||
|
||||
With fish:
|
||||
|
||||
```fish
|
||||
batman --export-env | source
|
||||
```
|
||||
|
||||
## Environment
|
||||
|
||||
|
|
|
|||
|
|
@ -21,23 +21,23 @@ See `man bat` for more information.
|
|||
|
||||
## Languages
|
||||
|
||||
| Language | Formatter |
|
||||
| -------------------- | --------------------------------------------------------------- |
|
||||
| JavaScript (JS, JSX) | [prettier](https://prettier.io/) |
|
||||
| TypeScript (TS, TSX) | [prettier](https://prettier.io/) |
|
||||
| CSS, SCSS, SASS | [prettier](https://prettier.io/) |
|
||||
| Markdown | [prettier](https://prettier.io/) |
|
||||
| JSON | [prettier](https://prettier.io/) |
|
||||
| YAML | [prettier](https://prettier.io/) |
|
||||
| HTML | [prettier](https://prettier.io/) |
|
||||
| SVG | [prettier](https://prettier.io/) |
|
||||
| Rust | [rustfmt](https://github.com/rust-lang/rustfmt) |
|
||||
| Bash | [shfmt](https://github.com/mvdan/sh) |
|
||||
| C | [ClangFormat](https://clang.llvm.org/docs/ClangFormat.html) |
|
||||
| C++ | [ClangFormat](https://clang.llvm.org/docs/ClangFormat.html) |
|
||||
| Objective-C | [ClangFormat](https://clang.llvm.org/docs/ClangFormat.html) |
|
||||
| Python | [black](https://black.readthedocs.io/) |
|
||||
| Elixir | [mix format](https://hexdocs.pm/mix/main/Mix.Tasks.Format.html) |
|
||||
| Language | Formatter |
|
||||
| -------------------- | ------------------------------------------------------------------------------------------------------ |
|
||||
| JavaScript (JS, JSX) | [prettier](https://prettier.io/) |
|
||||
| TypeScript (TS, TSX) | [prettier](https://prettier.io/) |
|
||||
| CSS, SCSS, SASS | [prettier](https://prettier.io/) |
|
||||
| Markdown | [prettier](https://prettier.io/) |
|
||||
| JSON | [yq](https://mikefarah.gitbook.io/yq), [prettier](https://prettier.io/) |
|
||||
| YAML | [yq](https://mikefarah.gitbook.io/yq), [prettier](https://prettier.io/) |
|
||||
| HTML | [prettier](https://prettier.io/) |
|
||||
| SVG | [prettier](https://prettier.io/) |
|
||||
| Rust | [rustfmt](https://github.com/rust-lang/rustfmt) |
|
||||
| Bash | [shfmt](https://github.com/mvdan/sh) |
|
||||
| C | [ClangFormat](https://clang.llvm.org/docs/ClangFormat.html) |
|
||||
| C++ | [ClangFormat](https://clang.llvm.org/docs/ClangFormat.html) |
|
||||
| Objective-C | [ClangFormat](https://clang.llvm.org/docs/ClangFormat.html) |
|
||||
| Python | [black](https://black.readthedocs.io/) |
|
||||
| Elixir | [mix format](https://hexdocs.pm/mix/main/Mix.Tasks.Format.html) |
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -155,8 +155,8 @@ print_bat_diff() {
|
|||
|
||||
# Diff git file.
|
||||
if "$SUPPORTS_BAT_DIFF"; then
|
||||
"$EXECUTABLE_GIT" diff "${GIT_ARGS[@]}" --name-only "${files[0]}" \
|
||||
| xargs "$EXECUTABLE_BAT" --diff --diff-context="$OPT_CONTEXT" "${BAT_ARGS[@]}"
|
||||
"$EXECUTABLE_GIT" diff "${GIT_ARGS[@]}" --name-only -z "${files[0]}" \
|
||||
| xargs --null "$EXECUTABLE_BAT" --diff --diff-context="$OPT_CONTEXT" "${BAT_ARGS[@]}"
|
||||
else
|
||||
"$EXECUTABLE_GIT" diff "${GIT_ARGS[@]}" "${files[0]}" | "$EXECUTABLE_BAT" --language=diff - "${BAT_ARGS[@]}"
|
||||
fi
|
||||
|
|
|
|||
|
|
@ -22,11 +22,13 @@ hook_version
|
|||
FORWARDED_ARGS=()
|
||||
MAN_ARGS=()
|
||||
BAT_ARGS=()
|
||||
OPT_EXPORT_ENV=false
|
||||
|
||||
SHIFTOPT_SHORT_OPTIONS="SPLIT"
|
||||
while shiftopt; do
|
||||
case "$OPT" in
|
||||
--paging|--pager) shiftval; FORWARDED_ARGS+=("${OPT}=${OPT_VAL}");
|
||||
--export-env) OPT_EXPORT_ENV=true ;;
|
||||
--paging|--pager|--wrap) shiftval; FORWARDED_ARGS+=("${OPT}=${OPT_VAL}");
|
||||
BAT_ARGS+=("${OPT}=${OPT_VAL}") ;;
|
||||
*) MAN_ARGS+=("$OPT") ;;
|
||||
esac
|
||||
|
|
@ -66,29 +68,46 @@ fi
|
|||
# -----------------------------------------------------------------------------
|
||||
if [[ -n "${MANPAGER}" ]]; then BAT_PAGER="$MANPAGER"; fi
|
||||
export MANPAGER="env BATMAN_IS_BEING_MANPAGER=yes bash $(printf "%q " "$SELF" "${FORWARDED_ARGS[@]}")"
|
||||
export MANPAGER="${MANPAGER%"${MANPAGER##*[![:space:]]}"}"
|
||||
export MANROFFOPT='-c'
|
||||
|
||||
# If `--export-env`, print exports to use batman as the manpager directly.
|
||||
if "$OPT_EXPORT_ENV"; then
|
||||
printf "export %s=%q\n" \
|
||||
"MANPAGER" "$MANPAGER" \
|
||||
"MANROFFOPT" "$MANROFFOPT"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# If no argument is provided and fzf is installed, use fzf to search for man pages.
|
||||
if [[ "${#MAN_ARGS[@]}" -eq 0 ]] && [[ -z "$BATMAN_LEVEL" ]] && command -v "$EXECUTABLE_FZF" &>/dev/null; then
|
||||
export BATMAN_LEVEL=1
|
||||
|
||||
|
||||
selected_page="$(man -k . | "$EXECUTABLE_FZF" --delimiter=" - " --reverse -e --preview="
|
||||
echo {1} \
|
||||
| sed 's/, /\n/g;' \
|
||||
| sed 's/\([^(]*\)(\([0-9A-Za-z ]\))/\2\t\1/g' \
|
||||
| BAT_STYLE=plain xargs -n2 batman --color=always --paging=never
|
||||
")"
|
||||
|
||||
|
||||
if [[ -z "$selected_page" ]]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
|
||||
# Some entries from `man -k .` may include "synonyms" of a man page's title.
|
||||
# For example, the manual for kubectl-edit will appear as:
|
||||
#
|
||||
# kubectl-edit(1), kubectl edit(1) - Edit a resource on the server
|
||||
#
|
||||
# `man` only needs one name/title, so we're taking the first one here.
|
||||
selected_page_unaliased="$(echo "$selected_page" | cut -d, -f1)"
|
||||
|
||||
# Convert the page(section) format to something that can be fed to the man command.
|
||||
while read -r line; do
|
||||
if [[ "$line" =~ ^(.*)\(([0-9a-zA-Z ]+)\) ]]; then
|
||||
MAN_ARGS+=("${BASH_REMATCH[2]}" "$(echo ${BASH_REMATCH[1]} | xargs)")
|
||||
fi
|
||||
done <<< "$selected_page"
|
||||
done <<< "$selected_page_unaliased"
|
||||
fi
|
||||
|
||||
# Run man.
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ source "${LIB}/str.sh"
|
|||
source "${LIB}/print.sh"
|
||||
source "${LIB}/version.sh"
|
||||
source "${LIB}/check.sh"
|
||||
source "${LIB}/term.sh"
|
||||
# -----------------------------------------------------------------------------
|
||||
# Init:
|
||||
# -----------------------------------------------------------------------------
|
||||
|
|
@ -22,7 +23,10 @@ hook_version
|
|||
# Formatters:
|
||||
# -----------------------------------------------------------------------------
|
||||
|
||||
FORMATTERS=("prettier" "rustfmt" "shfmt" "clangformat" "black", "mix_format")
|
||||
FORMATTERS=(
|
||||
"yq" "prettier" "rustfmt" "shfmt" "clangformat"
|
||||
"black" "mix_format" "column"
|
||||
)
|
||||
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
|
|
@ -138,6 +142,76 @@ formatter_mix_format_process() {
|
|||
return $?
|
||||
}
|
||||
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
formatter_column_supports() {
|
||||
case "$1" in
|
||||
.tsv)
|
||||
return 0
|
||||
;;
|
||||
esac
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
formatter_column_process() {
|
||||
local needs_newline=true
|
||||
local args=(
|
||||
-t
|
||||
-s $'\t'
|
||||
-c "$TERMINAL_WIDTH"
|
||||
)
|
||||
|
||||
if column --help &>/dev/null; then
|
||||
# GNU `column`
|
||||
args+=(--keep-empty-lines)
|
||||
needs_newline=false
|
||||
fi
|
||||
|
||||
{ { "$needs_newline" && sed 's/$/\n/'; } || cat; } | column "${args[@]}"
|
||||
}
|
||||
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
formatter_yq_supports__version_ok() {
|
||||
local yq_version
|
||||
yq_version=$(yq --version | sed 's/^.* version v//')
|
||||
|
||||
# If it's older than yq version 4, replace the functions to save processing.
|
||||
if version_compare "$yq_version" -lt 4.0; then
|
||||
formatter_yq_supports() { return 1; }
|
||||
formatter_yq_supports__version_ok() { return 1; }
|
||||
return 1
|
||||
fi
|
||||
|
||||
# It's supported.
|
||||
formatter_yq_supports__version_ok() { return 0; }
|
||||
return 0
|
||||
}
|
||||
|
||||
formatter_yq_supports() {
|
||||
case "$1" in
|
||||
.yaml | yml | \
|
||||
.json)
|
||||
formatter_yq_supports__version_ok
|
||||
return $?
|
||||
;;
|
||||
esac
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
formatter_yq_process() {
|
||||
local args=()
|
||||
case "$1" in
|
||||
*.json) args+=(--output-format json) ;;
|
||||
esac
|
||||
|
||||
yq --prettyPrint --indent 4 "${args[@]}" \
|
||||
| sed -e ':l' -e 's/^\(\t*\) /\1\t/g; t l'
|
||||
return $?
|
||||
}
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
# Functions:
|
||||
# -----------------------------------------------------------------------------
|
||||
|
|
@ -167,6 +241,7 @@ map_language_to_extension() {
|
|||
python | py) ext=".py" ;;
|
||||
elixir | ex) ext=".ex" ;;
|
||||
exs) ext=".exs" ;;
|
||||
tsv) ext=".tsv" ;;
|
||||
esac
|
||||
|
||||
echo "$ext"
|
||||
|
|
@ -294,6 +369,8 @@ OPT_LANGUAGE=
|
|||
FILES=()
|
||||
DEBUG_PRINT_FORMATTER=false
|
||||
|
||||
TERMINAL_WIDTH="$(term_width)"
|
||||
|
||||
# Parse arguments.
|
||||
while shiftopt; do
|
||||
case "$OPT" in
|
||||
|
|
|
|||
|
|
@ -1,14 +1,4 @@
|
|||
#!/usr/bin/env bash
|
||||
# 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
|
||||
# Run bash, but with executable name as `fish`.
|
||||
exec -a "${SHIM_ARGV0:-fish}" bash "$@"
|
||||
exit $?
|
||||
|
|
|
|||
|
|
@ -12,4 +12,10 @@ EOF
|
|||
exit 0
|
||||
fi
|
||||
|
||||
cat "$1"
|
||||
FILES=()
|
||||
while [[ $# -gt 0 ]]; do
|
||||
-*) : ;;
|
||||
*) FILES+=("$1")
|
||||
done
|
||||
|
||||
cat "${FILES[@]}"
|
||||
|
|
|
|||
7
test/shimexec/nu
Executable file
7
test/shimexec/nu
Executable file
|
|
@ -0,0 +1,7 @@
|
|||
#!/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;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
|
||||
[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
|
||||
[2m────────────────────────────────────────────────────────────────────────────────[0m
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
File: [1mfile.txt[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
|
||||
[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
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
[38;5;238m────────────────────────────────────────────────────────────────────────────────[0m
|
||||
[38;5;246m────────────────────────────────────────────────────────────────────────────────[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;238m────────────────────────────────────────────────────────────────────────────────[0m
|
||||
[38;5;246m────────────────────────────────────────────────────────────────────────────────[0m
|
||||
|
|
|
|||
|
|
@ -1,26 +1,26 @@
|
|||
[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
|
||||
[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
|
||||
|
|
|
|||
|
|
@ -11,12 +11,35 @@ test:detected_bash_shell() {
|
|||
}
|
||||
|
||||
test:detected_fish_shell() {
|
||||
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."
|
||||
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.'
|
||||
}
|
||||
|
||||
test:viewer_gzip() {
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
2024.02.12
|
||||
2024.08.24
|
||||
|
|
|
|||
Loading…
Reference in a new issue