3 # Description: Helper script for plugins
5 # Shell: POSIX compliant
8 selection=${NNN_SEL:-${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection}
11 ## Set CUR_CTX to 1 to open directory in current context
15 NNN_PREFER_SELECTION="${NNN_PREFER_SELECTION:-0}"
16 export NNN_PREFER_SELECTION
18 ## Ask nnn to switch to directory $1 in context $2.
19 ## If $2 is not provided, the function asks explicitly.
23 if [ -z "$NNN_PIPE" ]; then
24 echo "No pipe file found" 1>&2
30 elif [ $CUR_CTX -ne 1 ]; then
31 printf "Choose context 1-4 (blank for current): "
35 printf "%s" "${context:-0}c$dir" > "$NNN_PIPE"
39 type "$1" > /dev/null 2>&1
44 if ! [ -s "$selection" ]; then
48 if [ "$NNN_PREFER_SELECTION" -eq 1 ]; then
51 [ -n "$1" ] && printf "%s " "$1"
52 printf "(s)election/(c)urrent? [default=c] "
55 if [ "$resp__" = "s" ]; then