aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/.nnn-plugin-helper
diff options
context:
space:
mode:
authorGravatar Anna Arad <4895022+annagrram@users.noreply.github.com>2019-10-23 13:04:12 +0300
committerGravatar Mischievous Meerkat <engineerarun@gmail.com>2019-10-23 15:34:12 +0530
commit9afd7cf3bf8badb7e704fb1e1fbdb8031572c722 (patch)
tree90669833f994bfcff8b8f9edc0b044f2ea2f2e89 /plugins/.nnn-plugin-helper
parent0144f440609b4fb7dcdf9e3325e6d1de3e6085bf (diff)
downloadnnn-9afd7cf3bf8badb7e704fb1e1fbdb8031572c722.tar.gz
Implement plugins control of nnn + plugins (#364)
* Implement plugins control of nnn + plugins * Refactor plugins control code and fix getplugs to recognize hidden files * Fix bug when going to dir on non-current context from plugin * Fix some plugins to work on openbsd and freebsd * Renamings * Switch to -R flag in cp instead of -r; BSDs complain * Change braces of function location * Rewrite plugin creation in README and add new plugins to the table * Update the fzcd script to include fzy or fzf * Change plugin name resolve-link-dir -> lncd * Fixing plugins README table * Remove some cd plugins but add them as examples to plugins README
Diffstat (limited to 'plugins/.nnn-plugin-helper')
-rw-r--r--plugins/.nnn-plugin-helper33
1 files changed, 33 insertions, 0 deletions
diff --git a/plugins/.nnn-plugin-helper b/plugins/.nnn-plugin-helper
new file mode 100644
index 0000000..ec66a29
--- /dev/null
+++ b/plugins/.nnn-plugin-helper
@@ -0,0 +1,33 @@
+#!/usr/bin/env sh
+
+# Description: Helper script for plugins
+#
+# Shell: POSIX compliant
+# Author: Anna Arad
+
+selection=${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.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
+ else
+ echo -n "Choose context 1-4 (blank for current): "
+ read context
+ fi
+
+ echo -n ${context:-0}$dir > $NNN_PIPE
+}
+
+cmd_exists () {
+ which "$1" > /dev/null 2>&1
+ echo $?
+}