From 9072ab47a1e801c9f0ec3b768cb25d2e5a55ab53 Mon Sep 17 00:00:00 2001 From: Ethan P Date: Wed, 24 Mar 2021 20:04:14 -0700 Subject: [PATCH] batpipe: Change viewer_*_supports arg order --- doc/batpipe.md | 2 +- src/batpipe.sh | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/doc/batpipe.md b/doc/batpipe.md index c7534ae..7d8e4fd 100644 --- a/doc/batpipe.md +++ b/doc/batpipe.md @@ -39,7 +39,7 @@ External viewers are be added to batpipe by creating bash scripts inside the `~/ Viewers must define two functions and append the viewer's name to the `$BATPIPE_VIEWERS` array. - - `viewer_${viewer}_supports [file_path] [file_basename]` + - `viewer_${viewer}_supports [file_basename] [file_path] [inner_file_path]` - `viewer_${viewer}_process [file_path] [inner_file_path]` The `viewer_${viewer}_supports` function is called to determine if the external viewer is capable of viewing the provided file. If this function returns successfully, the corresponding `process` function will be called. diff --git a/src/batpipe.sh b/src/batpipe.sh index 489b2bf..1ff0767 100755 --- a/src/batpipe.sh +++ b/src/batpipe.sh @@ -16,7 +16,7 @@ # Viewers must define two functions and append the viewer's name to the # `BATPIPE_VIEWERS` array. # -# - viewer_${viewer}_supports [file_path] [file_basename] +# - viewer_${viewer}_supports [file_basename] [file_path] [inner_file_path] # If this returns 0, the viewer's process function will be used. # # - viewer_${viewer}_process [file_path] [inner_file_path] @@ -114,7 +114,7 @@ BATPIPE_VIEWERS=("ls" "tar" "unzip") # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - viewer_ls_supports() { - [[ -d "$1" ]] + [[ -d "$2" ]] return $? } @@ -130,7 +130,7 @@ viewer_ls_process() { viewer_tar_supports() { command -v "tar" &> /dev/null || return 1 - case "$2" in + case "$1" in *.tar | *.tar.*) return 0 ;; esac @@ -153,7 +153,7 @@ viewer_tar_process() { viewer_unzip_supports() { command -v "unzip" &> /dev/null || return 1 - case "$2" in + case "$1" in *.zip) return 0 ;; esac @@ -161,7 +161,7 @@ viewer_unzip_supports() { } viewer_unzip_process() { - if [[ -n "$2" ]]; then + if [[ -n "$1" ]]; then unzip -p "$1" "$2" | bat_if_not_bat --file-name="$1/$2" else batpipe_header "Viewing contents of archive: %{PATH}%s" "$1" @@ -324,7 +324,7 @@ fi # Try opening the file with the first viewer that supports it. for viewer in "${BATPIPE_VIEWERS[@]}"; do - if "viewer_${viewer}_supports" "$__TARGET_FILE" "$__TARGET_BASENAME" 1>&2; then + if "viewer_${viewer}_supports" "$__TARGET_BASENAME" "$__TARGET_FILE" "$__TARGET_INSIDE" 1>&2; then "viewer_${viewer}_process" "$__TARGET_FILE" "$__TARGET_INSIDE" exit $? fi