diff --git a/plugins/README.md b/plugins/README.md index 7e725427..f217495c 100644 --- a/plugins/README.md +++ b/plugins/README.md @@ -20,6 +20,7 @@ Plugins extend the capabilities of `nnn`. They are _executable_ scripts (or bina | [cdpath](cdpath) | `cd` to the directory from `CDPATH` | sh | fzf | | [chksum](chksum) | Create and verify checksums [✓] | sh | md5sum,
sha256sum | | [cleanfilename](cleanfilename) | Clean filename to be more shell-friendly [✓] | bash | sed | +| [cmusq](cmusq) | Queue files/dirs in cmus player | sh | cmus, pgrep | | [diffs](diffs) | Diff for selection (limited to 2 for directories) [✓] | sh | vimdiff, mktemp | | [dragdrop](dragdrop) | Drag/drop files from/into nnn | sh | [dragon](https://github.com/mwh/dragon) | | [dups](dups) | List non-empty duplicate files in current dir | bash | find, md5sum,
sort uniq xargs | diff --git a/plugins/cmusq b/plugins/cmusq new file mode 100755 index 00000000..aa67cb66 --- /dev/null +++ b/plugins/cmusq @@ -0,0 +1,79 @@ +#!/usr/bin/env sh + +# Description: Add selection or hovered file/directory to cmus queue +# +# Dependencies: cmus, pgrep, xdotool (optional) +# +# Notes: +# 1. If adding selection, files/dirs are added in the same order they were selected in nnn +# 2. A new window will be opened if cmus is not running already, playback will start immediately +# 3. If cmus is already running, files will be appended to the queue with no forced playback +# +# TODO: +# 1. Add cava and cmus-lyrics as optional dependencies +# 2. Start cava and/or cmus-lyrics in tmux or kitty panes next to cmus +# +# Shell: POSIX compliant +# Author: Kabouik + +# (Optional) Set preferred terminal emulator for cmus if not set in your env, +# or leave commented out to use OS default +#TERMINAL="kitty" + +if ! type cmus >/dev/null; then + printf "cmus missing" + read -r _ +fi + +selection=${NNN_SEL:-${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection} + +start_cmus() { + type xdotool >/dev/null && nnnwindow="$(xdotool getactivewindow)" + case "$TERMINAL" in + kitty | gnome-terminal | st) + nohup "$TERMINAL" -- cmus & ;; + havoc) + nohup "$TERMINAL" cmus & ;; + "") + nohup x-terminal-emulator -e cmus & ;; + *) + nohup "$TERMINAL" -e cmus & ;; + esac + # Give the new terminal some time to open + until pidof cmus >/dev/null; do sleep 0.1; done + [ -n "$nnnwindow" ] && xdotool windowactivate "$nnnwindow" +} >/dev/null 2>&1 + +fill_queue() { + if [ "$REPLY" = "s" ]; then + xargs < "$selection" -0 cmus-remote -q + elif [ -n "$1" ]; then + cmus-remote -q "$1" + fi +} + +# If active selection,then ask what to do +if [ -s "$selection" ]; then + printf "Queue [s]election or [c]urrently hovered? [default=c]: " + read -r REPLY +fi + +# If cmus is not running, start and play queue +if ! pgrep cmus >/dev/null; then + printf "cmus is not running, starting it in a new %s window.\n" "$TERMINAL" + start_cmus + fill_queue "$1" + cmus-remote -p + printf "Files added to cmus queue.\n" +else # Append to existing queue if cmus is already running + fill_queue "$1" + printf "Files appended to current cmus queue.\n" +fi + +# Change view +cmus-remote -C "view 4" + +# Clear selection +if [ -p "$NNN_PIPE" ]; then + printf "-" > "$NNN_PIPE" +fi diff --git a/plugins/fzplug b/plugins/fzplug index c2ad7622..6fcff416 100755 --- a/plugins/fzplug +++ b/plugins/fzplug @@ -17,6 +17,7 @@ # 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). @@ -29,7 +30,7 @@ CUSTOMDIR2="" nnnpluginsdir="$HOME/.config/nnn/plugins" # Preview with bat if installed -if [ -z "$(command -v bat)" ]; then +if type bat >/dev/null; then plugin=$(find "$nnnpluginsdir" "$CUSTOMDIR1" "$CUSTOMDIR2" \ -maxdepth 3 -perm -111 -type f 2>/dev/null | fzf --ansi --preview \ "cat {}" \ @@ -52,7 +53,7 @@ if ! [ "$plugin" = "" ]; then fi # If attempt with hovered file fails, try without any target -# (nnn selections should still be passed to the script int hat case) +# (nnn selections should still be passed to the script in that case) if [ "$err" -eq "1" ]; then clear && "$plugin" || err=2 fi diff --git a/plugins/unmount-parent b/plugins/unmount-parent index 3a89f650..d148fca1 100755 --- a/plugins/unmount-parent +++ b/plugins/unmount-parent @@ -8,12 +8,13 @@ # # Dependencies: fusermount # + # Shell: POSIX compliant # Authors: Kabouik & 0xACE # # TODO: # - Avoid lazy unmount by forcing nnn context to leave the subfolder before fusermount. -# Tried `printf "%s" "0c$m" > "$NNN_PIPE"` but it breaks the nnn interfacee, see #854. +# Tried `printf "%s" "0c$m" > "$NNN_PIPE"` but it breaks the nnn interface, see #854. err=0 m=$HOME/.config/nnn/mounts