]> Sergey Matveev's repositories - nnn.git/commitdiff
Added fzfz plugin (#502)
authorNick Waywood <n.waywood@gmail.com>
Wed, 1 Apr 2020 12:35:52 +0000 (23:35 +1100)
committerGitHub <noreply@github.com>
Wed, 1 Apr 2020 12:35:52 +0000 (18:05 +0530)
* Added fzfz plugin

* Fixed shellcheck errors

* Fixed copy/paste error

plugins/README.md
plugins/fzfz [new file with mode: 0755]

index 7bee5469bf614338105a10d07bf04cb76647fc67..156e786eead85a06a1f599b98a7a18e74f1e2b9d 100644 (file)
@@ -33,6 +33,7 @@ Plugins are installed to `${XDG_CONFIG_HOME:-$HOME/.config}/nnn/plugins`.
 | 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) |
 | fzcd | Change to the directory of a fuzzy-selected file/dir | sh | fzf/fzy<br>fd/fdfind/find |
+| fzfz | Change to any directory in the z database with fzf | sh | fzf, z |
 | 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 |
diff --git a/plugins/fzfz b/plugins/fzfz
new file mode 100755 (executable)
index 0000000..cb5e08a
--- /dev/null
@@ -0,0 +1,23 @@
+#!/usr/bin/env sh
+
+# Description: cd to any dir in the z database using an fzf pane
+#
+# Shell: POSIX compliant
+# Author: Nick Waywood
+
+. "$(dirname "$0")"/.nnn-plugin-helper
+
+if [ "$(cmd_exists fzf)" -eq "0" ]; then
+    if [ -f "$HOME/.z" ]; then
+        # I read the data from z's file instead of calling the z command so that the data doesn't need to be processed twice
+        sel=$(awk -F "|" '{print $1}' "$HOME/.z" | fzf | awk '{$1=$1};1')
+        # NOTE: Uncomment this line and comment out the line above if you want to see the weightings of the dir's in the fzf pane
+        # sel=$(awk -F "|" '{printf "%s %s\n", $2, $1}' "$HOME/.z" | fzf | sed 's/^[0-9,.]* *//' | awk '{$1=$1};1')
+    else
+        exit 1
+    fi
+else
+    exit 1
+fi
+
+printf "%s" "0$sel" > "$NNN_PIPE"