autojump (2058B)
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 # 12 # Note: The dependencies STORE NAVIGATION PATTERNS 13 # 14 # Shell: POSIX compliant 15 # Authors: Marty Buchaus, Dave Snider, Tim Adler, Nick Waywood 16 17 if [ ! -p "$NNN_PIPE" ]; then 18 printf 'ERROR: NNN_PIPE is not set!' 19 read -r _ 20 exit 2 21 fi 22 23 if type jump >/dev/null 2>&1; then 24 printf "jump to : " 25 IFS= read -r line 26 # shellcheck disable=SC2086 27 odir="$(jump cd ${line})" 28 printf "%s" "0c$odir" > "$NNN_PIPE" 29 elif type autojump >/dev/null 2>&1; then 30 printf "jump to : " 31 read -r dir 32 odir="$(autojump "$dir")" 33 printf "%s" "0c$odir" > "$NNN_PIPE" 34 elif type zoxide >/dev/null 2>&1; then 35 if type fzf >/dev/null 2>&1; then 36 odir="$(zoxide query -i --)" 37 printf "%s" "0c$odir" > "$NNN_PIPE" 38 else 39 printf "jump to : " 40 read -r dir 41 odir="$(zoxide query -- "$dir")" 42 printf "%s" "0c$odir" > "$NNN_PIPE" 43 fi 44 else 45 # rupa/z uses $_Z_DATA, jethrokuan/z (=port of z for fish) uses $Z_DATA 46 datafile="${_Z_DATA:-${Z_DATA:-$HOME/.z}}" 47 if type fzf >/dev/null 2>&1 && [ -f "$datafile" ]; then 48 # Read the data from z's file instead of calling 49 # z so the data doesn't need to be processed twice 50 sel=$(awk -F "|" '{print $1}' "$datafile" | fzf | awk '{$1=$1};1') 51 52 # NOTE: Uncomment this line and comment out the line above if 53 # you want to see the weightings of the dir's in the fzf pane 54 # sel=$(awk -F "|" '{printf "%s %s\n", $2, $1}' "$datafile" | fzf | sed 's/^[0-9,.]* *//' | awk '{$1=$1};1') 55 56 printf "%s" "0c$sel" > "$NNN_PIPE" 57 else 58 printf "No supported autojump script [jump/autojump/zoxide/z (needs fzf)] found" 59 read -r _ 60 fi 61 fi