mirror of
https://github.com/jarun/nnn.git
synced 2024-11-18 17:09:14 +00:00
69d63ff50e
* Fix conflict with #1006 * Queue/play in cmus player * Remove leftover comments * start_cmus function, optional xdotool dependency, better process waiting * start_cmus function, better process waiting, optional xdotool dep * Merge conflicts * Better reporting of past actions * Discriminate newly started queue and existing queue * Harmonize descriptions, rename cmusqueue to cmusq, clean cmusq code * Remove cmusqueue * Exit if cmus missing and style changes Co-authored-by: luukvbaal <31730729+luukvbaal@users.noreply.github.com>
66 lines
2.4 KiB
Bash
Executable file
66 lines
2.4 KiB
Bash
Executable file
#!/usr/bin/env sh
|
|
|
|
# Description: Fuzzy find and execute nnn plugins (and optionally,
|
|
# custom scripts located elsewhere).
|
|
# Description and details of plugins can be previewed
|
|
# from the fzf interface. Use `?` to toggle preview
|
|
# pane on and off, ^Up/^Dn to scroll.
|
|
#
|
|
# Dependencies: find, fzf, cat (or bat, if installed)
|
|
#
|
|
# Note: For better compatibility with as many nnn plugins as possible,
|
|
# fzplug will first execute the chosen script on the file hovered
|
|
# in nnn, and upon failure, try to run it with no target (i.e on
|
|
# an active selection, if present).
|
|
#
|
|
# Shell: POSIX compliant
|
|
# Author: Kabouik
|
|
|
|
# Optional scripts sources
|
|
|
|
# Leave blank or fill with the absolute path of a folder containing executable
|
|
# scripts other than nnn plugins (e.g., "$HOME/.local/share/nautilus/scripts",
|
|
# since there are numerous Nautilus script git repositories).
|
|
# Add extra variables if needed, make sure you call them in the find command.
|
|
|
|
#CUSTOMDIR1="$HOME/.local/share/nautilus/scripts"
|
|
CUSTOMDIR1=""
|
|
CUSTOMDIR2=""
|
|
|
|
nnnpluginsdir="$HOME/.config/nnn/plugins"
|
|
|
|
# Preview with bat if installed
|
|
if type bat >/dev/null; then
|
|
plugin=$(find "$nnnpluginsdir" "$CUSTOMDIR1" "$CUSTOMDIR2" \
|
|
-maxdepth 3 -perm -111 -type f 2>/dev/null | fzf --ansi --preview \
|
|
"cat {}" \
|
|
--preview-window right:66%:wrap --delimiter / --with-nth -1 \
|
|
--bind="?:toggle-preview")
|
|
else
|
|
plugin=$(find "$nnnpluginsdir" "$CUSTOMDIR1" "$CUSTOMDIR2" \
|
|
-maxdepth 3 -perm -111 -type f 2>/dev/null | fzf --ansi --preview \
|
|
"bat --terminal-width='$(tput cols)' --decorations=always --color=always \
|
|
--style='${BAT_STYLE:-header,numbers}' {}" \
|
|
--preview-window right:66% --delimiter / --with-nth -1 \
|
|
--bind="?:toggle-preview")
|
|
fi
|
|
|
|
# Try running the script on the hovered file, and abort
|
|
# abort if no plugin was selected (ESC or ^C pressed).
|
|
err=0
|
|
if ! [ "$plugin" = "" ]; then
|
|
"$plugin" "$1" || err=1
|
|
fi
|
|
|
|
# If attempt with hovered file fails, try without any target
|
|
# (nnn selections should still be passed to the script in that case)
|
|
if [ "$err" -eq "1" ]; then
|
|
clear && "$plugin" || err=2
|
|
fi
|
|
|
|
# Abort and show error if both fail
|
|
if [ "$err" -eq "2" ]; then
|
|
sep="\n---\n"
|
|
printf "$sep""Failed to execute '%s'. See error above or try without fzfplug. Press return to continue. " "$plugin" && read -r _ && clear
|
|
fi
|