]> Sergey Matveev's repositories - nnn.git/commitdiff
Replace which with builtin type in plugins
authorArun Prakash Jana <engineerarun@gmail.com>
Fri, 14 May 2021 12:03:28 +0000 (17:33 +0530)
committerArun Prakash Jana <engineerarun@gmail.com>
Fri, 14 May 2021 12:03:28 +0000 (17:33 +0530)
29 files changed:
plugins/.cbcp
plugins/.nnn-plugin-helper
plugins/.ntfy
plugins/README.md
plugins/autojump
plugins/boom
plugins/cleanfilename
plugins/diffs
plugins/dragdrop
plugins/fzhist
plugins/fzopen
plugins/fzplug
plugins/fzz
plugins/getplugs
plugins/hexview
plugins/imgur
plugins/imgview
plugins/launch
plugins/nuke
plugins/preview-tabbed
plugins/preview-tui
plugins/preview-tui-ext
plugins/pskill
plugins/renamer
plugins/suedit
plugins/unmount-parent
plugins/upload
plugins/wall
plugins/x2sel

index 04a09dc7a3f5a2edd26560dab2646a155aeb534c..3a71927e5a7ffc059184d39343e6386a6d5ff916 100755 (executable)
@@ -23,28 +23,28 @@ IFS="$(printf '%b_' '\n')"; IFS="${IFS%_}" # protect trailing \n
 
 selection=${NNN_SEL:-${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection}
 
-if which xsel >/dev/null 2>&1; then
+if type xsel >/dev/null 2>&1; then
     # Linux
     tr '\0' '\n' < "$selection" | xsel -bi
-elif which xclip >/dev/null 2>&1; then
+elif type xclip >/dev/null 2>&1; then
     # Linux
     tr '\0' '\n' < "$selection" | xclip -sel clip
-elif which pbcopy >/dev/null 2>&1; then
+elif type pbcopy >/dev/null 2>&1; then
     # macOS
     tr '\0' '\n' < "$selection" | pbcopy
-elif which termux-clipboard-set >/dev/null 2>&1; then
+elif type termux-clipboard-set >/dev/null 2>&1; then
     # Termux
     tr '\0' '\n' < "$selection" | termux-clipboard-set
-elif which clip.exe >/dev/null 2>&1; then
+elif type clip.exe >/dev/null 2>&1; then
     # WSL
     tr '\0' '\n' < "$selection" | clip.exe
-elif which clip >/dev/null 2>&1; then
+elif type clip >/dev/null 2>&1; then
     # Cygwin
     tr '\0' '\n' < "$selection" | clip
-elif which wl-copy >/dev/null 2>&1; then
+elif type wl-copy >/dev/null 2>&1; then
     # Wayland
     tr '\0' '\n' < "$selection" | wl-copy
-elif which clipboard >/dev/null 2>&1; then
+elif type clipboard >/dev/null 2>&1; then
     # Haiku
     tr '\0' '\n' < "$selection" | clipboard --stdin
 fi
index bcb9649fc42541b6738bb0d49398f5cf3e5a1563..4738c699d8267ff6d8d8c3daf8168b53cb62371f 100644 (file)
@@ -33,6 +33,6 @@ nnn_cd () {
 }
 
 cmd_exists () {
-       which "$1" > /dev/null 2>&1
+       type "$1" > /dev/null 2>&1
        echo $?
 }
index 3a7f27fa9f4962821577492a59f0a2e20e8ab496..2a614781a6cc798c418b049c52145e5974c0a4dc 100755 (executable)
 
 OS="$(uname)"
 
-if which notify-send >/dev/null 2>&1; then
+if type notify-send >/dev/null 2>&1; then
     notify-send nnn "Done!"
 elif [ "$OS" = "Darwin" ]; then
     osascript -e 'display notification "Done!" with title "nnn"'
-elif which ntfy >/dev/null 2>&1; then
+elif type ntfy >/dev/null 2>&1; then
     ntfy -t nnn send "Done!"
 elif [ "$OS" = "Haiku" ]; then
     notify --title "nnn" "Done!"
index cdf7445ddf4319398a66ed8e6058df9f8eeae32f..7e7254271440d732b62c0a5f4dce70ff724ee356 100644 (file)
@@ -291,7 +291,7 @@ There are many plugins provided by `nnn` which can be used as examples. Here are
     printf "pattern: "
     read -r pattern
 
-    if ! [ -z "$pattern" ]; then
+    if [ -n "$pattern" ]; then
         printf "%s" "+l" > "$NNN_PIPE"
         eval "fd -HI $pattern -0" > "$NNN_PIPE"
     fi
@@ -306,7 +306,7 @@ There are many plugins provided by `nnn` which can be used as examples. Here are
     printf "pattern: "
     read -r pattern
 
-    if ! [ -z "$pattern" ]; then
+    if [ -n "$pattern" ]; then
         printf "%s" "+l" > "$NNN_PIPE"
         eval "rg -l0 --hidden -S $pattern" > "$NNN_PIPE"
     fi
index 8f058d0bdff85a9b8a42f4a72474bf4f936258bd..0b8425326f23611d215e6af7477e29b480fec522 100755 (executable)
@@ -16,18 +16,18 @@ if [ ! -p "$NNN_PIPE" ]; then
     exit 2
 fi
 
-if which jump >/dev/null 2>&1; then
+if type jump >/dev/null 2>&1; then
     printf "jump to : "
     read -r dir
     odir="$(jump cd "$dir")"
     printf "%s" "0c$odir" > "$NNN_PIPE"
-elif which autojump >/dev/null 2>&1; then
+elif type autojump >/dev/null 2>&1; then
     printf "jump to : "
     read -r dir
     odir="$(autojump "$dir")"
     printf "%s" "0c$odir" > "$NNN_PIPE"
-elif which zoxide >/dev/null 2>&1; then
-    if which fzf >/dev/null 2>&1; then
+elif type zoxide >/dev/null 2>&1; then
+    if type fzf >/dev/null 2>&1; then
        odir="$(zoxide query -i --)"
        printf "%s" "0c$odir" > "$NNN_PIPE"
     else
index 10f14f6097ae7150b1b3f8828a150af9c47d7d91..39da84c2c9c5f1b6cab1481a7e1f025c7452a147 100755 (executable)
@@ -14,7 +14,7 @@ if [ -n "$GUIPLAYER" ]; then
 
     # detach the player
     sleep 1
-elif which mocp >/dev/null 2>&1; then
+elif type mocp >/dev/null 2>&1; then
     cmd=$(pgrep -x mocp 2>/dev/null)
     ret=$cmd
 
index ce573fabf3548f152dfb044e091c9e4b9383af9d..4047152018ba92db92118e2e831a05c30c393318 100755 (executable)
@@ -2,7 +2,7 @@
 
 # Description: Clean filename or dirname (either hovered or selections)
 #              to be more shell-friendly. This script cleans
-#              any character which is not A-Za-z0-9._-
+#              non A-Za-z0-9._- characters.
 #              and replaces it with underscore (_).
 #
 #              It supports cleaning single/double quote, newline,
@@ -15,7 +15,7 @@
 #                qwe\trty                    -> __qwe_rty
 #
 #              And if there are two almost similar filenames
-#              like: 'asd]f' and 'asd f' which both will be renamed to 'asd_f',
+#              like: 'asd]f' and 'asd f' both will be renamed to 'asd_f',
 #              to avoid overwriting, the last file will be prepended by _.
 #              So they will be: 'asd_f' and '_asd_f'
 #
index dea3a4cd5d3e0d4f90379b649817c770d9876a8a..1028f4e7a7d945031356b2fb2f0ed99dc4849749 100755 (executable)
@@ -12,7 +12,7 @@
 
 selection=${NNN_SEL:-${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection}
 
-if which nvim >/dev/null 2>&1; then
+if type nvim >/dev/null 2>&1; then
     diffcmd="nvim -d"
 else
     diffcmd="vimdiff +0"
index a69ed84101a4805e32461be44fa9d771b7605873..ef352da7b7c924d7e0264c94e03a468b5c05c65c 100755 (executable)
@@ -17,7 +17,7 @@
 selection=${NNN_SEL:-${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection}
 resp=f
 all=
-if which dragon-drag-and-drop >/dev/null 2>&1; then
+if type dragon-drag-and-drop >/dev/null 2>&1; then
     dnd="dragon-drag-and-drop"
 else
     dnd="dragon"
index e824fc2f008b8455d13ab69ae00c43d86e37a8ec..2a801f08261cf11aa320c1a37b1c9886e6710976 100755 (executable)
@@ -6,7 +6,7 @@
 # Shell: POSIX compliant
 # Author: Arun Prakash Jana
 
-if which fzf >/dev/null 2>&1; then
+if type fzf >/dev/null 2>&1; then
     fuzzy=fzf
 else
     exit 1
index fa44e0fc3845e323f6c8caff60a6b895b510e532..63f2e2f92c4f1918ba3919c7ed7902283e6fb9be 100755 (executable)
@@ -9,9 +9,9 @@
 # Shell: POSIX compliant
 # Author: Arun Prakash Jana
 
-if which fzf >/dev/null 2>&1; then
+if type fzf >/dev/null 2>&1; then
     cmd="$FZF_DEFAULT_COMMAND"
-    if which fd >/dev/null 2>&1; then
+    if type fd >/dev/null 2>&1; then
         [ -z "$cmd" ] && cmd="fd -t f 2>/dev/null"
     else
         [ -z "$cmd" ] && cmd="find . -type f 2>/dev/null"
@@ -19,7 +19,7 @@ if which fzf >/dev/null 2>&1; then
     entry="$(eval "$cmd" | fzf --delimiter / --nth=-1 --tiebreak=begin --info=hidden)"
     # To show only the file name
     # entry=$(find . -type f 2>/dev/null | fzf --delimiter / --with-nth=-1 --tiebreak=begin --info=hidden)
-elif which sk >/dev/null 2>&1; then
+elif type sk >/dev/null 2>&1; then
        entry=$(find . -type f 2>/dev/null | sk)
 else
     exit 1
index 50b485b65ac9d601812a8d0d6e390f8da1e6995a..b945e0c69eff9bfacd71919f3b49e305d002cd4d 100755 (executable)
@@ -6,14 +6,13 @@
 #
 # For better compatibility with as many nnn plugins as possible, fzfplug will first execute
 # the chosen script on the file hovered in nnn, and upon failure, try to run it with no target
-# (which should actually run it on selected files if nnn has an active selection). I don't
-# have the required dependencies to confirm compatibility with all scripts though.
+# (i.e on an active selection, if present).
 #
 # Dependencies: find, fzf, cat (or bat, if installed)
 # Shell: POSIX compliant
 # Author: Kabouik
 
-# OPTIONAL SCRIPTS SOURCES
+# Optional scripts sources
 # Leave blank or fill with the absolute path of a folder containing executable scripts other than nnn plugins
 # (e.g., "$HOME/.local/share/nautilus/scripts", since there are numerous Nautilus script git repositories).
 # Add extra variables if need be, but be sure to call them in the find command below at lines 28:49 and 30:49.
 CUSTOMDIR1=""
 CUSTOMDIR2=""
 
-# REQUIRED VARIABLES
 nnnpluginsdir="$HOME/.config/nnn/plugins"
 
-# PREVIEW WITH bat INSTEAD OF cat IF INSTALLED
+# Preview with bat if installed
 if [ -z "$(command -v bat)" ]; then
     plugin=$(find "$nnnpluginsdir" "$CUSTOMDIR1" "$CUSTOMDIR2" -maxdepth 3 -perm -111 -type f 2>/dev/null | fzf --ansi --preview 'cat {}' --preview-window right:66% --delimiter / --with-nth -1 --bind="?:toggle-preview")
 else
     plugin=$(find "$nnnpluginsdir" "$CUSTOMDIR1" "$CUSTOMDIR2" -maxdepth 3 -perm -111 -type f 2>/dev/null | fzf --ansi --preview 'bat --color=always --style=grid {}' --preview-window right:66% --delimiter / --with-nth -1 --bind="?:toggle-preview")
 fi
 
-# TRY RUNNING THE SCRIPT ON HOVERED FILE FIRST, AND ABORT IF NO PLUGIN WAS SELECTED IN FZFPLUG (ESC OR ^C),
+# Try running the script on the hovered file, and abort if no plugin was selected (ESC or ^C pressed),
 err=0
 if ! [ "$plugin" = "" ]; then
     "$plugin" "$1" || err=1
 fi
 
-# IF THAT FAILS WITH HOVERED FILE, TRY WITH NO TARGET (nnn SELECTIONS SHOULD STILL BE PASSED TO THE SCRIPT IN THAT CASE)
+# If attempt with hovered file fails, try without any target
+# (nnn selections should still be passed to the script int hat case)
 if [ "$err" -eq "1" ]; then
     clear && "$plugin" || err=2
 fi
 
-# IF THAT FAILS TOO, ABORT AND SHOW AN ERROR
+# Abort and show error if both fail
 if [ "$err" -eq "2" ]; then
     sep="\n---\n"
     printf "$sep""Failed to execute '%s'. See error above or try without fzfplug. Press return to continue. " "$plugin" && read -r _ && clear
index 049cf9dca49d8c400ef6e4a95bab110e33ddfa41..a79cee0a90ce5bf17efebfb0761fe3e3110bccd8 100755 (executable)
@@ -7,7 +7,7 @@
 
 . "$(dirname "$0")"/.nnn-plugin-helper
 
-if which fzf >/dev/null 2>&1; then
+if type fzf >/dev/null 2>&1; then
     fuzzy=fzf
 else
     exit 1
index d8750746bc5faeb3f22122156613329bf26d021f..361a605fdbe29ac019a72af823e189c8329da655 100755 (executable)
@@ -8,13 +8,8 @@
 CONFIG_DIR=${XDG_CONFIG_HOME:-$HOME/.config}/nnn/
 PLUGIN_DIR=${XDG_CONFIG_HOME:-$HOME/.config}/nnn/plugins
 
-# is_cmd_exists () {
-#     which "$1" > /dev/null 2>&1
-#     echo $?
-# }
-
 merge () {
-       if which nvim >/dev/null 2>&1; then
+       if type nvim >/dev/null 2>&1; then
                nvim -d "$1" "$2"
        else
                vimdiff +0 "$1" "$2"
@@ -35,18 +30,10 @@ prompt () {
        fi
 }
 
-# if [ "$(is_cmd_exists sudo)" -eq "0" ]; then
-#     sucmd=sudo
-# elif [ "$(is_cmd_exists doas)" -eq "0" ]; then
-#     sucmd=doas
-# else
-#     sucmd=: # noop
-# fi
-
 if [ "$1" = "master" ] ; then
     VER="master"
     ARCHIVE_URL=https://github.com/jarun/nnn/archive/master.tar.gz
-elif which nnn >/dev/null 2>&1; then
+elif type nnn >/dev/null 2>&1; then
     VER=$(nnn -V)
     ARCHIVE_URL=https://github.com/jarun/nnn/releases/download/v"$VER"/nnn-v"$VER".tar.gz
 else
index 22936bc8398de8b0151d1a7f839ac00f6fe968fa..ad6e97fac47089be148f5f71ab03c8fe5dc2b35a 100755 (executable)
@@ -7,7 +7,7 @@
 # Author: Arun Prakash Jana
 
 if [ -n "$1" ]; then
-    if which hx >/dev/null 2>&1; then
+    if type hx >/dev/null 2>&1; then
         hx "$1"
     else
         xxd "$1" | $PAGER
index 2da549c62ba72510c78d09200c6eb003b00bd966..c6a46ae1f681de52c83f8f1cd91349e0075ba87f 100755 (executable)
@@ -117,23 +117,23 @@ fi
 
 # dependency check
 if [ "${1}" = "--check" ]; then
-  (which grep &>/dev/null && echo "OK: found grep") || echo "ERROR: grep not found"
+  (type grep &>/dev/null && echo "OK: found grep") || echo "ERROR: grep not found"
   if is_mac; then
-    if which growlnotify &>/dev/null; then
+    if type growlnotify &>/dev/null; then
       echo "OK: found growlnotify"
-    elif which terminal-notifier &>/dev/null; then
+    elif type terminal-notifier &>/dev/null; then
       echo "OK: found terminal-notifier"
     else
       echo "ERROR: growlnotify nor terminal-notifier found"
     fi
-    (which screencapture &>/dev/null && echo "OK: found screencapture") || echo "ERROR: screencapture not found"
-    (which pbcopy &>/dev/null && echo "OK: found pbcopy") || echo "ERROR: pbcopy not found"
+    (type screencapture &>/dev/null && echo "OK: found screencapture") || echo "ERROR: screencapture not found"
+    (type pbcopy &>/dev/null && echo "OK: found pbcopy") || echo "ERROR: pbcopy not found"
   else
-    (which notify-send &>/dev/null && echo "OK: found notify-send") || echo "ERROR: notify-send (from libnotify-bin) not found"
-    (which scrot &>/dev/null && echo "OK: found scrot") || echo "ERROR: scrot not found"
-    (which xclip &>/dev/null && echo "OK: found xclip") || echo "ERROR: xclip not found"
+    (type notify-send &>/dev/null && echo "OK: found notify-send") || echo "ERROR: notify-send (from libnotify-bin) not found"
+    (type scrot &>/dev/null && echo "OK: found scrot") || echo "ERROR: scrot not found"
+    (type xclip &>/dev/null && echo "OK: found xclip") || echo "ERROR: xclip not found"
   fi
-  (which curl &>/dev/null && echo "OK: found curl") || echo "ERROR: curl not found"
+  (type curl &>/dev/null && echo "OK: found curl") || echo "ERROR: curl not found"
   exit 0
 fi
 
@@ -141,7 +141,7 @@ fi
 # notify <'ok'|'error'> <title> <text>
 function notify() {
   if is_mac; then
-    if which growlnotify &>/dev/null; then
+    if type growlnotify &>/dev/null; then
       growlnotify  --icon "${imgur_icon_path}" --iconpath "${imgur_icon_path}" --title "${2}" --message "${3}"
     else
       terminal-notifier -appIcon "${imgur_icon_path}" -contentImage "${imgur_icon_path}" -title "imgur: ${2}" -message "${3}"
index 42f60cdec7669ea012c4e83955182437f4b0704a..9a3083229af54e1da4a58e74e3192d0bd092126d 100755 (executable)
@@ -49,19 +49,19 @@ if uname | grep -q "Darwin"; then
     fi
 # `imvr` is often callable as `imv` on Linux distros
 # You might need to change the reference below
-elif which imvr >/dev/null 2>&1; then
+elif type imvr >/dev/null 2>&1; then
     if [ -f "$1" ]; then
         view_dir imvr "$1" >/dev/null 2>&1 &
     elif [ -d "$1" ] || [ -h "$1" ]; then
         imvr "$1" >/dev/null 2>&1 &
     fi
-elif which sxiv >/dev/null 2>&1; then
+elif type sxiv >/dev/null 2>&1; then
     if [ -f "$1" ]; then
         view_dir sxiv "$1" >/dev/null 2>&1 &
     elif [ -d "$1" ] || [ -h "$1" ]; then
         sxiv -aqt "$1" >/dev/null 2>&1 &
     fi
-elif which viu >/dev/null 2>&1; then
+elif type viu >/dev/null 2>&1; then
     viu -n "$1" | less -R
 else
     printf "Please install imv/sxiv/viu and check their callable names match the plugin source"
index c131235e78ba79a55895155153623b923ab93ef7..d666cc565c795e0f6c8a21d470c874ae1abfdce6 100755 (executable)
@@ -24,7 +24,7 @@
 IFS=':'
 
 get_selection() {
-    if which fzf >/dev/null 2>&1; then
+    if type fzf >/dev/null 2>&1; then
         { IFS=':'; ls -H $PATH; } | sort | fzf
     else
         exit 1
index 10d478cdb39e68ecf3c6b6995f484e092688c7b2..1018a621af38e4c0eaf5024f392d55f5aad6a78c 100755 (executable)
@@ -91,36 +91,36 @@ handle_pdf() {
     if [ "$GUI" -ne 0 ] && is_mac; then
         nohup open "${FPATH}" >/dev/null 2>&1 &
         exit 0
-    elif [ "$GUI" -ne 0 ] && which zathura >/dev/null 2>&1; then
+    elif [ "$GUI" -ne 0 ] && type zathura >/dev/null 2>&1; then
         nohup zathura "${FPATH}" >/dev/null 2>&1 &
         exit 0
-    elif which pdftotext >/dev/null 2>&1; then
+    elif type pdftotext >/dev/null 2>&1; then
         ## Preview as text conversion
         pdftotext -l 10 -nopgbrk -q -- "${FPATH}" - | eval "$PAGER"
         exit 0
-    elif which mutool >/dev/null 2>&1; then
+    elif type mutool >/dev/null 2>&1; then
         mutool draw -F txt -i -- "${FPATH}" 1-10 | eval "$PAGER"
         exit 0
-    elif which exiftool >/dev/null 2>&1; then
+    elif type exiftool >/dev/null 2>&1; then
         exiftool "${FPATH}" | eval "$PAGER"
         exit 0
     fi
 }
 
 handle_audio() {
-    if which mocp >/dev/null 2>&1 && which mocplay >/dev/null 2>&1; then
+    if type mocp >/dev/null 2>&1 && type mocplay >/dev/null 2>&1; then
         mocplay "${FPATH}" "opener" >/dev/null 2>&1
         exit 0
-    elif which mpv >/dev/null 2>&1; then
+    elif type mpv >/dev/null 2>&1; then
         mpv "${FPATH}" >/dev/null 2>&1 &
         exit 0
-    elif which media_client >/dev/null 2>&1; then
+    elif type media_client >/dev/null 2>&1; then
         media_client play "${FPATH}" >/dev/null 2>&1 &
         exit 0
-    elif which mediainfo >/dev/null 2>&1; then
+    elif type mediainfo >/dev/null 2>&1; then
         mediainfo "${FPATH}" | eval "$PAGER"
         exit 0
-    elif which exiftool >/dev/null 2>&1; then
+    elif type exiftool >/dev/null 2>&1; then
         exiftool "${FPATH}"| eval "$PAGER"
         exit 0
     fi
@@ -130,22 +130,22 @@ handle_video() {
     if [ "$GUI" -ne 0 ] && is_mac; then
         nohup open "${FPATH}" >/dev/null 2>&1 &
         exit 0
-    elif [ "$GUI" -ne 0 ] && which smplayer >/dev/null 2>&1; then
+    elif [ "$GUI" -ne 0 ] && type smplayer >/dev/null 2>&1; then
         nohup smplayer "${FPATH}" >/dev/null 2>&1 &
         exit 0
-    elif [ "$GUI" -ne 0 ] && which mpv >/dev/null 2>&1; then
+    elif [ "$GUI" -ne 0 ] && type mpv >/dev/null 2>&1; then
         nohup mpv "${FPATH}" >/dev/null 2>&1 &
         exit 0
-    elif which ffmpegthumbnailer >/dev/null 2>&1; then
+    elif type ffmpegthumbnailer >/dev/null 2>&1; then
         # Thumbnail
         [ -d "${IMAGE_CACHE_PATH}" ] || mkdir "${IMAGE_CACHE_PATH}"
         ffmpegthumbnailer -i "${FPATH}" -o "${IMAGE_CACHE_PATH}/${FNAME}.jpg" -s 0
         viu -n "${IMAGE_CACHE_PATH}/${FNAME}.jpg" | eval "$PAGER"
         exit 0
-    elif which mediainfo >/dev/null 2>&1; then
+    elif type mediainfo >/dev/null 2>&1; then
         mediainfo "${FPATH}" | eval "$PAGER"
         exit 0
-    elif which exiftool >/dev/null 2>&1; then
+    elif type exiftool >/dev/null 2>&1; then
         exiftool "${FPATH}"| eval "$PAGER"
         exit 0
     fi
@@ -157,22 +157,22 @@ handle_extension() {
         ## Archive
         a|ace|alz|arc|arj|bz|bz2|cab|cpio|deb|gz|jar|lha|lz|lzh|lzma|lzo|\
         rpm|rz|t7z|tar|tbz|tbz2|tgz|tlz|txz|tZ|tzo|war|xpi|xz|Z|zip)
-            if which atool >/dev/null 2>&1; then
+            if type atool >/dev/null 2>&1; then
                 atool --list -- "${FPATH}" | eval "$PAGER"
                 exit 0
-            elif which bsdtar >/dev/null 2>&1; then
+            elif type bsdtar >/dev/null 2>&1; then
                 bsdtar --list --file "${FPATH}" | eval "$PAGER"
                 exit 0
             fi
             exit 1;;
         rar)
-            if which unrar >/dev/null 2>&1; then
+            if type unrar >/dev/null 2>&1; then
                 ## Avoid password prompt by providing empty password
                 unrar lt -p- -- "${FPATH}" | eval "$PAGER"
             fi
             exit 1;;
         7z)
-            if which 7z >/dev/null 2>&1; then
+            if type 7z >/dev/null 2>&1; then
                 ## Avoid password prompt by providing empty password
                 7z l -p -- "${FPATH}" | eval "$PAGER"
                 exit 0
@@ -201,10 +201,10 @@ handle_extension() {
 
         ## BitTorrent
         torrent)
-            if which rtorrent >/dev/null 2>&1; then
+            if type rtorrent >/dev/null 2>&1; then
                 rtorrent "${FPATH}"
                 exit 0
-            elif which transmission-show >/dev/null 2>&1; then
+            elif type transmission-show >/dev/null 2>&1; then
                 transmission-show -- "${FPATH}"
                 exit 0
             fi
@@ -212,7 +212,7 @@ handle_extension() {
 
         ## OpenDocument
         odt|ods|odp|sxw)
-            if which odt2txt >/dev/null 2>&1; then
+            if type odt2txt >/dev/null 2>&1; then
                 ## Preview as text conversion
                 odt2txt "${FPATH}" | eval "$PAGER"
                 exit 0
@@ -221,10 +221,10 @@ handle_extension() {
 
         ## Markdown
         md)
-            if which glow >/dev/null 2>&1; then
+            if type glow >/dev/null 2>&1; then
                 glow -sdark "${FPATH}" | eval "$PAGER"
                 exit 0
-            elif which lowdown >/dev/null 2>&1; then
+            elif type lowdown >/dev/null 2>&1; then
                 lowdown -Tterm "${FPATH}" | eval "$PAGER"
                 exit 0
             fi
@@ -233,13 +233,13 @@ handle_extension() {
         ## HTML
         htm|html|xhtml)
             ## Preview as text conversion
-            if which w3m >/dev/null 2>&1; then
+            if type w3m >/dev/null 2>&1; then
                 w3m -dump "${FPATH}" | eval "$PAGER"
                 exit 0
-            elif which lynx >/dev/null 2>&1; then
+            elif type lynx >/dev/null 2>&1; then
                 lynx -dump -- "${FPATH}" | eval "$PAGER"
                 exit 0
-            elif which elinks >/dev/null 2>&1; then
+            elif type elinks >/dev/null 2>&1; then
                 elinks -dump "${FPATH}" | eval "$PAGER"
                 exit 0
             fi
@@ -247,10 +247,10 @@ handle_extension() {
 
         ## JSON
         json)
-            if which jq >/dev/null 2>&1; then
+            if type jq >/dev/null 2>&1; then
                 jq --color-output . "${FPATH}" | eval "$PAGER"
                 exit 0
-            elif which python >/dev/null 2>&1; then
+            elif type python >/dev/null 2>&1; then
                 python -m json.tool -- "${FPATH}" | eval "$PAGER"
                 exit 0
             fi
@@ -311,19 +311,19 @@ handle_multimedia() {
             if [ "$GUI" -ne 0 ] && is_mac; then
                 nohup open "${FPATH}" >/dev/null 2>&1 &
                 exit 0
-            elif [ "$GUI" -ne 0 ] && which imvr >/dev/null 2>&1; then
+            elif [ "$GUI" -ne 0 ] && type imvr >/dev/null 2>&1; then
                 load_dir imvr "${FPATH}" >/dev/null 2>&1 &
                 exit 0
-            elif [ "$GUI" -ne 0 ] && which sxiv >/dev/null 2>&1; then
+            elif [ "$GUI" -ne 0 ] && type sxiv >/dev/null 2>&1; then
                 load_dir sxiv "${FPATH}" >/dev/null 2>&1 &
                 exit 0
-            elif which viu >/dev/null 2>&1; then
+            elif type viu >/dev/null 2>&1; then
                 viu -n "${FPATH}" | eval "$PAGER"
                 exit 0
-            elif which img2txt >/dev/null 2>&1; then
+            elif type img2txt >/dev/null 2>&1; then
                 img2txt --gamma=0.6 -- "${FPATH}" | eval "$PAGER"
                 exit 0
-            elif which exiftool >/dev/null 2>&1; then
+            elif type exiftool >/dev/null 2>&1; then
                 exiftool "${FPATH}" | eval "$PAGER"
                 exit 0
             fi
@@ -466,11 +466,11 @@ handle_mime() {
 
         ## DjVu
         image/vnd.djvu)
-            if which djvutxt >/dev/null 2>&1; then
+            if type djvutxt >/dev/null 2>&1; then
                 ## Preview as text conversion (requires djvulibre)
                 djvutxt "${FPATH}" | eval "$PAGER"
                 exit 0
-            elif which exiftool >/dev/null 2>&1; then
+            elif type exiftool >/dev/null 2>&1; then
                 exiftool "${FPATH}" | eval "$PAGER"
                 exit 0
             fi
@@ -479,10 +479,10 @@ handle_mime() {
 }
 
 handle_fallback() {
-    if [ "$GUI" -ne 0 ] && which xdg-open >/dev/null 2>&1; then
+    if [ "$GUI" -ne 0 ] && type xdg-open >/dev/null 2>&1; then
         nohup xdg-open "${FPATH}" >/dev/null 2>&1 &
         exit 0
-    elif [ "$GUI" -ne 0 ] && which open >/dev/null 2>&1; then
+    elif [ "$GUI" -ne 0 ] && type open >/dev/null 2>&1; then
         nohup open "${FPATH}" >/dev/null 2>&1 &
         exit 0
     fi
index 43cb40bb08cf7bff42b0b8aa6a283365d22f80ef..0fcb31488f772d919ef7c10a6cdf9a84c29e91b5 100755 (executable)
@@ -54,11 +54,11 @@ PAGER=${PAGER:-"vim -R"}
 NUKE="${XDG_CONFIG_HOME:-$HOME/.config}/nnn/plugins/nuke"
 
 
-if which xterm >/dev/null 2>&1 ; then
+if type xterm >/dev/null 2>&1 ; then
     TERMINAL="xterm -into"
-elif which urxvt >/dev/null 2>&1 ; then
+elif type urxvt >/dev/null 2>&1 ; then
     TERMINAL="urxvt -embed"
-elif which st >/dev/null 2>&1 ; then
+elif type st >/dev/null 2>&1 ; then
     TERMINAL="st -w"
 else
     echo "No xembed term found" >&2
@@ -142,28 +142,28 @@ previewer_loop () {
 
         case "$MIME" in
             video/*)
-                if which mpv >/dev/null 2>&1 ; then
+                if type mpv >/dev/null 2>&1 ; then
                     mpv --force-window=immediate --loop-file --wid="$XID" "$FILE" &
                 else
                     term_nuke "$XID" "$FILE"
                 fi
                 ;;
             audio/*)
-                if which mpv >/dev/null 2>&1 ; then
+                if type mpv >/dev/null 2>&1 ; then
                     mpv --force-window=immediate --loop-file --wid="$XID" "$FILE" &
                 else
                     term_nuke "$XID" "$FILE"
                 fi
                 ;;
             image/*)
-                if which sxiv >/dev/null 2>&1 ; then
+                if type sxiv >/dev/null 2>&1 ; then
                     sxiv -e "$XID" "$FILE" &
                 else
                     term_nuke "$XID" "$FILE"
                 fi
                 ;;
             application/pdf)
-                if which zathura >/dev/null 2>&1 ; then
+                if type zathura >/dev/null 2>&1 ; then
                     zathura -e "$XID" "$FILE" &
                 else
                     term_nuke "$XID" "$FILE"
index 2b0d8d45e2610fe44f6c552f52d6630204a5a179..c0b055a1e56f45748a9fe03e6a241861e82226bf 100755 (executable)
@@ -138,7 +138,7 @@ togglepreview() {
 }
 
 exists() {
-    which "$1" >/dev/null 2>&1
+    type "$1" >/dev/null 2>&1
 }
 
 fifo_pager() {
index 4f03419dddb2b6550c085e13901221b768c4d24a..e50b3e416e52eb88771b4f8f1143885b27c22b32 100755 (executable)
@@ -158,7 +158,7 @@ togglepreview() {
 }
 
 exists() {
-    which "$1" >/dev/null 2>&1
+    type "$1" >/dev/null 2>&1
 }
 
 fifo_pager() {
index 89008097838677a39f54f280805de8c2dbfb191c..e01c7391d03356f5a033b4a583daaaf1fc61fa94 100755 (executable)
@@ -14,15 +14,15 @@ read -r psname
 
 # shellcheck disable=SC2009
 if [ -n "$psname" ]; then
-    if which sudo >/dev/null 2>&1; then
+    if type sudo >/dev/null 2>&1; then
         sucmd=sudo
-    elif which doas >/dev/null 2>&1; then
+    elif type doas >/dev/null 2>&1; then
         sucmd=doas
     else
         sucmd=: # noop
     fi
 
-    if which fzf >/dev/null 2>&1; then
+    if type fzf >/dev/null 2>&1; then
         fuzzy=fzf
     else
         exit 1
index 532434a9f92b2b8a8489eb9121d22da6f0c67d50..eb79435f76aebe6396c0baa03db7a9ac6e3cb2b4 100755 (executable)
 
 selection=${NNN_SEL:-${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection}
 
-if which qmv >/dev/null 2>&1; then
+if type qmv >/dev/null 2>&1; then
        batchrenamesel="qmv -fdo -da"
        batchrename="qmv -fdo -a"
-elif which vidir >/dev/null 2>&1; then
+elif type vidir >/dev/null 2>&1; then
        batchrenamesel="vidir"
        batchrename="vidir"
 else
index 7598525b361f9e9fc23772cd6827ad33bbfb37ec..e0fdfb5d6633005653c7c63cae8af7d0a045c52e 100755 (executable)
@@ -7,15 +7,10 @@
 
 EDITOR="${EDITOR:-vim}"
 
-is_cmd_exists () {
-    which "$1" > /dev/null 2>&1
-    echo $?
-}
-
-if [ "$(is_cmd_exists sudo)" -eq "0" ]; then
+if type sudo >/dev/null 2>&1; then
     sudo "$EDITOR" "$1"
-elif [ "$(is_cmd_exists sudoedit)" -eq "0" ]; then
+elif type sudoedit >/dev/null 2>&1; then
     sudoedit "$1"
-elif [ "$(is_cmd_exists doas)" -eq "0" ]; then
+elif type doas >/dev/null 2>&1; then
     doas "$EDITOR" "$1"
 fi
index 1d876ef819c47f339707d0c0786300e8df31823e..4abf6ab0931d746516c532dcc3fb1792a99ee251 100755 (executable)
 # TODO: Try better avoiding lazy unmount by forcing nnn context to leave the subfolder before fusermount.
 # I tried `printf "%s" "0c$m" > "$NNN_PIPE"` but this would break nnn UI all the time, see #854.
 
-# ENVIRONMENT
 err=0
 m=$HOME/.config/nnn/mounts
-if [ "$PWD" = "$m" ]; then  # ALLOW USING THE SCRIPT ON HOVERED DIRECTORY IF USER IS IN ~/.config/nnn/mounts
+if [ "$PWD" = "$m" ]; then
+    # Allow running the script on hovered directory if user is in ~/.config/nnn/mounts
     d="$1"
 else
     d=$(dirname "$(readlink -f "$1")" | grep -oP "^$m\K.*" | cut -d"/" -f2)
 fi
 
-# TEST IF USER IS CURRENTLY WITHIN $m OR A SUBFOLDER, ABORT IF NOT
-    if [ "$d" = "" ]; then
-        clear && printf "You are not in a remote folder mounted with nnn. Press return to continue. " && read -r _
+# Test if user is within $m or a subdir, abort if not
+if [ "$d" = "" ]; then
+    clear && printf "You are not in a remote folder mounted with nnn. Press return to continue. " && read -r _
+else
+    # Test if $m/$d is a mountpoint and try unmounting if it is
+    mountpoint -q -- "$m/$d"
+    if [ "$?" -eq "1" ]; then
+        clear && printf "Parent '%s' is not a mountpoint. Press return to continue. " "$d" && read -r _
     else
-        # TEST IF $m/$d IS A MOUNTPOINT AND TRY UNMOUNTING IF YES
-        mountpoint -q -- "$m/$d"
-        if [ "$?" -eq "1" ]; then
-            clear && printf "Parent '%s' is not a mountpoint. Press return to continue. " "$d" && read -r _
+        cd "$m" && fusermount -uq "$m/$d" || err=1
+        if [ "$err" -eq "0" ]; then
+            rmdir "$m/$d" && clear && printf "Parent '%s' unmounted." "$d"
         else
-            cd "$m" && fusermount -uq "$m/$d" || err=1
-            if [ "$err" -eq "0" ]; then
-                rmdir "$m/$d" && clear && printf "Parent '%s' unmounted." "$d"
-            else
-                clear && printf "Failed to unmount. Try lazy unmount? [Yy/Nn] " && read -r
-            fi
+            clear && printf "Failed to unmount. Try lazy unmount? [Yy/Nn] " && read -r
         fi
     fi
+fi
 
-# IF FAILURE TO UNMOUNT, OFFER TO TRY LAZY UNMOUNT
-    if [ "$REPLY" = "y" ] || [ "$REPLY" = "Y" ]; then 
-        err=0
-        cd "$m" && fusermount -uqz "$m/$d" || err=1
-        if [ "$err" -eq "0" ]; then
-            rmdir "$m/$d" && clear && printf "Parent '%s' unmounted with lazy unmount. " "$d"
-        fi
+# If unmount fails, offer lazy unmount
+if [ "$REPLY" = "y" ] || [ "$REPLY" = "Y" ]; then
+    err=0
+    cd "$m" && fusermount -uqz "$m/$d" || err=1
+    if [ "$err" -eq "0" ]; then
+        rmdir "$m/$d" && clear && printf "Parent '%s' unmounted with lazy unmount. " "$d"
     fi
+fi
index 6a929a577ebf51a0abb497863ec6e09647aea8a5..0bbf5626d978c8d722daaa5afa559fe4611c0e8b 100755 (executable)
@@ -10,7 +10,7 @@
 # Author: Arun Prakash Jana
 
 if [ -n "$1" ] && [ -s "$1" ]; then
-    if which ffsend >/dev/null 2>&1; then
+    if type ffsend >/dev/null 2>&1; then
         ffsend -fiq u "$1"
     elif [ "$(mimetype --output-format %m "$1" | awk -F '/' '{print $1}')" = "text" ]; then
         curl -F "f:1=@$1" ix.io
index 2471d06615292dbe404f7d17b2a7b16446eb207a..a154134665826bf3b144e4ad1046973071e97781 100755 (executable)
@@ -6,16 +6,11 @@
 # Shell: POSIX Compliant
 # Author: juacq97
 
-cmd_exists () {
-       which "$1" > /dev/null 2>&1
-       echo $?
-}
-
 if [ -n "$1" ]; then
        if [ "$(file --mime-type "$1" | awk '{print $NF}' | awk -F '/' '{print $1}')" = "image" ]; then
-        if [ "$(cmd_exists nitrogen)" -eq "0" ]; then
+        if type nitrogen >/dev/null 2>&1; then
                nitrogen --set-zoom-fill --save "$1"
-        elif [ "$(cmd_exists wal)" -eq "0" ]; then
+        elif type wal >/dev/null 2>&1; then
                wal -i "$1"
         else
             printf "nitrogen ir pywal missing"
index 0a0fcd4ecf6debba64c5ea3dbde883e455a553ea..0e6cbad73077b5ac4de84c2d868479d5df575fe7 100755 (executable)
@@ -22,28 +22,28 @@ selection=${NNN_SEL:-${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection}
 
 getclip () {
 
-       if which xsel >/dev/null 2>&1; then
+       if type xsel >/dev/null 2>&1; then
                # Linux
                xsel -bo
-       elif which xclip >/dev/null 2>&1; then
+       elif type xclip >/dev/null 2>&1; then
                # Linux
                xclip -sel clip -o
-       elif which pbpaste >/dev/null 2>&1; then
+       elif type pbpaste >/dev/null 2>&1; then
                # macOS
                pbpaste
-       elif which termux-clipboard-get >/dev/null 2>&1; then
+       elif type termux-clipboard-get >/dev/null 2>&1; then
                # Termux
                termux-clipboard-get
-       elif which powershell.exe >/dev/null 2>&1; then
+       elif type powershell.exe >/dev/null 2>&1; then
                # WSL
                powershell.exe Get-Clipboard
        elif [ -r /dev/clipboard ] ; then
                # Cygwin
                cat /dev/clipboard
-       elif which wl-paste >/dev/null 2>&1; then
+       elif type wl-paste >/dev/null 2>&1; then
                # Wayland
                wl-paste
-       elif which clipboard >/dev/null 2>&1; then
+       elif type clipboard >/dev/null 2>&1; then
                # Haiku
                clipboard --print
        fi