From eec0e6d18ef03ec85772606521f2f141b0d4a1a3 Mon Sep 17 00:00:00 2001 From: Arun Prakash Jana Date: Mon, 27 Apr 2020 00:05:11 +0530 Subject: [PATCH] Various plugin improvements --- plugins/boom | 6 +++--- plugins/fzopen | 8 ++++++-- plugins/mocplay | 14 ++++---------- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/plugins/boom b/plugins/boom index 14f481da..aa776347 100755 --- a/plugins/boom +++ b/plugins/boom @@ -10,7 +10,7 @@ GUIPLAYER="${GUIPLAYER}" NUMTRACKS="${NUMTRACKS:-100}" if [ ! -z "$GUIPLAYER" ]; then - find . -type f \( -iname "*.mp3" -o -iname "*.flac" -o -iname "*.m4a" -o -iname "*.webm" -o -iname "*.wma" \) | shuf | head -n "$NUMTRACKS" | xargs -d "\n" "$GUIPLAYER" > /dev/null 2>&1 & + find . -type f \( -iname "*.mp3" -o -iname "*.flac" -o -iname "*.m4a" -o -iname "*.webm" -o -iname "*.wma" \) | shuf -n "$NUMTRACKS" | xargs -d "\n" "$GUIPLAYER" > /dev/null 2>&1 & # detach the player sleep 1 @@ -26,7 +26,7 @@ elif which mocp >/dev/null 2>&1; then state=$(mocp -i | grep "State:" | cut -d' ' -f2) if [ "$state" = 'PLAY' ]; then # add up to 100 random audio files - find . -type f \( -iname "*.mp3" -o -iname "*.flac" -o -iname "*.m4a" -o -iname "*.webm" -o -iname "*.wma" \) | shuf | head -n "$NUMTRACKS" | xargs -d "\n" mocp -a + find . -type f \( -iname "*.mp3" -o -iname "*.flac" -o -iname "*.m4a" -o -iname "*.webm" -o -iname "*.wma" \) | shuf -n "$NUMTRACKS" | xargs -d "\n" mocp -a exit fi fi @@ -35,7 +35,7 @@ elif which mocp >/dev/null 2>&1; then mocp -c # add up to 100 random audio files - find . -type f \( -iname "*.mp3" -o -iname "*.flac" -o -iname "*.m4a" -o -iname "*.webm" -o -iname "*.wma" \) | shuf | head -n "$NUMTRACKS" | xargs -d "\n" mocp -a + find . -type f \( -iname "*.mp3" -o -iname "*.flac" -o -iname "*.m4a" -o -iname "*.webm" -o -iname "*.wma" \) | shuf -n "$NUMTRACKS" | xargs -d "\n" mocp -a # start playing mocp -p diff --git a/plugins/fzopen b/plugins/fzopen index 9f5ff052..e262d684 100755 --- a/plugins/fzopen +++ b/plugins/fzopen @@ -4,14 +4,18 @@ # Opens in $VISUAL or $EDITOR if text # Opens other type of files with xdg-open # -# Requires: fzf/fzy, xdg-open +# Requires: fd/find, fzf/fzy/skim, xdg-open # # Shell: POSIX compliant # Author: Arun Prakash Jana if which fzf >/dev/null 2>&1; then cmd="$FZF_DEFAULT_COMMAND" - [ -z "$cmd" ] && cmd="find . -type f 2>/dev/null" + if which fd >/dev/null 2>&1; then + [ -z "$cmd" ] && cmd="fd -t f 2>/dev/null" + else + [ -z "$cmd" ] && cmd="find . -type f 2>/dev/null" + fi entry="$(eval "$cmd" | fzf --delimiter / --nth=-1 --tiebreak=begin --info=hidden)" # To show only the file name # entry=$(find . -type f 2>/dev/null | fzf --delimiter / --with-nth=-1 --tiebreak=begin --info=hidden) diff --git a/plugins/mocplay b/plugins/mocplay index 5db44b94..36e7e500 100755 --- a/plugins/mocplay +++ b/plugins/mocplay @@ -7,6 +7,7 @@ # - appends tracks and exits is MOC is running, else clears playlist and adds tracks # - to randomize the order of files appended to the playlist, set SHUFFLE=1 # if you add a directory with many files when SHUFFLE=1 is set, it might take a very long time to finish! +# - max 100 files are added # # Shell: POSIX compliant # Author: Arun Prakash Jana, ath3 @@ -30,20 +31,13 @@ mocp_add () for entry in $arr do if [ -d "$entry" ]; then - arr2=$arr2$(find "$entry" -type f) - else + arr2=$arr2$(find "$entry" -type f \( ! -iname "*.m3u" ! -iname "*.pls" \)) + elif echo "$entry" | grep -qv '\.m3u$\|\.pls$' ; then arr2=$(printf "%s\n%s" "$entry" "$arr2") fi done - arr2=$(echo "$arr2" | awk 'BEGIN{srand();}{print rand()"\t"$0}' | sort -k1 -n | cut -f2-) - for entry in $arr2 - do - if [ -f "$entry" ] && echo "$entry" | grep -qv '\.m3u$\|\.pls$' ; then - mocp -a "$entry" - fi - done - + echo "$arr2" | shuf -n 100 | xargs -d "\n" mocp -a else if [ "$resp" = "y" ]; then xargs < "$selection" -0 mocp -a