]> Sergey Matveev's repositories - nnn.git/commitdiff
Support both fzf and fzy
authorArun Prakash Jana <engineerarun@gmail.com>
Mon, 9 Dec 2019 13:06:48 +0000 (18:36 +0530)
committerArun Prakash Jana <engineerarun@gmail.com>
Mon, 9 Dec 2019 13:06:48 +0000 (18:36 +0530)
plugins/README.md
plugins/fzcd
plugins/fzhist
plugins/fzopen
plugins/launch
plugins/pskill

index 1906df7ead67db88f4c79b11c6e83055e5da0339..4bf724b1e0fc9d4dd1d6d00148df381c17313762 100644 (file)
@@ -20,9 +20,9 @@ Plugins extend the capabilities of `nnn`. They are _executable_ scripts (or bina
 | diffs | Diff for selection (limited to 2 for directories) | sh | vimdiff |
 | dragdrop | Drag/drop files from/into nnn | sh | [dragon](https://github.com/mwh/dragon) |
 | exetoggle | Toggle executable status of hovered file | sh | chmod |
-| fzcd | Change to the directory of a fuzzy-selected file/dir | sh | fzf/fzy<br>(optional fd) |
-| fzhist | Fuzzy-select a cmd from history, edit in `$EDITOR` and run | sh | fzy |
-| fzopen | Fuzzy find a file in dir subtree and edit or open | sh | fzy, xdg-open |
+| fzcd | Change to the directory of a fuzzy-selected file/dir | sh | fzf/fzy<br>fd/fdfind/find |
+| fzhist | Fuzzy-select a cmd from history, edit in `$EDITOR` and run | sh | fzf/fzy |
+| fzopen | Fuzzy find a file in dir subtree and edit or open | sh | fzf/fzy, xdg-open |
 | getplugs | Update plugins | sh | curl |
 | gutenread | Browse, download, read from Project Gutenberg | sh | curl, unzip, w3m<br>[epr](https://github.com/wustho/epr) (optional) |
 | hexview | View a file in hex in `$PAGER` | sh | xxd |
@@ -46,7 +46,7 @@ Plugins extend the capabilities of `nnn`. They are _executable_ scripts (or bina
 | pdfread | Read a PDF or text file aloud | sh | pdftotext, mpv,<br>pico2wave |
 | pdfview | View PDF file in `$PAGER` | sh | pdftotext/<br>mupdf-tools |
 | picker | Pick files and list one per line (to pipe) | sh | nnn |
-| pskill | Fuzzy list by name and kill process or zombie | sh | fzy, sudo/doas |
+| pskill | Fuzzy list by name and kill process or zombie | sh | fzf/fzy, ps,<br>sudo/doas |
 | renamer | Batch rename selection or files in dir | sh | [qmv](https://www.nongnu.org/renameutils/)/[vidir](https://joeyh.name/code/moreutils/) |
 | ringtone | Create a variable bitrate mp3 ringtone from file | sh | date, ffmpeg |
 | splitjoin | Split file or join selection | sh | split, cat |
index d10b119fa5a011117855db6ca36dd9e1fd6f527d..88f5397691c0b36878522a574585ec2b73430cb5 100755 (executable)
@@ -1,6 +1,6 @@
 #!/usr/bin/env sh
 
-# Description: Run fzf/fzy/fd/fdfind/find and go to the directory of the file selected
+# Description: Run fzf/fzyfd/fdfind/find and go to the directory of the file selected
 #
 # Shell: POSIX compliant
 # Author: Anna Arad
index c47efa25a1c17db9e3dc5bd523748c0851dad83a..e5618ae93838f9dc4c55f3ae0f000c427a0abfbd 100755 (executable)
@@ -6,14 +6,22 @@
 # Shell: POSIX compliant
 # Author: Arun Prakash Jana
 
+if which fzf >/dev/null 2>&1; then
+    fuzzy=fzf
+elif which fzy >/dev/null 2>&1; then
+    fuzzy=fzy
+else
+    exit 1
+fi
+
 shellname="$(basename "$SHELL")"
 
 if [ "$shellname" = "bash" ]; then
     hist_file="$HOME/.bash_history"
-    entry="$(fzy < "$hist_file")"
+    entry="$("$fuzzy" < "$hist_file")"
 elif [ "$shellname" = "fish" ]; then
     hist_file="$HOME/.config/fish/fish_history"
-    entry="$(grep "\- cmd: " "$hist_file" | cut -c 8- | fzy)"
+    entry="$(grep "\- cmd: " "$hist_file" | cut -c 8- | "$fuzzy")"
 fi
 
 if ! [ -z "$entry" ]; then
index 046e7e91d7e187988137ef31abf505893c571561..91a504d525c2611911e59263b2e0e0739ca7175a 100755 (executable)
@@ -4,10 +4,20 @@
 #              Opens in $VISUAL or $EDITOR if text
 #              Opens other type of files with xdg-open
 #
+# Requires: fzf/fzy, xdg-open
+#
 # Shell: POSIX compliant
 # Author: Arun Prakash Jana
 
-entry="$(find . -type f 2>/dev/null | fzy)"
+if which fzf >/dev/null 2>&1; then
+    fuzzy=fzf
+elif which fzy >/dev/null 2>&1; then
+    fuzzy=fzy
+else
+    exit 1
+fi
+
+entry="$(find . -type f 2>/dev/null | "$fuzzy")"
 
 case "$(file -biL "$entry")" in
     *text*)
index 018aca3056821f85c3ae554280e70ff43bb9e123..0444e91b23002ba7b31c9badb7971f82adc5044f 100755 (executable)
@@ -9,7 +9,7 @@
 #
 #              xfce4-terminal -e "${XDG_CONFIG_HOME:-$HOME/.config}/nnn/plugins/launch
 #
-# Requires: fzf or fzy
+# Requires: fzf/fzy
 #
 # Usage: launch [delay]
 #        delay is in seconds, if omitted launch waits for 1 sec
@@ -25,7 +25,7 @@ IFS=':'
 
 get_selection() {
     if which fzf >/dev/null 2>&1; then
-        { IFS=':'; ls -H $PATH; } | sort | fzy
+        { IFS=':'; ls -H $PATH; } | sort | fzf
     elif which fzy >/dev/null 2>&1; then
         { IFS=':'; ls -H $PATH; } | sort | fzy
     else
index d02c9fa44c71d183256395cc2b5a6ed8d564107d..fdb5396dffb2dbfb57e1d817302e49ea6b7fa4f2 100755 (executable)
@@ -2,29 +2,34 @@
 
 # Description: Fuzzy list and kill a (zombie) process by name
 #
+# Requires: fzf or fzy, ps
+#
 # Note: To kill a zombie process enter "zombie"
 #
 # Shell: POSIX compliant
 # Author: Arun Prakash Jana
 
-is_cmd_exists () {
-    which "$1" > /dev/null 2>&1
-    echo $?
-}
-
-if [ "$(is_cmd_exists sudo)" -eq "0" ]; then
-    sucmd=sudo
-elif [ "$(is_cmd_exists doas)" -eq "0" ]; then
-    sucmd=doas
-else
-    sucmd=: # noop
-fi
-
 printf "Enter process name ['defunct' for zombies]: "
 read -r psname
 
+# shellcheck disable=SC2009
 if ! [ -z "$psname" ]; then
-    # shellcheck disable=SC2009
-    cmd="$(ps -ax | grep -iw "$psname" | fzy | sed -e 's/^[ \t]*//' | cut -d' ' -f1)"
+    if which sudo >/dev/null 2>&1; then
+        sucmd=sudo
+    elif which doas >/dev/null 2>&1; then
+        sucmd=doas
+    else
+        sucmd=: # noop
+    fi
+
+    if which fzf >/dev/null 2>&1; then
+        fuzzy=fzf
+    elif which fzy >/dev/null 2>&1; then
+        fuzzy=fzy
+    else
+        exit 1
+    fi
+
+    cmd="$(ps -ax | grep -iw "$psname" | "$fuzzy" | sed -e 's/^[ \t]*//' | cut -d' ' -f1)"
     $sucmd kill -9 "$cmd"
 fi