mirror of
https://github.com/jarun/nnn.git
synced 2025-01-15 21:36:42 +00:00
plugin-helper: add nnn_use_selection()
This commit is contained in:
parent
9cc4b66868
commit
4867fa2bc7
20
plugins/.nmv
20
plugins/.nmv
|
@ -17,10 +17,12 @@
|
||||||
# Shell: bash
|
# Shell: bash
|
||||||
# Author: KlzXS
|
# Author: KlzXS
|
||||||
|
|
||||||
|
# shellcheck disable=SC1090,SC1091
|
||||||
|
. "$(dirname "$0")"/.nnn-plugin-helper
|
||||||
|
|
||||||
EDITOR="${EDITOR:-vi}"
|
EDITOR="${EDITOR:-vi}"
|
||||||
TMPDIR="${TMPDIR:-/tmp}"
|
TMPDIR="${TMPDIR:-/tmp}"
|
||||||
NNN_INCLUDE_HIDDEN="${NNN_INCLUDE_HIDDEN:-0}"
|
NNN_INCLUDE_HIDDEN="${NNN_INCLUDE_HIDDEN:-0}"
|
||||||
NNN_PREFER_SELECTION="${NNN_PREFER_SELECTION:-0}"
|
|
||||||
VERBOSE="${VERBOSE:-0}"
|
VERBOSE="${VERBOSE:-0}"
|
||||||
RECURSIVE="${RECURSIVE:-0}"
|
RECURSIVE="${RECURSIVE:-0}"
|
||||||
|
|
||||||
|
@ -33,25 +35,11 @@ case "$NNN_TRASH" in
|
||||||
RM_UTIL="rm -ri" ;;
|
RM_UTIL="rm -ri" ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
selection=${NNN_SEL:-${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection}
|
|
||||||
exit_status=0
|
exit_status=0
|
||||||
|
|
||||||
dst_file=$(mktemp "$TMPDIR/.nnnXXXXXX")
|
dst_file=$(mktemp "$TMPDIR/.nnnXXXXXX")
|
||||||
|
|
||||||
if [ -s "$selection" ]; then
|
if nnn_use_selection "Rename"; then
|
||||||
if [ "$NNN_PREFER_SELECTION" -eq 1 ]; then
|
|
||||||
resp="s"
|
|
||||||
else
|
|
||||||
printf "Rename 'c'urrent / 's'election? "
|
|
||||||
read -r resp
|
|
||||||
|
|
||||||
if ! [ "$resp" = "c" ] && ! [ "$resp" = "s" ]; then
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "$resp" = "s" ]; then
|
|
||||||
arr=$(tr '\0' '\n' < "$selection")
|
arr=$(tr '\0' '\n' < "$selection")
|
||||||
else
|
else
|
||||||
findcmd="find . ! -name ."
|
findcmd="find . ! -name ."
|
||||||
|
|
|
@ -12,6 +12,9 @@ export selection
|
||||||
CUR_CTX=0
|
CUR_CTX=0
|
||||||
export CUR_CTX
|
export CUR_CTX
|
||||||
|
|
||||||
|
NNN_PREFER_SELECTION="${NNN_PREFER_SELECTION:-0}"
|
||||||
|
export NNN_PREFER_SELECTION
|
||||||
|
|
||||||
## Ask nnn to switch to directory $1 in context $2.
|
## Ask nnn to switch to directory $1 in context $2.
|
||||||
## If $2 is not provided, the function asks explicitly.
|
## If $2 is not provided, the function asks explicitly.
|
||||||
nnn_cd () {
|
nnn_cd () {
|
||||||
|
@ -36,3 +39,23 @@ cmd_exists () {
|
||||||
type "$1" > /dev/null 2>&1
|
type "$1" > /dev/null 2>&1
|
||||||
echo $?
|
echo $?
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nnn_use_selection() {
|
||||||
|
if ! [ -s "$selection" ]; then
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$NNN_PREFER_SELECTION" -eq 1 ]; then
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
[ -n "$1" ] && printf "$1 "
|
||||||
|
printf "(s)election/(c)urrent? [default=c] "
|
||||||
|
read -r resp__
|
||||||
|
|
||||||
|
if [ "$resp__" = "s" ]; then
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
18
plugins/gpge
18
plugins/gpge
|
@ -10,7 +10,8 @@
|
||||||
# Shell: POSIX compliant
|
# Shell: POSIX compliant
|
||||||
# Author: KlzXS
|
# Author: KlzXS
|
||||||
|
|
||||||
selection=${NNN_SEL:-${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection}
|
# shellcheck disable=SC1090,SC1091
|
||||||
|
. "$(dirname "$0")"/.nnn-plugin-helper
|
||||||
|
|
||||||
printf "(s)ymmetric, (a)symmetric? [default=a] "
|
printf "(s)ymmetric, (a)symmetric? [default=a] "
|
||||||
read -r symmetry
|
read -r symmetry
|
||||||
|
@ -18,12 +19,11 @@ read -r symmetry
|
||||||
if [ "$symmetry" = "s" ]; then
|
if [ "$symmetry" = "s" ]; then
|
||||||
gpg --symmetric "$1"
|
gpg --symmetric "$1"
|
||||||
else
|
else
|
||||||
printf "(s)election/(c)urrent? [default=c] "
|
if nnn_use_selection; then
|
||||||
read -r resp
|
clear_sel=1
|
||||||
|
|
||||||
if [ "$resp" = "s" ]; then
|
|
||||||
files=$(tr '\0' '\n' < "$selection")
|
files=$(tr '\0' '\n' < "$selection")
|
||||||
else
|
else
|
||||||
|
clear_sel=0
|
||||||
files=$1
|
files=$1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -37,8 +37,8 @@ else
|
||||||
|
|
||||||
printf "%s" "$files" | xargs -n1 gpg --encrypt --recipient "$recipient"
|
printf "%s" "$files" | xargs -n1 gpg --encrypt --recipient "$recipient"
|
||||||
|
|
||||||
# Clear selection
|
# Clear selection
|
||||||
if [ "$resp" = "s" ] && [ -p "$NNN_PIPE" ]; then
|
if [ "$clear_sel" -eq 1 ] && [ -p "$NNN_PIPE" ]; then
|
||||||
printf "-" > "$NNN_PIPE"
|
printf "-" > "$NNN_PIPE"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in a new issue