autojump (2645B)
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 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 printf "jump to : " 49 read -r line 50 if type fzf >/dev/null 2>&1; then 51 odir="$(lua "$NNN_ZLUA" -l "$line" | fzf --nth 2.. --reverse --inline-info --tac +s -e --height 35%)" 52 printf "%s" "0c$(echo "$odir" | awk '{print $2}')" > "$NNN_PIPE" 53 else 54 odir="$(lua "$NNN_ZLUA" -e "$line")" 55 printf "%s" "0c$odir" > "$NNN_PIPE" 56 fi 57 else 58 # rupa/z uses $_Z_DATA, jethrokuan/z (=port of z for fish) uses $Z_DATA 59 datafile="${_Z_DATA:-${Z_DATA:-$HOME/.z}}" 60 if type fzf >/dev/null 2>&1 && [ -f "$datafile" ]; then 61 # Read the data from z's file instead of calling 62 # z so the data doesn't need to be processed twice 63 sel=$(awk -F "|" '{print $1}' "$datafile" | fzf | awk '{$1=$1};1') 64 65 # NOTE: Uncomment this line and comment out the line above if 66 # you want to see the weightings of the dir's in the fzf pane 67 # sel=$(awk -F "|" '{printf "%s %s\n", $2, $1}' "$datafile" | fzf | sed 's/^[0-9,.]* *//' | awk '{$1=$1};1') 68 69 printf "%s" "0c$sel" > "$NNN_PIPE" 70 else 71 printf "No supported autojump script [jump/autojump/zoxide/z (needs fzf)] found" 72 read -r _ 73 fi 74 fi