README.md | 2 +- nnn.1 | 2 ++ plugins/.cbcp | 16 ++++++++-------- plugins/.nmv | 2 +- plugins/.nnn-plugin-helper | 2 +- plugins/chksum | 2 +- plugins/diffs | 2 +- plugins/dragdrop | 2 +- plugins/kdeconnect | 8 ++++---- plugins/mocplay | 2 +- plugins/renamer | 2 +- plugins/splitjoin | 2 +- plugins/x2sel | 4 ++-- src/nnn.c | 23 ++++++++++++++++------- diff --git a/README.md b/README.md index c1fe19567db26eeeafd28558afb752185423f615..696f74a453bb1e83fb2e3ce152897550b61b92c3 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ Travis Status CircleCI Status Privacy Awareness License -Donate via PayPal! +Donate via PayPal!

diff --git a/nnn.1 b/nnn.1 index 350f48fd26990640e8c94570321b1b7f566211ee..5048bb07a6ea5cb16c1094f96957c6f9939b447a 100644 --- a/nnn.1 +++ b/nnn.1 @@ -421,6 +421,8 @@ NOTE: Only the first character is considered if not a \fICtrl+key\fR combo. .Ed .Pp +\fBNNN_SEL:\fR absolute path to custom selection file. +.Pp \fBnnn:\fR this is a special variable set to the hovered entry before executing a command from the command prompt or spawning a shell. .Pp diff --git a/plugins/.cbcp b/plugins/.cbcp index 022e88a362bb573b9abd9e3d87012e766e95e34a..8830e90ed6c306931b6b6a247ba2b2a26a79eb6b 100755 --- a/plugins/.cbcp +++ b/plugins/.cbcp @@ -19,27 +19,27 @@ # Author: Arun Prakash Jana IFS="$(printf '%b_' '\n')"; IFS="${IFS%_}" # protect trailing \n -SELECTION=${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection +selection=${NNN_SEL:-${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection} if which xsel >/dev/null 2>&1; then # Linux - tr '\0' '\n' < "$SELECTION" | xsel -bi + tr '\0' '\n' < "$selection" | xsel -bi elif which xclip >/dev/null 2>&1; then # Linux - tr '\0' '\n' < "$SELECTION" | xclip -sel clip + tr '\0' '\n' < "$selection" | xclip -sel clip elif which pbcopy >/dev/null 2>&1; then # macOS - tr '\0' '\n' < "$SELECTION" | pbcopy + tr '\0' '\n' < "$selection" | pbcopy elif which termux-clipboard-set >/dev/null 2>&1; then # Termux - tr '\0' '\n' < "$SELECTION" | termux-clipboard-set + tr '\0' '\n' < "$selection" | termux-clipboard-set elif which clip.exe >/dev/null 2>&1; then # WSL - tr '\0' '\n' < "$SELECTION" | clip.exe + tr '\0' '\n' < "$selection" | clip.exe elif which clip >/dev/null 2>&1; then # Cygwin - tr '\0' '\n' < "$SELECTION" | clip + tr '\0' '\n' < "$selection" | clip elif which wl-copy >/dev/null 2>&1; then # Wayland - tr '\0' '\n' < "$SELECTION" | wl-copy + tr '\0' '\n' < "$selection" | wl-copy fi diff --git a/plugins/.nmv b/plugins/.nmv index 023328df4206952f33eb8069b7b22a4b365cf44c..77625466996568126ab9bc3c7d80de9c943c0fb2 100755 --- a/plugins/.nmv +++ b/plugins/.nmv @@ -21,7 +21,7 @@ TMPDIR="${TMPDIR:-/tmp}" INCLUDE_HIDDEN="${INCLUDE_HIDDEN:-0}" VERBOSE="${VERBOSE:-0}" -selection=${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection +selection=${NNN_SEL:-${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection} exit_status=0 dst_file=$(mktemp "$TMPDIR/.nnnXXXXXX") diff --git a/plugins/.nnn-plugin-helper b/plugins/.nnn-plugin-helper index a42ee69763d21fff0192d31118ef0c8240ea087f..06b3bcbe9fc1a3313fe32f412635d3787e7c821a 100644 --- a/plugins/.nnn-plugin-helper +++ b/plugins/.nnn-plugin-helper @@ -5,7 +5,7 @@ # # Shell: POSIX compliant # Author: Anna Arad -selection=${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection +selection=${NNN_SEL:-${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection} export selection ## Set CUR_CTX to 1 to open directory in current context diff --git a/plugins/chksum b/plugins/chksum index 0c13da2e7ed9f75692e4d0838671c1e0249e90e2..1514de7222b8b9d9387acfe40f9b62ec54ac9ea8 100755 --- a/plugins/chksum +++ b/plugins/chksum @@ -14,7 +14,7 @@ # # Shell: POSIX compliant # Author: ath3, Arun Prakash Jana -selection=${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection +selection=${NNN_SEL:-${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection} resp=f chsum=md5 diff --git a/plugins/diffs b/plugins/diffs index ff85aa8f3d3a493461f2b62d81b09769b53b1605..294c5e77a6a2e2b9df85392e42d20befb889287d 100755 --- a/plugins/diffs +++ b/plugins/diffs @@ -10,7 +10,7 @@ # # Shell: POSIX compliant # Authors: Arun Prakash Jana, ath3 -selection=${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection +selection=${NNN_SEL:-${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection} if which nvim >/dev/null 2>&1; then diffcmd="nvim -d" diff --git a/plugins/dragdrop b/plugins/dragdrop index bbbd19e7818886290b02597ad0865c93dd46974d..bc01d870ac0261d8fa1bc5bdc1859a0e2c7c7a55 100755 --- a/plugins/dragdrop +++ b/plugins/dragdrop @@ -13,7 +13,7 @@ # Dependency: https://github.com/mwh/dragon # Shell: POSIX compliant # Author: 0xACE -selection=${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection +selection=${NNN_SEL:-${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection} resp=f all= if which dragon-drag-and-drop >/dev/null 2>&1; then diff --git a/plugins/kdeconnect b/plugins/kdeconnect index 9ee2e600b8d8321f5311058a9527157f7aa20c3c..f1cfd95b1a640f6c7cf513b3cac4cbdca641e236 100755 --- a/plugins/kdeconnect +++ b/plugins/kdeconnect @@ -5,13 +5,13 @@ # # Shell: POSIX compliant # Author: juacq97 -SELECTION=${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection +selection=${NNN_SEL:-${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection} id=$(kdeconnect-cli -a --id-only | awk '{print $1}') -if [ "$(find "$SELECTION")" ]; then - kdeconnect-cli -d "$id" --share "$(cat "$SELECTION")" +if [ "$(find "$selection")" ]; then + kdeconnect-cli -d "$id" --share "$(cat "$selection")" # If you want a system notification, uncomment the next 3 lines. -# notify-send -a "Kdeconnect" "Sending $(cat "$SELECTION")" +# notify-send -a "Kdeconnect" "Sending $(cat "$selection")" #else # notify-send -a "Kdeconnect" "No file selected" fi diff --git a/plugins/mocplay b/plugins/mocplay index 6f5a2a080bddbdde8fee158816e97934d27bcd0d..5db44b94c5f4432e4f739112f279552413134fbd 100755 --- a/plugins/mocplay +++ b/plugins/mocplay @@ -12,7 +12,7 @@ # Shell: POSIX compliant # Author: Arun Prakash Jana, ath3 IFS="$(printf '\n\r')" -selection=${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection +selection=${NNN_SEL:-${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection} cmd=$(pgrep -x mocp 2>/dev/null) ret=$cmd diff --git a/plugins/renamer b/plugins/renamer index 8ea2d928c9c7aadd9e28a6da848cb5330fe963ba..4c157648a517b62927fb85cbc2b0af56f4365890 100755 --- a/plugins/renamer +++ b/plugins/renamer @@ -12,7 +12,7 @@ # # Shell: POSIX compliant # Author: José Neder -selection=${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection +selection=${NNN_SEL:-${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection} if command -v qmv >/dev/null 2>&1; then batchrenamesel="qmv -fdo -da" diff --git a/plugins/splitjoin b/plugins/splitjoin index fcd49de3b575298acf67d24005d0f5c28943f291..545eadb4ce514a13badce7af96ba611677f9eb31 100755 --- a/plugins/splitjoin +++ b/plugins/splitjoin @@ -8,7 +8,7 @@ # # Shell: POSIX compliant # Authors: Arun Prakash Jana, ath3 -selection=${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection +selection=${NNN_SEL:-${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection} resp=s if [ -s "$selection" ]; then diff --git a/plugins/x2sel b/plugins/x2sel index 31137730c7cabac7dc09e1fd25754c62afe4ea4f..79856eb1453ac5d7f9aec2aebcf72fd638636617 100755 --- a/plugins/x2sel +++ b/plugins/x2sel @@ -16,7 +16,7 @@ # Author: Léo Villeveygoux, after Arun Prakash Jana's .cbcp IFS="$(printf '%b_' '\n')"; IFS="${IFS%_}" # protect trailing \n -SELECTION=${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection +selection=${NNN_SEL:-${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection} getclip () { @@ -54,4 +54,4 @@ exit 1; fi done -printf "%s" "$CLIPBOARD" | tr '\n' '\0' > "$SELECTION" +printf "%s" "$CLIPBOARD" | tr '\n' '\0' > "$selection" diff --git a/src/nnn.c b/src/nnn.c index 86b09d45743bdc477693a8e3177f5875e552aeb7..ef1b50ac8760f395e626623905c75951539fa8a7 100644 --- a/src/nnn.c +++ b/src/nnn.c @@ -579,8 +579,9 @@ #define NNN_COLORS 4 #define NNNLVL 5 #define NNN_PIPE 6 #define NNN_MCLICK 7 -#define NNN_ARCHIVE 8 /* strings end here */ -#define NNN_TRASH 9 /* flags begin here */ +#define NNN_SEL 8 +#define NNN_ARCHIVE 9 /* strings end here */ +#define NNN_TRASH 10 /* flags begin here */ static const char * const env_cfg[] = { "NNN_OPTS", @@ -591,6 +592,7 @@ "NNN_COLORS", "NNNLVL", "NNN_PIPE", "NNN_MCLICK", + "NNN_SEL", "NNN_ARCHIVE", "NNN_TRASH", }; @@ -6612,16 +6614,23 @@ } /* Set selection file path */ if (!cfg.picker) { - /* Length of "/.config/nnn/.selection" */ - selpath = (char *)malloc(len + 3); + char *env_sel = xgetenv(env_cfg[NNN_SEL], NULL); + if (env_sel) + selpath = xstrdup(env_sel); + else + /* Length of "/.config/nnn/.selection" */ + selpath = (char *)malloc(len + 3); + if (!selpath) { xerror(); return FALSE; } - r = xstrsncpy(selpath, cfgdir, len + 3); - xstrsncpy(selpath + r - 1, "/.selection", 12); - DPRINTF_S(selpath); + if (!env_sel) { + r = xstrsncpy(selpath, cfgdir, len + 3); + xstrsncpy(selpath + r - 1, "/.selection", 12); + DPRINTF_S(selpath); + } } return TRUE;