diff options
| author | Anton Bobov <anton@bobov.name> | 2023-08-23 19:43:08 +0500 |
|---|---|---|
| committer | Anton Bobov <anton@bobov.name> | 2023-08-23 19:43:08 +0500 |
| commit | 6dab4cddfaa9ae393301d23b8c7456dee39a0ad8 (patch) | |
| tree | 63f6e443850cffe020d76c2a81db06d256edb1f9 /files/.config/nnn/plugins/.nnn-plugin-helper | |
| parent | 5694227f8d2c4b5c5e6da251a496b808b7b59897 (diff) | |
[nnn] Add plugins
Diffstat (limited to 'files/.config/nnn/plugins/.nnn-plugin-helper')
| -rwxr-xr-x | files/.config/nnn/plugins/.nnn-plugin-helper | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/files/.config/nnn/plugins/.nnn-plugin-helper b/files/.config/nnn/plugins/.nnn-plugin-helper new file mode 100755 index 0000000..118e6c7 --- /dev/null +++ b/files/.config/nnn/plugins/.nnn-plugin-helper @@ -0,0 +1,61 @@ +#!/usr/bin/env sh + +# Description: Helper script for plugins +# +# Shell: POSIX compliant +# Author: Anna Arad + +selection=${NNN_SEL:-${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection} +export selection + +## Set CUR_CTX to 1 to open directory in current context +CUR_CTX=0 +export CUR_CTX + +NNN_PREFER_SELECTION="${NNN_PREFER_SELECTION:-0}" +export NNN_PREFER_SELECTION + +## Ask nnn to switch to directory $1 in context $2. +## If $2 is not provided, the function asks explicitly. +nnn_cd () { + dir="$1" + + if [ -z "$NNN_PIPE" ]; then + echo "No pipe file found" 1>&2 + return + fi + + if [ -n "$2" ]; then + context=$2 + elif [ $CUR_CTX -ne 1 ]; then + printf "Choose context 1-4 (blank for current): " + read -r context + fi + + printf "%s" "${context:-0}c$dir" > "$NNN_PIPE" +} + +cmd_exists () { + type "$1" > /dev/null 2>&1 + echo $? +} + +nnn_use_selection() { + if ! [ -s "$selection" ]; then + return 1 + fi + + if [ "$NNN_PREFER_SELECTION" -eq 1 ]; then + return 0 + else + [ -n "$1" ] && printf "%s " "$1" + printf "(s)election/(c)urrent? [default=c] " + read -r resp__ + + if [ "$resp__" = "s" ]; then + return 0 + else + return 1 + fi + fi +} |
