| 1 |
#!/usr/bin/env sh |
| 2 |
|
| 3 |
# Description: Navigate to directory using jump/autojump/zoxide/z |
| 4 |
# |
| 5 |
# Dependencies: |
| 6 |
# - jump - https://github.com/gsamokovarov/jump |
| 7 |
# - OR autojump - https://github.com/wting/autojump |
| 8 |
# - OR zoxide - https://github.com/ajeetdsouza/zoxide |
| 9 |
# - OR z - https://github.com/rupa/z (z requires fzf) |
| 10 |
# - OR z (fish) - https://github.com/jethrokuan/z (z requires fzf) |
| 11 |
# - OR z.lua - https://github.com/skywind3000/z.lua (z.lua can enhanced with fzf) |
| 12 |
# |
| 13 |
# Note: The dependencies STORE NAVIGATION PATTERNS |
| 14 |
# |
| 15 |
# to make z.lua work, you need to set $NNN_ZLUA to the path of script z.lua |
| 16 |
# |
| 17 |
# Shell: POSIX compliant |
| 18 |
# Authors: Marty Buchaus, Dave Snider, Tim Adler, Nick Waywood, Markus Meier |
| 19 |
|
| 20 |
if [ ! -p "$NNN_PIPE" ]; then |
| 21 |
printf 'ERROR: NNN_PIPE is not set!' |
| 22 |
read -r _ |
| 23 |
exit 2 |
| 24 |
fi |
| 25 |
|
| 26 |
if type jump >/dev/null 2>&1; then |
| 27 |
printf "jump to: " |
| 28 |
IFS= read -r line |
| 29 |
# shellcheck disable=SC2086 |
| 30 |
odir="$(jump cd ${line})" |
| 31 |
printf "%s" "0c$odir" > "$NNN_PIPE" |
| 32 |
elif type autojump >/dev/null 2>&1; then |
| 33 |
printf "jump to: " |
| 34 |
read -r dir |
| 35 |
odir="$(autojump "$dir")" |
| 36 |
printf "%s" "0c$odir" > "$NNN_PIPE" |
| 37 |
elif type zoxide >/dev/null 2>&1; then |
| 38 |
if type fzf >/dev/null 2>&1; then |
| 39 |
odir="$(zoxide query -i --)" |
| 40 |
printf "%s" "0c$odir" > "$NNN_PIPE" |
| 41 |
else |
| 42 |
printf "jump to: " |
| 43 |
read -r dir |
| 44 |
odir="$(zoxide query -- "$dir")" |
| 45 |
printf "%s" "0c$odir" > "$NNN_PIPE" |
| 46 |
fi |
| 47 |
elif type lua >/dev/null 2>&1 && [ -n "$NNN_ZLUA" ]; then |
| 48 |
if type fzf >/dev/null 2>&1; then |
| 49 |
odir="$(lua "$NNN_ZLUA" -l \ |
| 50 |
| awk '{print $2}' \ |
| 51 |
| fzf --nth -1 --delimiter=/ --reverse --inline-info --tac +s -e --height 35%)" |
| 52 |
printf "0c%s" "$odir" > "$NNN_PIPE" |
| 53 |
else |
| 54 |
printf "jump to: " |
| 55 |
read -r line |
| 56 |
odir="$(lua "$NNN_ZLUA" -e "$line")" |
| 57 |
printf "%s" "0c$odir" > "$NNN_PIPE" |
| 58 |
fi |
| 59 |
else |
| 60 |
# rupa/z uses $_Z_DATA, jethrokuan/z (=port of z for fish) uses $Z_DATA |
| 61 |
datafile="${_Z_DATA:-${Z_DATA:-$HOME/.z}}" |
| 62 |
if type fzf >/dev/null 2>&1 && [ -f "$datafile" ]; then |
| 63 |
# Read the data from z's file instead of calling |
| 64 |
# z so the data doesn't need to be processed twice |
| 65 |
sel=$(awk -F "|" '{print $1}' "$datafile" | fzf | awk '{$1=$1};1') |
| 66 |
|
| 67 |
# NOTE: Uncomment this line and comment out the line above if |
| 68 |
# you want to see the weightings of the dir's in the fzf pane |
| 69 |
# sel=$(awk -F "|" '{printf "%s %s\n", $2, $1}' "$datafile" | fzf | sed 's/^[0-9,.]* *//' | awk '{$1=$1};1') |
| 70 |
|
| 71 |
printf "%s" "0c$sel" > "$NNN_PIPE" |
| 72 |
else |
| 73 |
printf "No supported autojump script [jump/autojump/zoxide/z (needs fzf)] found" |
| 74 |
read -r _ |
| 75 |
fi |
| 76 |
fi |