mirror of
https://github.com/jarun/nnn.git
synced 2024-11-24 11:51:27 +00:00
Add plugin cmusq (#1010)
* 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>
This commit is contained in:
parent
5e8ef070dc
commit
69d63ff50e
|
@ -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 |
|
| [cdpath](cdpath) | `cd` to the directory from `CDPATH` | sh | fzf |
|
||||||
| [chksum](chksum) | Create and verify checksums [✓] | sh | md5sum,<br>sha256sum |
|
| [chksum](chksum) | Create and verify checksums [✓] | sh | md5sum,<br>sha256sum |
|
||||||
| [cleanfilename](cleanfilename) | Clean filename to be more shell-friendly [✓] | bash | sed |
|
| [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 |
|
| [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) |
|
| [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,<br>sort uniq xargs |
|
| [dups](dups) | List non-empty duplicate files in current dir | bash | find, md5sum,<br>sort uniq xargs |
|
||||||
|
|
79
plugins/cmusq
Executable file
79
plugins/cmusq
Executable file
|
@ -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
|
|
@ -17,6 +17,7 @@
|
||||||
# Author: Kabouik
|
# Author: Kabouik
|
||||||
|
|
||||||
# Optional scripts sources
|
# Optional scripts sources
|
||||||
|
|
||||||
# Leave blank or fill with the absolute path of a folder containing executable
|
# 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",
|
# scripts other than nnn plugins (e.g., "$HOME/.local/share/nautilus/scripts",
|
||||||
# since there are numerous Nautilus script git repositories).
|
# since there are numerous Nautilus script git repositories).
|
||||||
|
@ -29,7 +30,7 @@ CUSTOMDIR2=""
|
||||||
nnnpluginsdir="$HOME/.config/nnn/plugins"
|
nnnpluginsdir="$HOME/.config/nnn/plugins"
|
||||||
|
|
||||||
# Preview with bat if installed
|
# Preview with bat if installed
|
||||||
if [ -z "$(command -v bat)" ]; then
|
if type bat >/dev/null; then
|
||||||
plugin=$(find "$nnnpluginsdir" "$CUSTOMDIR1" "$CUSTOMDIR2" \
|
plugin=$(find "$nnnpluginsdir" "$CUSTOMDIR1" "$CUSTOMDIR2" \
|
||||||
-maxdepth 3 -perm -111 -type f 2>/dev/null | fzf --ansi --preview \
|
-maxdepth 3 -perm -111 -type f 2>/dev/null | fzf --ansi --preview \
|
||||||
"cat {}" \
|
"cat {}" \
|
||||||
|
@ -52,7 +53,7 @@ if ! [ "$plugin" = "" ]; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# If attempt with hovered file fails, try without any target
|
# 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
|
if [ "$err" -eq "1" ]; then
|
||||||
clear && "$plugin" || err=2
|
clear && "$plugin" || err=2
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -8,12 +8,13 @@
|
||||||
#
|
#
|
||||||
# Dependencies: fusermount
|
# Dependencies: fusermount
|
||||||
#
|
#
|
||||||
|
|
||||||
# Shell: POSIX compliant
|
# Shell: POSIX compliant
|
||||||
# Authors: Kabouik & 0xACE
|
# Authors: Kabouik & 0xACE
|
||||||
#
|
#
|
||||||
# TODO:
|
# TODO:
|
||||||
# - Avoid lazy unmount by forcing nnn context to leave the subfolder before fusermount.
|
# - 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
|
err=0
|
||||||
m=$HOME/.config/nnn/mounts
|
m=$HOME/.config/nnn/mounts
|
||||||
|
|
Loading…
Reference in a new issue