.nnn-plugin-helper (791B)
1 #!/usr/bin/env sh 2 3 # Description: Helper script for plugins 4 # 5 # Shell: POSIX compliant 6 # Author: Anna Arad 7 8 selection=${NNN_SEL:-${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection} 9 export selection 10 11 ## Set CUR_CTX to 1 to open directory in current context 12 CUR_CTX=0 13 export CUR_CTX 14 15 ## Ask nnn to switch to directory $1 in context $2. 16 ## If $2 is not provided, the function asks explicitly. 17 nnn_cd () { 18 dir="$1" 19 20 if [ -z "$NNN_PIPE" ]; then 21 echo "No pipe file found" 1>&2 22 return 23 fi 24 25 if [ -n "$2" ]; then 26 context=$2 27 elif [ $CUR_CTX -ne 1 ]; then 28 printf "Choose context 1-4 (blank for current): " 29 read -r context 30 fi 31 32 printf "%s" "${context:-0}c$dir" > "$NNN_PIPE" 33 } 34 35 cmd_exists () { 36 type "$1" > /dev/null 2>&1 37 echo $? 38 }