aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/fzz
blob: 049cf9dca49d8c400ef6e4a95bab110e33ddfa41 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/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 which fzf >/dev/null 2>&1; then
    fuzzy=fzf
else
    exit 1
fi

datafile="${_Z_DATA:-$HOME/.z}"
if [ -f "$datafile" ]; 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}' "$datafile" | "$fuzzy" | 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}' "$datafile" | "$fuzzy" | sed 's/^[0-9,.]* *//' | awk '{$1=$1};1')
else
    exit 1
fi

printf "%s" "0c$sel" > "$NNN_PIPE"