mirror of
https://github.com/eth-p/bat-extras.git
synced 2025-06-20 19:57:46 +02:00
batpipe: Improve batpipe
when used both inside and outside less
This commit is contained in:
parent
fa32c5875d
commit
2a28cbff3a
@ -32,7 +32,7 @@
|
|||||||
# batpipe_subheader [pattern] [...] -- Print a viewer subheader line.
|
# batpipe_subheader [pattern] [...] -- Print a viewer subheader line.
|
||||||
#
|
#
|
||||||
# bat -- Use `bat` for highlighting.
|
# bat -- Use `bat` for highlighting.
|
||||||
# bat_if_not_bat [...] -- Use `bat` for highlighting (only supported in `less`).
|
# bat_if_not_bat [...] -- Use `bat` for highlighting (when running from `less`).
|
||||||
#
|
#
|
||||||
# strip_trailing_slashes [path] -- Strips trailing slashes from a path.
|
# strip_trailing_slashes [path] -- Strips trailing slashes from a path.
|
||||||
#
|
#
|
||||||
@ -97,12 +97,12 @@ BATPIPE_INSIDE_LESS=false
|
|||||||
BATPIPE_INSIDE_BAT=false
|
BATPIPE_INSIDE_BAT=false
|
||||||
TERM_WIDTH="$(term_width)"
|
TERM_WIDTH="$(term_width)"
|
||||||
|
|
||||||
bat_if_not_bat() { bat "$@"; return $?; }
|
bat_if_not_bat() { cat; }
|
||||||
if [[ "$(basename -- "$(parent_executable "$(parent_executable_pid)"|cut -f1 -d' ')")" == less ]]; then
|
if [[ "$(basename -- "$(parent_executable "$(parent_executable_pid)"|cut -f1 -d' ')")" == less ]]; then
|
||||||
BATPIPE_INSIDE_LESS=true
|
BATPIPE_INSIDE_LESS=true
|
||||||
|
bat_if_not_bat() { bat "$@"; return $?; }
|
||||||
elif [[ "$(basename -- "$(parent_executable|cut -f1 -d' ')")" == "$(basename -- "$EXECUTABLE_BAT")" ]]; then
|
elif [[ "$(basename -- "$(parent_executable|cut -f1 -d' ')")" == "$(basename -- "$EXECUTABLE_BAT")" ]]; then
|
||||||
BATPIPE_INSIDE_BAT=true
|
BATPIPE_INSIDE_BAT=true
|
||||||
bat_if_not_bat() { cat; }
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
@ -139,7 +139,7 @@ viewer_tar_supports() {
|
|||||||
|
|
||||||
viewer_tar_process() {
|
viewer_tar_process() {
|
||||||
if [[ -n "$2" ]]; then
|
if [[ -n "$2" ]]; then
|
||||||
tar -xf "$1" -O "$2" 2>&1 | bat_if_not_bat --file-name="$1/$2"
|
tar -xf "$1" -O "$2" | bat_if_not_bat --file-name="$1/$2"
|
||||||
else
|
else
|
||||||
batpipe_header "Viewing contents of archive: %{PATH}%s" "$1"
|
batpipe_header "Viewing contents of archive: %{PATH}%s" "$1"
|
||||||
batpipe_subheader "To view files within the archive, add the file path after the archive."
|
batpipe_subheader "To view files within the archive, add the file path after the archive."
|
||||||
@ -308,4 +308,5 @@ for viewer in "${BATPIPE_VIEWERS[@]}"; do
|
|||||||
done
|
done
|
||||||
|
|
||||||
# No supported viewer. Just pass it through.
|
# No supported viewer. Just pass it through.
|
||||||
|
cat
|
||||||
exit 1
|
exit 1
|
||||||
|
Loading…
x
Reference in New Issue
Block a user