diff options
| author | --global <ik.boikov.public@protonmail.com> | 2021-05-31 10:08:15 +0200 |
|---|---|---|
| committer | --global <ik.boikov.public@protonmail.com> | 2021-05-31 10:08:15 +0200 |
| commit | 72000d2f0c23a685f4c4d458158712340f6b9a68 (patch) | |
| tree | 5698acadb5240ed9313f9af2dfe2cc5d731baad4 /nnn | |
| parent | 1079eb062f2f48eb4bcd11528cf811ba5a4cf9e9 (diff) | |
nnn goodies, wal call fix
Diffstat (limited to 'nnn')
| -rwxr-xr-x | nnn/.config/nnn/plugins/.nnn-plugin-helper | 38 | ||||
| -rwxr-xr-x | nnn/.config/nnn/plugins/dragdrop | 74 | ||||
| -rwxr-xr-x[-rw-r--r--] | nnn/.config/nnn/plugins/mimelist | 0 |
3 files changed, 112 insertions, 0 deletions
diff --git a/nnn/.config/nnn/plugins/.nnn-plugin-helper b/nnn/.config/nnn/plugins/.nnn-plugin-helper new file mode 100755 index 0000000..a0377ac --- /dev/null +++ b/nnn/.config/nnn/plugins/.nnn-plugin-helper @@ -0,0 +1,38 @@ +#!/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 + +## 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 $? +} diff --git a/nnn/.config/nnn/plugins/dragdrop b/nnn/.config/nnn/plugins/dragdrop new file mode 100755 index 0000000..8623f24 --- /dev/null +++ b/nnn/.config/nnn/plugins/dragdrop @@ -0,0 +1,74 @@ +#!/usr/bin/env sh + +# Description: Open a Drag and drop window, to drop files onto other programs. +# Also provides drag and drop window for files. +# +# Dependencies: dragon - https://github.com/mwh/dragon +# +# Notes: +# 1. Files that are dropped will be added to nnn's selection +# Some web-based files will be downloaded to current dir +# with curl and it may overwrite some existing files +# 2. The user has to mm to clear nnn's selection first +# +# Shell: POSIX compliant +# Author: 0xACE + +selection=${NNN_SEL:-${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection} +resp=f +all= +if type dragon-drag-and-drop >/dev/null 2>&1; then + dnd="dragon-drag-and-drop" +else + dnd="dragon" +fi + +add_file () +{ + printf '%s\0' "$@" >> "$selection" +} + +use_all () +{ + printf "mark --all (a) [default=none]: " + read -r resp + if [ "$resp" = "a" ]; then + all="--all" + else + all="" + fi +} + +if [ -s "$selection" ]; then + printf "Drop file (r). Drag selection (s), Drag current directory (d) or drag current file (f) [default=f]: " + read -r resp +else + printf "Drop file (r). Drag current directory (d) or drag current file (f) [default=f]: " + read -r resp + if [ "$resp" = "s" ]; then + resp=f + fi +fi + +if [ "$resp" = "s" ]; then + use_all + sed -z 's|'"$PWD/"'||g' < "$selection" | xargs -0 "$dnd" "$all" & +elif [ "$resp" = "d" ]; then + use_all + "$dnd" "$all" "$PWD/"* & +elif [ "$resp" = "r" ]; then + true > "$selection" + "$dnd" --print-path --target | while read -r f + do + if printf "%s" "$f" | grep '^\(https\?\|ftps\?\|s\?ftp\):\/\/' ; then + curl -LJO "$f" + add_file "$PWD/$(basename "$f")" + elif [ -e "$f" ]; then + add_file "$f" + fi + done & +else + if [ -n "$1" ] && [ -e "$1" ]; then + "$dnd" "$1" & + fi +fi diff --git a/nnn/.config/nnn/plugins/mimelist b/nnn/.config/nnn/plugins/mimelist index d601cd8..d601cd8 100644..100755 --- a/nnn/.config/nnn/plugins/mimelist +++ b/nnn/.config/nnn/plugins/mimelist |
