mirror of
https://github.com/jarun/nnn.git
synced 2025-01-15 21:36:42 +00:00
opener improvements
- show file name - open hovered if none selected - open and exit if only one file selected - code improvements
This commit is contained in:
parent
5745597fd5
commit
88e9122c79
|
@ -1,42 +1,49 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
# Description: Open selected files in nuke one by one or in oneshot
|
# Description: Open selected files in nuke one by one or in oneshot
|
||||||
# Tip: keep pressing "Enter" to open files one by one
|
|
||||||
#
|
#
|
||||||
# Note: Uses nuke by default, easy to replace with preferred opener
|
# Notes: 1. Opens the hovered file if the selection is empty
|
||||||
# nuke is invoked once for each file in a loop
|
# 2. nuke is the default, set OPENER below for custom
|
||||||
|
# 3. Opener is invoked once for each file in a loop
|
||||||
|
# 4. Keep pressing "Enter" to open files one by one
|
||||||
#
|
#
|
||||||
# Shell: bash
|
# Shell: bash
|
||||||
# Author: Arun Prakash Jana
|
# Author: Arun Prakash Jana
|
||||||
|
|
||||||
sel=${NNN_SEL:-${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection}
|
sel=${NNN_SEL:-${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection}
|
||||||
nuke="${XDG_CONFIG_HOME:-$HOME/.config}/nnn/plugins/nuke"
|
OPENER="${XDG_CONFIG_HOME:-$HOME/.config}/nnn/plugins/nuke"
|
||||||
|
|
||||||
printf "open [A]ll? "
|
|
||||||
read -r all
|
|
||||||
|
|
||||||
if [ -s "$sel" ]; then
|
if [ -s "$sel" ]; then
|
||||||
targets=()
|
targets=()
|
||||||
while IFS= read -r -d '' entry || [ -n "$entry" ]; do
|
while IFS= read -r -d '' entry || [ -n "$entry" ]; do
|
||||||
targets+=( "$entry" )
|
targets+=( "$entry" )
|
||||||
done < "$sel"
|
done < "$sel"
|
||||||
fi
|
|
||||||
|
|
||||||
last=${targets[${#targets[@]}-1]}
|
elements=${#targets[@]}
|
||||||
|
|
||||||
for entry in "${targets[@]}"; do
|
if (( elements == 1 )); then
|
||||||
# replace nuke with your preferred opened below
|
# If there's only one file selected, open without prompts
|
||||||
"$nuke" "$entry"
|
"$OPENER" "${targets[0]}"
|
||||||
if [ "$all" != "A" ] && [ "$entry" != "$last" ]; then
|
else
|
||||||
printf "press Enter to open next\n"
|
printf "open [A]ll? "
|
||||||
read -r -s -n 1 key
|
read -r all
|
||||||
if [[ $key != "" ]]; then
|
|
||||||
break
|
for ((index=0; index <= ${#targets[@]}; index++)); do
|
||||||
fi
|
"$OPENER" "${targets[index]}"
|
||||||
|
if [ "$all" != "A" ] && (( index+1 < elements )); then
|
||||||
|
printf "press Enter to open '%s'\n" "${targets[index+1]}"
|
||||||
|
read -r -s -n 1 key
|
||||||
|
if [[ $key != "" ]]; then
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done
|
||||||
fi
|
fi
|
||||||
done
|
|
||||||
|
|
||||||
# Clear selection
|
# Clear selection
|
||||||
if [ -s "$sel" ] && [ -p "$NNN_PIPE" ]; then
|
if [ -s "$sel" ] && [ -p "$NNN_PIPE" ]; then
|
||||||
printf "-" > "$NNN_PIPE"
|
printf "-" > "$NNN_PIPE"
|
||||||
|
fi
|
||||||
|
elif [ -n "$1" ]; then
|
||||||
|
"$OPENER" "$1"
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in a new issue