"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "plugins/fzcd" between
nnn-v4.1.1.tar.gz and nnn-v4.2.tar.gz

About: nnn is a full-featured terminal file manager.

fzcd  (nnn-v4.1.1):fzcd  (nnn-v4.2)
#!/usr/bin/env sh #!/usr/bin/env sh
# Description: Fuzzy search multiple locations read-in from a path-list file # Description: Fuzzy search multiple locations read-in from a path-list file
# (or $PWD) and open the selected file's dir in a smart context. # (or $PWD) and open the selected file's dir in a smart context.
# Dependencies: fzf, fd (only for multi-location search) # Dependencies: fzf, find (only for multi-location search)
# #
# 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: # The path-list file precedence is:
# - "$1" (the hovered file) if it exists, is plain-text and the # - "$1" (the hovered file) if it exists, is plain-text and the
# first line points to an existing file # first line points to an existing file
# - "$LIST" if set below # - "$LIST" if set below
# - "$2" (the current directory) [mimics plugin fzcd behaviour] # - "$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
# #
# The plugin clears nnn selection as the user can be tempted to delete
# duplicate files after finding copies and remove selection by mistake.
#
# Shell: POSIX compliant # Shell: POSIX compliant
# Author: Anna Arad, Arun Prakash Jana # Author: Anna Arad, Arun Prakash Jana, KlzXS
IFS="$(printf '\n\r')" IFS="$(printf '\n\r')"
. "$(dirname "$0")"/.nnn-plugin-helper . "$(dirname "$0")"/.nnn-plugin-helper
CTX=+ CTX=+
LIST="$LIST" LIST="$LIST"
if ! type fzf >/dev/null 2>&1; then if ! type fzf >/dev/null 2>&1; then
printf "fzf missing" printf "fzf missing"
read -r _ read -r _
exit 1 exit 1
fi fi
if [ -n "$1" ] && [ "$(file -b --mime-type "$1")" = 'text/plain' ] && [ -e "$(he ad -1 "$1")" ]; then if [ -n "$1" ] && [ "$(file -b --mime-type "$1")" = 'text/plain' ] && [ -e "$(he ad -1 "$1")" ]; then
LIST="$1" LIST="$1"
elif ! [ -s "$LIST" ]; then elif ! [ -s "$LIST" ]; then
# Clear selection
if [ -p "$NNN_PIPE" ]; then
printf "-" >"$NNN_PIPE"
fi
sel=$(fzf) sel=$(fzf)
# Show only the file and parent dir # Show only the file and parent dir
# sel=$(fzf --delimiter / --with-nth=-2,-1 --tiebreak=begin --info=hidden) # sel=$(fzf --delimiter / --with-nth=-2,-1 --tiebreak=begin --info=hidden)
LIST='' LIST=''
fi fi
if [ -n "$LIST" ]; then if [ -n "$LIST" ]; then
if type fd >/dev/null 2>&1; then if type find >/dev/null 2>&1; then
tmpfile=$(mktemp /tmp/abc-script.XXXXXX) tmpfile=$(mktemp /tmp/abc-script.XXXXXX)
while IFS= read -r path; do while IFS= read -r path; do
if [ -d "$path" ]; then if [ -d "$path" ]; then
printf "%s\n" "$path" >> "$tmpfile" printf "%s\n" "$path" >> "$tmpfile"
elif [ -f "$path" ]; then elif [ -f "$path" ]; then
printf "%s\n" "$(dirname "$path")" >> "$tmpfile" printf "%s\n" "$(dirname "$path")" >> "$tmpfile"
fi fi
done < "$LIST" done < "$LIST"
# Clear selection sel=$(xargs -d '\n' -a "$tmpfile" -I{} find {} -type f -printf "%H//%P\n
if [ -p "$NNN_PIPE" ]; then " | sed '/.*\/\/\(\..*\|.*\/\..*\)/d; s:/\+:/:g' | fzf --delimiter / --tiebreak=
printf "-" >"$NNN_PIPE" begin --info=hidden)
fi # Alternative for 'fd'
# sel=$(xargs -d '\n' -a "$tmpfile" fd . | fzf --delimiter / --tiebreak=
sel=$(xargs -d '\n' -a "$tmpfile" fd -H . | fzf --delimiter / --tiebreak begin --info=hidden)
=begin --info=hidden)
rm "$tmpfile" rm "$tmpfile"
else else
printf "fd missing" printf "find missing"
read -r _ read -r _
exit 1 exit 1
fi fi
fi fi
if [ -n "$sel" ]; then if [ -n "$sel" ]; then
if [ "$sel" = "." ] || { ! [ -d "$sel" ] && ! [ -f "$sel" ]; }; then if [ "$sel" = "." ] || { ! [ -d "$sel" ] && ! [ -f "$sel" ]; }; then
exit 0 exit 0
fi fi
 End of changes. 8 change blocks. 
20 lines changed or deleted 11 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)