aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorGravatar Todd Yamakawa <toddyamakawa@users.noreply.github.com>2020-06-03 14:17:46 -0500
committerGravatar GitHub <noreply@github.com>2020-06-04 00:47:46 +0530
commit995fa1ceb678b138eef03a09effff73dc07a0558 (patch)
tree8338ec4c56e3cf22b583509359097dad6467f5ec /plugins
parent58fd92c7aee2bd068c612e98c0272b133e32f791 (diff)
downloadnnn-995fa1ceb678b138eef03a09effff73dc07a0558.tar.gz
bookmarks: Pipe error to PAGER and clean up code (#631)
Co-authored-by: Todd Yamakawa <todd.yamakawa@arm.com>
Diffstat (limited to 'plugins')
-rwxr-xr-xplugins/bookmarks12
1 files changed, 8 insertions, 4 deletions
diff --git a/plugins/bookmarks b/plugins/bookmarks
index c17d9e2..614b20f 100755
--- a/plugins/bookmarks
+++ b/plugins/bookmarks
@@ -17,6 +17,7 @@
# `ln -s /path/to/movies movies`
#
# Bonus tip: Add `$BOOKMARKS_DIR` to your `$CDPATH`
+# https://linux.101hacks.com/cd-command/cdpath/
#
# TODO:
# 1. Remove `fzf` dependency
@@ -27,7 +28,10 @@
BOOKMARKS_DIR="${XDG_CACHE_HOME:-$HOME/.cache}/nnn/bookmarks"
# Check if NNN_PIPE is set
-[ -z "$NNN_PIPE" ] && { echo 'NNN_PIPE is not set'; exit 2; }
+if [ -z "$NNN_PIPE" ]; then
+ echo 'ERROR: NNN_PIPE is not set' | ${PAGER:-less}
+ exit 2
+fi
# Get all directory symlinks
get_links() {
@@ -37,12 +41,12 @@ get_links() {
[ -h "$entry" ] || continue
[ -d "$entry" ] || continue
- echo "$(basename "$entry") -> $(readlink -f "$entry")"
- done | column -t
+ printf "%20s -> %s\n" "$(basename "$entry")" "$(readlink -f "$entry")"
+ done | fzf | awk 'END { print "'"$BOOKMARKS_DIR"'/"$1 }'
}
# Choose symlink with fzf
-cddir="$(get_links "$BOOKMARKS_DIR" | fzf | awk 'END { print "'"$BOOKMARKS_DIR"'/"$1 }')"
+cddir="$(get_links "$BOOKMARKS_DIR")"
# Writing result to NNN_PIPE will change nnn's active directory
# https://github.com/jarun/nnn/tree/master/plugins#send-data-to-nnn