aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Arun Prakash Jana <engineerarun@gmail.com>2020-03-16 06:40:02 +0530
committerGravatar Arun Prakash Jana <engineerarun@gmail.com>2020-03-16 07:13:35 +0530
commitb8a973a91ac406266befcb36599ce8df64d096b9 (patch)
tree256fac02bace6a06cad239d37c19d1d400ee40e6
parenta2c2332fc549b43c91dce97f4c099bfa55762277 (diff)
downloadnnn-b8a973a91ac406266befcb36599ce8df64d096b9.tar.gz
Update plugins to support some env vars
-rwxr-xr-xplugins/boom27
-rwxr-xr-xplugins/gutenread6
-rwxr-xr-xplugins/imgresize10
-rwxr-xr-xplugins/mocplay4
-rwxr-xr-xplugins/nuke12
5 files changed, 35 insertions, 24 deletions
diff --git a/plugins/boom b/plugins/boom
index 460b9dd..14f481d 100755
--- a/plugins/boom
+++ b/plugins/boom
@@ -6,25 +6,36 @@
# Shell: POSIX compliant
# Author: Arun Prakash Jana
-#GUIPLAYER=smplayer
-
-NUMTRACKS=100
+GUIPLAYER="${GUIPLAYER}"
+NUMTRACKS="${NUMTRACKS:-100}"
if [ ! -z "$GUIPLAYER" ]; then
- PLAYER="$GUIPLAYER"
- find . -type f \( -iname "*.mp3" -o -iname "*.flac" -o -iname "*.m4a" -o -iname "*.webm" -o -iname "*.wma" \) | shuf | head -n $NUMTRACKS | xargs -d "\n" "$PLAYER" > /dev/null 2>&1 &
+ 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 &
# detach the player
sleep 1
elif which mocp >/dev/null 2>&1; then
- # start MOC server
- mocp -S
+ cmd=$(pgrep -x mocp 2>/dev/null)
+ ret=$cmd
+
+ if [ -z "$ret" ]; then
+ # start MOC server
+ mocp -S
+ else
+ # mocp running, check if it's playing
+ 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
+ exit
+ fi
+ fi
# clear MOC playlist
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 | head -n "$NUMTRACKS" | xargs -d "\n" mocp -a
# start playing
mocp -p
diff --git a/plugins/gutenread b/plugins/gutenread
index 029cccf..eb845bf 100755
--- a/plugins/gutenread
+++ b/plugins/gutenread
@@ -18,11 +18,11 @@
# Shell: POSIX compliant
# Author: Arun Prakash Jana
-EBOOK_ID=
+EBOOK_ID="${EBOOK_ID}"
DIR="${XDG_CACHE_HOME:-$HOME/.cache}/nnn/gutenbooks/$EBOOK_ID"
BROWSE_LINK="http://www.gutenberg.org/ebooks/search/?sort_order=downloads"
-BROWSER=w3m
-READER=
+BROWSER="${BROWSER:-w3m}"
+READER="${READER}"
if [ -n "$EBOOK_ID" ]; then
if [ ! -e "$DIR" ]; then
diff --git a/plugins/imgresize b/plugins/imgresize
index def5560..d85d4b5 100755
--- a/plugins/imgresize
+++ b/plugins/imgresize
@@ -5,7 +5,7 @@
#
# Notes:
# 1. Set res if you don't want to be prompted for desktop resolution every time
-# 2. minsize is set to 1MB by default, adjust it if you want
+# 2. MINSIZE is set to 1MB by default, adjust it if you want
# 3. imgp options used:
# a - adaptive mode
# c - convert PNG to JPG
@@ -15,16 +15,16 @@
# Author: Arun Prakash Jana
# set resolution (e.g. 1920x1080)
-res=
+res="${RESOLUTION}"
# set minimum image size (in bytes) to resize (default: 1MB)
-minsize=1048576
+MINSIZE="${MINSIZE:-1048576}"
if [ -z "$res" ]; then
printf "desktop resolution (hxv): "
read -r res
fi
-if ! [ -z "$res" ] && ! [ -z "$minsize" ]; then
- imgp -ackx "$res" -s "$minsize"
+if ! [ -z "$res" ] && ! [ -z "$MINSIZE" ]; then
+ imgp -ackx "$res" -s "$MINSIZE"
fi
diff --git a/plugins/mocplay b/plugins/mocplay
index 30818b2..6f5a2a0 100755
--- a/plugins/mocplay
+++ b/plugins/mocplay
@@ -16,11 +16,11 @@ selection=${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection
cmd=$(pgrep -x mocp 2>/dev/null)
ret=$cmd
-SHUFFLE=0
+SHUFFLE="${SHUFFLE:-0}"
mocp_add ()
{
- if [ $SHUFFLE = 1 ]; then
+ if [ "$SHUFFLE" = 1 ]; then
if [ "$resp" = "y" ]; then
arr=$(tr '\0' '\n' < "$selection")
elif [ -n "$1" ]; then
diff --git a/plugins/nuke b/plugins/nuke
index 81a6d4d..50840fe 100755
--- a/plugins/nuke
+++ b/plugins/nuke
@@ -66,7 +66,7 @@
# #############################################################################
# set to 1 to enable GUI apps
-GUI=0
+GUI="${GUI:-0}"
set -euf -o noclobber -o noglob -o nounset
IFS="$(printf '%b_' '\n')"; IFS="${IFS%_}" # protect trailing \n
@@ -82,7 +82,7 @@ if ! [ -z "$ext" ]; then
fi
handle_pdf() {
- if [ $GUI -ne 0 ] && which zathura >/dev/null 2>&1; then
+ if [ "$GUI" -ne 0 ] && which zathura >/dev/null 2>&1; then
zathura "${FPATH}" >/dev/null 2>&1 &
exit 0
elif which pdftotext >/dev/null 2>&1; then
@@ -115,10 +115,10 @@ handle_audio() {
}
handle_video() {
- if [ $GUI -ne 0 ] && which smplayer >/dev/null 2>&1; then
+ if [ "$GUI" -ne 0 ] && which smplayer >/dev/null 2>&1; then
smplayer "${FPATH}" >/dev/null 2>&1 &
exit 0
- elif [ $GUI -ne 0 ] && which mpv >/dev/null 2>&1; then
+ elif [ "$GUI" -ne 0 ] && which mpv >/dev/null 2>&1; then
mpv "${FPATH}" >/dev/null 2>&1 &
exit 0
elif which ffmpegthumbnailer >/dev/null 2>&1; then
@@ -285,7 +285,7 @@ handle_multimedia() {
## Image
image/*)
- if [ $GUI -ne 0 ] && which sxiv >/dev/null 2>&1; then
+ if [ "$GUI" -ne 0 ] && which sxiv >/dev/null 2>&1; then
sxiv_load_dir "${FPATH}" >/dev/null 2>&1 &
exit 0
elif which viu >/dev/null 2>&1; then
@@ -450,7 +450,7 @@ handle_mime() {
}
handle_fallback() {
- if [ $GUI -ne 0 ]; then
+ if [ "$GUI" -ne 0 ]; then
xdg-open "${FPATH}" >/dev/null 2>&1 &
exit 0
fi