]> Sergey Matveev's repositories - nnn.git/commitdiff
Update plugins to support some env vars
authorArun Prakash Jana <engineerarun@gmail.com>
Mon, 16 Mar 2020 01:10:02 +0000 (06:40 +0530)
committerArun Prakash Jana <engineerarun@gmail.com>
Mon, 16 Mar 2020 01:43:35 +0000 (07:13 +0530)
plugins/boom
plugins/gutenread
plugins/imgresize
plugins/mocplay
plugins/nuke

index 460b9dd6a0ce140b109fb2524d25cb90e78978af..14f481da7d543d315229e66b8de96357f39a5a41 100755 (executable)
@@ -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
index 029cccf314cde1a45bbb0c81a4d6fdff34d80b69..eb845bf41f4f8c0c7c43d4248af4139cba3597c8 100755 (executable)
 # 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
index def556019f4db13ad550a63330b1f8f00dbd8893..d85d4b519762ca5fdd4bbd24f825a05d2b8cde22 100755 (executable)
@@ -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
 # 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
index 30818b29688348814875e087fc48bf695b797bbc..6f5a2a080bddbdde8fee158816e97934d27bcd0d 100755 (executable)
@@ -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
index 81a6d4d1dc985586346f161b90f2552ff92403b3..50840fe6e2c7d974b165cbb7d258fc8f424b4267 100755 (executable)
@@ -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