3 # Description: Regular mode:
4 # Fuzzy find a file in directory subtree.
5 # Opens in $VISUAL or $EDITOR if text.
6 # Opens other type of files with xdg-open.
7 # Work only with a single file selected.
10 # If picker mode output file is passed, it
11 # will be overwritten with any picked files.
12 # Leaves untouched if no file is picked.
13 # Works with single/multiple files selected.
15 # Dependencies: fd/find, fzf/skim, xdg-open/open (on macOS)
17 # Shell: POSIX compliant
18 # Author: Arun Prakash Jana
20 NUKE="${XDG_CONFIG_HOME:-$HOME/.config}/nnn/plugins/nuke"
23 # shellcheck disable=SC1090,SC1091
24 . "$(dirname "$0")"/.nnn-plugin-helper
26 if type fzf >/dev/null 2>&1; then
27 cmd="$FZF_DEFAULT_COMMAND"
28 if type fd >/dev/null 2>&1; then
29 [ -z "$cmd" ] && cmd="fd -t f 2>/dev/null"
31 [ -z "$cmd" ] && cmd="find . -type f 2>/dev/null"
33 entry="$(eval "$cmd" | fzf -m)"
34 # To show only the file name
35 # entry=$(find . -type f 2>/dev/null | fzf --delimiter / --with-nth=-1 --tiebreak=begin --info=hidden)
36 elif type sk >/dev/null 2>&1; then
37 entry=$(find . -type f 2>/dev/null | sk)
42 # Check for picker mode
46 /*) fullpath="$entry" ;;
47 *) fullpath="$PWD/$entry" ;;
49 if [ "-" = "$3" ]; then
50 printf "%s\n" "$fullpath"
52 printf "%s\n" "$fullpath" > "$3"
55 # Tell `nnn` to clear its internal selection
56 printf "%s" "0p" > "$NNN_PIPE"
63 if [ "$USE_NUKE" -ne 0 ]; then
68 # Open the file (works for a single file only)
71 if uname | grep -q "Darwin"; then
79 case "$($cmd_file "$entry")" in
81 "${VISUAL:-$EDITOR}" "$entry" ;;
83 $cmd_open "$entry" >/dev/null 2>&1 ;;