2019-10-23 13:04:12 +03:00
|
|
|
#!/usr/bin/env sh
|
|
|
|
|
|
|
|
# Description: Helper script for plugins
|
|
|
|
#
|
|
|
|
# Shell: POSIX compliant
|
|
|
|
# Author: Anna Arad
|
|
|
|
|
2020-04-24 10:12:24 +05:30
|
|
|
selection=${NNN_SEL:-${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection}
|
2019-11-22 02:14:25 +05:30
|
|
|
export selection
|
2019-10-23 13:04:12 +03:00
|
|
|
|
2020-02-20 07:54:32 +05:30
|
|
|
## Set CUR_CTX to 1 to open directory in current context
|
|
|
|
CUR_CTX=0
|
|
|
|
export CUR_CTX
|
|
|
|
|
2019-10-23 13:04:12 +03:00
|
|
|
## Ask nnn to switch to directory $1 in context $2.
|
|
|
|
## If $2 is not provided, the function asks explicitly.
|
|
|
|
nnn_cd () {
|
2020-05-06 18:41:01 +05:30
|
|
|
dir="$1"
|
2019-10-23 13:04:12 +03:00
|
|
|
|
|
|
|
if [ -z "$NNN_PIPE" ]; then
|
|
|
|
echo "No pipe file found" 1>&2
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -n "$2" ]; then
|
|
|
|
context=$2
|
2020-02-20 07:54:32 +05:30
|
|
|
elif [ $CUR_CTX -ne 1 ]; then
|
2019-11-22 02:14:25 +05:30
|
|
|
printf "Choose context 1-4 (blank for current): "
|
|
|
|
read -r context
|
2019-10-23 13:04:12 +03:00
|
|
|
fi
|
|
|
|
|
2020-05-03 14:55:33 +05:30
|
|
|
printf "%s" "${context:-0}c$dir" > "$NNN_PIPE"
|
2019-10-23 13:04:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
cmd_exists () {
|
2021-05-15 06:57:20 +05:30
|
|
|
type "$1" > /dev/null 2>&1
|
|
|
|
echo $?
|
2019-10-23 13:04:12 +03:00
|
|
|
}
|