mirror of
https://github.com/jarun/nnn.git
synced 2024-11-05 02:43:12 +00:00
fzdirs: support default list, default to $PWD
This commit is contained in:
parent
462531b8c7
commit
b397606d0a
|
@ -7,6 +7,11 @@
|
||||||
# Details: Paths in list file should be newline-separated absolute paths.
|
# Details: Paths in list file should be newline-separated absolute paths.
|
||||||
# Paths can be file paths; the script will scan the parent dirs.
|
# Paths can be file paths; the script will scan the parent dirs.
|
||||||
#
|
#
|
||||||
|
# The path-list file precedence is:
|
||||||
|
# - "$1" (the hovered file) if it exists and is plaintext
|
||||||
|
# - "$LIST" if set below
|
||||||
|
# - "$2" (the current directory) [mimics plugin fzcd behaviour]
|
||||||
|
#
|
||||||
# The path-list file can be generated easily:
|
# The path-list file can be generated easily:
|
||||||
# - pick the (file)paths in picker mode to path-list file
|
# - pick the (file)paths in picker mode to path-list file
|
||||||
# - OR, edit selection in nnn and save as path-list file
|
# - OR, edit selection in nnn and save as path-list file
|
||||||
|
@ -22,19 +27,24 @@ IFS="$(printf '\n\r')"
|
||||||
. "$(dirname "$0")"/.nnn-plugin-helper
|
. "$(dirname "$0")"/.nnn-plugin-helper
|
||||||
|
|
||||||
CTX=+
|
CTX=+
|
||||||
|
LIST="$LIST"
|
||||||
|
|
||||||
if [ "$(cmd_exists fzf)" -eq "0" ] && [ -s "$1" ]; then
|
if [ -n "$1" ] && [ $(file -b --mime-type "$1") = 'text/plain' ]; then
|
||||||
|
LIST="$1"
|
||||||
|
elif ! [ -s "$LIST" ]; then
|
||||||
|
LIST="$2"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$(cmd_exists fzf)" -eq "0" ]; then
|
||||||
tmpfile=$(mktemp /tmp/abc-script.XXXXXX)
|
tmpfile=$(mktemp /tmp/abc-script.XXXXXX)
|
||||||
|
|
||||||
for entry in $(tr '\0' '\n' < "$1")
|
while IFS= read -r path; do
|
||||||
do
|
if [ -d "$path" ]; then
|
||||||
if [ -d "$entry" ]; then
|
printf "%s\n" "$path" >> "$tmpfile"
|
||||||
printf "%s\n" "$entry" >> "$tmpfile"
|
elif [ -f "$path" ]; then
|
||||||
elif [ -f "$entry" ]; then
|
printf "%s\n" "$(dirname "$path")" >> "$tmpfile"
|
||||||
printf "%s\n" "$(dirname "$entry")" >> "$tmpfile"
|
|
||||||
fi
|
fi
|
||||||
done
|
done < "$LIST"
|
||||||
|
|
||||||
# Clear selection
|
# Clear selection
|
||||||
if [ -p "$NNN_PIPE" ]; then
|
if [ -p "$NNN_PIPE" ]; then
|
||||||
|
@ -53,8 +63,7 @@ if [ -n "$sel" ]; then
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check if selected path returned
|
# Check if the selected path returned by fzf command is absolute
|
||||||
# by fzf command is absolute
|
|
||||||
case $sel in
|
case $sel in
|
||||||
/*) nnn_cd "$sel" "$CTX" ;;
|
/*) nnn_cd "$sel" "$CTX" ;;
|
||||||
*)
|
*)
|
||||||
|
|
Loading…
Reference in a new issue