]> Sergey Matveev's repositories - nnn.git/commitdiff
shellcheck fixes
authorArun Prakash Jana <engineerarun@gmail.com>
Thu, 21 Nov 2019 20:44:25 +0000 (02:14 +0530)
committerArun Prakash Jana <engineerarun@gmail.com>
Fri, 22 Nov 2019 05:43:34 +0000 (11:13 +0530)
36 files changed:
misc/auto-completion/bash/nnn-completion.bash
misc/quitcd/quitcd.bash
misc/quitcd/quitcd.zsh
misc/test/mktest.sh
plugins/.nnn-plugin-helper
plugins/boom
plugins/checksum
plugins/dragdrop
plugins/dups
plugins/fzcd
plugins/fzhist
plugins/fzopen
plugins/getplugs
plugins/gutenread
plugins/imgresize
plugins/imgur
plugins/ipinfo
plugins/moclyrics
plugins/mocplay
plugins/ndiff
plugins/nmount
plugins/nwal
plugins/oldbigfile
plugins/pastebin
plugins/pdfview
plugins/pskill
plugins/pywal
plugins/readit
plugins/ringtone
plugins/splitjoin
plugins/sxiv
plugins/thumb
plugins/transfer
plugins/uidgid
plugins/upgrade
plugins/vidthumb

index 22180e51a760f06bdf12a1ededad6e48eeb446ae..638df496704b1da9fd21b4f34153494a850dd9a3 100644 (file)
@@ -5,7 +5,8 @@
 #   Arun Prakash Jana <engineerarun@gmail.com>
 #
 
-_nnn () {
+_nnn ()
+{
     COMPREPLY=()
     local IFS=$' \n'
     local cur=$2 prev=$3
@@ -36,7 +37,7 @@ _nnn () {
         COMPREPLY=( $(compgen -f -d -- "$cur") )
     elif [[ $prev == -e ]]; then
         local sessions_dir=${XDG_CONFIG_HOME:-$HOME/.config}/nnn/sessions
-        COMPREPLY=( $(compgen -W "$(ls $sessions_dir)" -- "$cur") )
+        COMPREPLY=( $(compgen -W "$(ls "$sessions_dir")" -- "$cur") )
     elif [[ $cur == -* ]]; then
         COMPREPLY=( $(compgen -W "${opts[*]}" -- "$cur") )
     else
index 70498cbf709f6527550d05ad88700247641220c9..5c94b11f3fc9aadcaf5925f54b7c5983c0f3e82d 100644 (file)
@@ -1,24 +1,24 @@
-n()
+n ()
 {
     # Block nesting of nnn in subshells
-    if [ $(expr $NNNLVL + 0) -ge 1 ]; then
+    if [ "$((NNNLVL + 0))" -ge 1 ]; then
         echo "nnn is already running"
         return
     fi
 
+    # The default behaviour is to cd on quit (nnn checks if NNN_TMPFILE is set)
+    # To cd on quit only on ^G, export NNN_TMPFILE after the call to nnn
+    export NNN_TMPFILE=${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.lastd
+
     # Unmask ^Q (, ^V etc.) (if required, see `stty -a`) to Quit nnn
     # stty start undef
     # stty stop undef
     # stty lwrap undef
 
-    # The default behaviour is to cd on quit (nnn checks if NNN_TMPFILE is set)
-    # To cd on quit only on ^G, export NNN_TMPFILE after the call to nnn
-    export NNN_TMPFILE=${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.lastd
-
     nnn "$@"
 
-    if [ -f $NNN_TMPFILE ]; then
-            . $NNN_TMPFILE
-            rm -f $NNN_TMPFILE > /dev/null
+    if [ -f "$NNN_TMPFILE" ]; then
+            . "$NNN_TMPFILE"
+            rm -f "$NNN_TMPFILE" > /dev/null
     fi
 }
index 57f0fcf331f6b6c1ec8f47134f42eb600c5fe629..5c94b11f3fc9aadcaf5925f54b7c5983c0f3e82d 100644 (file)
@@ -1,7 +1,7 @@
-n()
+n ()
 {
     # Block nesting of nnn in subshells
-    if [ $(expr $NNNLVL + 0) -ge 1 ]; then
+    if [ "$((NNNLVL + 0))" -ge 1 ]; then
         echo "nnn is already running"
         return
     fi
@@ -17,8 +17,8 @@ n()
 
     nnn "$@"
 
-    if [ -f $NNN_TMPFILE ]; then
-            . $NNN_TMPFILE
-            rm $NNN_TMPFILE
+    if [ -f "$NNN_TMPFILE" ]; then
+            . "$NNN_TMPFILE"
+            rm -f "$NNN_TMPFILE" > /dev/null
     fi
 }
index 2d1decf2d211fe8279a3a3223083dbc3b5d1d9f4..aa5a921b2583cfd648561edb9b82e0adf43e95b1 100755 (executable)
@@ -7,7 +7,7 @@ test -e outdir && {
     exit 1
 }
 
-mkdir -p outdir && cd outdir
+mkdir -p outdir && cd outdir || exit 1
 
 echo 'It works!' > normal.txt
 echo 'Με δουλέβει;' > 'κοινό.txt'
index ec66a29df0078ee6893e4976e84d2619779c8201..c26566df00d93497caafa3a7074e780ece65840b 100644 (file)
@@ -6,6 +6,7 @@
 # Author: Anna Arad
 
 selection=${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection
+export selection
 
 ## Ask nnn to switch to directory $1 in context $2.
 ## If $2 is not provided, the function asks explicitly.
@@ -20,11 +21,11 @@ nnn_cd () {
     if [ -n "$2" ]; then
         context=$2
     else
-        echo -n "Choose context 1-4 (blank for current): "
-        read context
+        printf "Choose context 1-4 (blank for current): "
+        read -r context
     fi
 
-    echo -n ${context:-0}$dir > $NNN_PIPE
+    printf "%s" "${context:-0}$dir" > "$NNN_PIPE"
 }
 
 cmd_exists () {
index 47036e0e7e6634d3dfca99562fa61481fc482639..40931b4782b7fdf5b888d3b0b23bce671d407202 100755 (executable)
@@ -15,7 +15,7 @@ if [ ! -z "$GUIPLAYER" ]; then
     find . -type f \( -iname "*.mp3" -o -iname "*.flac" -o -iname "*.webm" -o -iname "*.wma" \) | sort -R | head -n $NUMTRACKS | xargs -d "\n" "$PLAYER" > /dev/null 2>&1 &
 
     # detach the player
-    disown
+    sleep 1
 else
     # start MOC server
     mocp -S
index 2040e68865b6c3da69545179260041cc6b5f9326..0c13da2e7ed9f75692e4d0838671c1e0249e90e2 100755 (executable)
@@ -21,8 +21,8 @@ chsum=md5
 checksum_type()
 {
     echo "possible checksums: md5, sha1, sha224, sha256, sha384, sha512"
-    echo -n "create md5 (m), sha256 (s), sha512 (S) (or type one of the above checksums) [default=m]: "
-    read chsum_resp
+    printf "create md5 (m), sha256 (s), sha512 (S) (or type one of the above checksums) [default=m]: "
+    read -r chsum_resp
     for chks in md5 sha1 sha224 sha256 sha384 sha512
     do
         if [ "$chsum_resp" = "$chks" ]; then
@@ -38,8 +38,8 @@ checksum_type()
 }
 
 if [ -s "$selection" ]; then
-    echo -n "work with selection (s) or current file (f) [default=f]: "
-    read resp
+    printf "work with selection (s) or current file (f) [default=f]: "
+    read -r resp
 fi
 
 if [ "$resp" = "s" ]; then
@@ -49,10 +49,10 @@ elif [ -n "$1" ]; then
     if [ -f "$1" ]; then
         for chks in md5 sha1 sha224 sha256 sha384 sha512
         do
-            if [ "$(echo "$1" | grep \.${chks}$)" ]; then
+            if echo "$1" | grep -q \.${chks}$; then
                 ${chks}sum -c < "$1"
-                read dummy
-                exit
+                read -r _
+                return
             fi
         done
         checksum_type
index 47b325c57c4b1d16bd8c660b1a25857f49a972fd..ee4fc201223e69cb87181d5d740751fef42c5670 100755 (executable)
 selection=${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection
 resp=f
 all=
-if which dragon-drag-and-drop 2>&1 >/dev/null; then
+if which dragon-drag-and-drop >/dev/null 2>&1; then
     dnd="dragon-drag-and-drop"
 else
     dnd="dragon"
 fi
 
-function add_file() {
-       echo -n "$@" >> "$selection"
-       echo -ne "\0" >> "$selection"
+add_file ()
+{
+       printf "%s" "$@" >> "$selection"
+       printf "\0" >> "$selection"
 }
 
-function use_all()
+use_all ()
 {
-    echo -n "mark --all (a) [default=none]: "
-    read resp
+    printf "mark --all (a) [default=none]: "
+    read -r resp
     if [ "$resp" = "a" ]; then
         all="--all"
     else
@@ -39,11 +40,11 @@ function use_all()
 }
 
 if [ -s "$selection" ]; then
-    echo -n "Drop file (r). Drag selection (s), Drag current directory (d) or drag current file (f) [default=f]: "
-    read resp
+    printf "Drop file (r). Drag selection (s), Drag current directory (d) or drag current file (f) [default=f]: "
+    read -r resp
 else
-    echo -n "Drop file (r). Drag current directory (d) or drag current file (f) [default=f]: "
-    read resp
+    printf "Drop file (r). Drag current directory (d) or drag current file (f) [default=f]: "
+    read -r resp
     if [ "$resp" = "s" ]; then
         resp=f
     fi
@@ -56,10 +57,10 @@ elif [ "$resp" = "d" ]; then
     use_all
     "$dnd" "$all" "$PWD/"* &
 elif [ "$resp" = "r" ]; then
-    echo -n > "$selection"
-    "$dnd" --print-path --target | while read f
+    printf > "$selection"
+    "$dnd" --print-path --target | while read -r f
     do
-            if echo -n "$f" | grep '^\(https\?\|ftps\?\|s\?ftp\):\/\/' ; then
+            if printf "%s" "$f" | grep '^\(https\?\|ftps\?\|s\?ftp\):\/\/' ; then
                     curl -LJO "$f"
                     add_file "$PWD/$(basename "$f")"
             elif [ -e "$f" ]; then
index 06430251f697f08bc4337dadf3967dbfb246bd6d..2c5bb5ecefca9a2be3663380aa15d2d817a68aa6 100755 (executable)
@@ -9,7 +9,7 @@
 # Shell: POSIX compliant
 # Author: syssyphus
 
-find -size +0 -type f -printf "%s\n" | sort -rn | uniq -d | xargs -I{} -n1 find -type f -size {}c -print0 | xargs -0 md5sum | sort | uniq -w32 --all-repeated=separate
+find -size +0 -type f -printf "%s\n" | sort -rn | uniq -d | xargs -I{} -n1 find -type f -size {}c -print0 | xargs -0 md5sum | sort | uniq -w32 --all-repeated=separate
 
-echo "Press any key to exit"
-read dummy
+printf "Press any key to exit"
+read -r _
index c4694e3c839b4fc087e3c03dd5758832891b3aae..3633e645d6d7f78649be9dc1e56203b831050a9d 100755 (executable)
@@ -5,7 +5,7 @@
 # Shell: POSIX compliant
 # Author: Anna Arad
 
-. $(dirname $0)/.nnn-plugin-helper
+. "$(dirname "$0")"/.nnn-plugin-helper
 
 if [ "$(cmd_exists fzy)" -eq "0" ]; then
        if [ "$(cmd_exists fd)" -eq "0" ]; then
@@ -23,7 +23,7 @@ else
        exit 1
 fi
 
-if [ "$?" -eq "0" ]; then
+if ! [ -z "$sel" ]; then
        case "$(file -bi "$sel")" in
                *directory*) ;;
                *) sel=$(dirname "$sel") ;;
index ca1db630b5a8bef9a7402287b34880e618e83d7e..c47efa25a1c17db9e3dc5bd523748c0851dad83a 100755 (executable)
@@ -18,15 +18,15 @@ fi
 
 if ! [ -z "$entry" ]; then
     tmpfile=$(mktemp)
-    echo "$entry" >> $tmpfile
-    $EDITOR $tmpfile
+    echo "$entry" >> "$tmpfile"
+    $EDITOR "$tmpfile"
 
-    if [ -s $tmpfile ]; then
-        $SHELL -c "$(cat $tmpfile)"
+    if [ -s "$tmpfile" ]; then
+        $SHELL -c "$(cat "$tmpfile")"
     fi
 
-    rm $tmpfile
+    rm "$tmpfile"
 
-    echo -n "Press any key to exit"
-    read input
+    printf "Press any key to exit"
+    read -r _
 fi
index 97da456590288ab1507c168fec72ce6286d5d5b4..046e7e91d7e187988137ef31abf505893c571561 100755 (executable)
@@ -7,7 +7,7 @@
 # Shell: POSIX compliant
 # Author: Arun Prakash Jana
 
-entry="$(find -type f 2>/dev/null | fzy)"
+entry="$(find -type f 2>/dev/null | fzy)"
 
 case "$(file -biL "$entry")" in
     *text*)
index 34f599f4c088804030cbfe44f4778bd935cb6a00..f7720a877b31eb27179efecb263b192056706bef 100755 (executable)
@@ -14,13 +14,13 @@ is_cmd_exists () {
 }
 
 merge () {
-       vimdiff $1 $2
+       vimdiff "$1" "$2"
 }
 
 prompt () {
-       echo "Plugin $1 already exists and is different."
-       echo -n "Keep (k), merge (m), overwrite (o) [default: k]? "
-       read operation
+       printf "%s" "Plugin $1 already exists and is different.\n"
+       printf "Keep (k), merge (m), overwrite (o) [default: k]? "
+       read -r operation
 
        if [ "$operation" = "m" ]; then
                op="merge"
@@ -40,27 +40,27 @@ else
 fi
 
 # backup any earlier plugins
-if [ -d $PLUGIN_DIR ]; then
-    tar -C $CONFIG_DIR -czf $CONFIG_DIR"plugins-$(date '+%Y%m%d%H%M').tar.gz" plugins/
+if [ -d "$PLUGIN_DIR" ]; then
+    tar -C "$CONFIG_DIR" -czf "$CONFIG_DIR""plugins-$(date '+%Y%m%d%H%M').tar.gz" plugins/
 fi
 
-mkdir -p $PLUGIN_DIR
-cd $CONFIG_DIR
+mkdir -p "$PLUGIN_DIR"
+cd "$CONFIG_DIR" || exit 1
 curl -Ls -O https://github.com/jarun/nnn/archive/master.tar.gz
 tar -zxf master.tar.gz
 
-cd nnn-master/plugins
+cd nnn-master/plugins || exit 1
 for f in *; do
-       if [ -f ../../plugins/$f ]; then
-               if [ "$(diff --brief $f ../../plugins/$f)" ]; then
-                       prompt $f
-                       $op $f ../../plugins/
+       if [ -f ../../plugins/"$f" ]; then
+               if [ "$(diff --brief "$f" ../../plugins/"$f")" ]; then
+                       prompt "$f"
+                       $op "$f" ../../plugins/
                fi
        else
-               cp -vRf $f ../../plugins/
+               cp -vRf "$f" ../../plugins/
        fi
 done
-cd ../..
+cd ../.. || exit 1
 
 $sucmd mv -vf nnn-master/misc/nlaunch/nlaunch /usr/local/bin/
-rm -rf nnn-master/ master.tar.gz $PLUGIN_DIR/README.md
+rm -rf nnn-master/ master.tar.gz "$PLUGIN_DIR"/README.md
index c1ff6ba1146bc5b3c4ad91f8a126ee0c3c361903..95634ab9618730f9715dff1cb79a99a2759f6f53 100755 (executable)
@@ -25,25 +25,25 @@ BROWSER=w3m
 READER=
 
 if [ ! -z "$EBOOK_ID" ]; then
-    if [ ! -e $DIR ]; then
-        mkdir -p $DIR
-        cd $DIR
+    if [ ! -e "$DIR" ]; then
+        mkdir -p "$DIR"
+        cd "$DIR" || exit 1
 
         if [ -z "$READER" ]; then
-            curl -L -O "https://www.gutenberg.org/files/"$EBOOK_ID"/"$EBOOK_ID"-h.zip"
+            curl -L -O https://www.gutenberg.org/files/"$EBOOK_ID"/"$EBOOK_ID"-h.zip
             unzip "$EBOOK_ID"-h.zip
         else
-            curl -L -o "$EBOOK_ID".epub "http://www.gutenberg.org/ebooks/"$EBOOK_ID".epub.noimages"
+            curl -L -o "$EBOOK_ID".epub http://www.gutenberg.org/ebooks/"$EBOOK_ID".epub.noimages
         fi
     fi
 
-    if [ -d $DIR ]; then
+    if [ -d "$DIR" ]; then
         if [ -z "$READER" ]; then
-            "$BROWSER" $DIR/"$EBOOK_ID"-h/"$EBOOK_ID"-h.htm
+            "$BROWSER" "$DIR"/"$EBOOK_ID"-h/"$EBOOK_ID"-h.htm
         else
-            "$READER" $DIR/"$EBOOK_ID".epub
+            "$READER" "$DIR"/"$EBOOK_ID".epub
         fi
     fi
 else
-    "$BROWSER" $BROWSE_LINK
+    "$BROWSER" "$BROWSE_LINK"
 fi
index 01917e772f46abc7cf286ebd2cd4a5f4a19f271c..def556019f4db13ad550a63330b1f8f00dbd8893 100755 (executable)
@@ -21,8 +21,8 @@ res=
 minsize=1048576
 
 if [ -z "$res" ]; then
-    echo -n "desktop resolution (hxv): "
-    read res
+    printf "desktop resolution (hxv): "
+    read -r res
 fi
 
 if ! [ -z "$res" ] && ! [ -z "$minsize" ]; then
index 8b39b557f530522441748fe80788c837a066f430..a5715157c49d7d8da7c7f6cb994c37bb2154c927 100755 (executable)
@@ -78,14 +78,22 @@ upload_timeout="120"
 upload_retries="1"
 
 if is_mac; then
+  # shellcheck disable=SC2034
   screenshot_select_command="screencapture -i %img"
+  # shellcheck disable=SC2034
   screenshot_window_command="screencapture -iWa %img"
+  # shellcheck disable=SC2034
   screenshot_full_command="screencapture %img"
+  # shellcheck disable=SC2034
   open_command="open %url"
 else
+  # shellcheck disable=SC2034
   screenshot_select_command="scrot -s %img"
+  # shellcheck disable=SC2034
   screenshot_window_command="scrot %img"
+  # shellcheck disable=SC2034
   screenshot_full_command="scrot %img"
+  # shellcheck disable=SC2034
   open_command="xdg-open %url"
 fi
 open="true"
@@ -162,7 +170,7 @@ function take_screenshot() {
   cmd=${!cmd//\%img/${1}}
 
   shot_err="$(${cmd} &>/dev/null)" #takes a screenshot with selection
-  if [ "${?}" != "0" ]; then
+  if ! [ -z "$shot_err" ]; then
     echo "Failed to take screenshot '${1}': '${shot_err}'. For more information visit https://github.com/jomo/imgur-screenshot/wiki/Troubleshooting" | tee -a "${log_file}"
     notify error "Something went wrong :(" "Information has been logged"
     exit 1
@@ -171,8 +179,8 @@ function take_screenshot() {
 
 function check_for_update() {
   # exit non-zero on HTTP error, output only the body (no stats) but output errors, follow redirects, output everything to stdout
-  remote_version="$(curl --compressed -fsSL --stderr - "https://api.github.com/repos/jomo/imgur-screenshot/releases" | egrep -m 1 --color 'tag_name":\s*".*"' | cut -d '"' -f 4)"
-  if [ "${?}" -eq "0" ]; then
+  remote_version="$(curl --compressed -fsSL --stderr - "https://api.github.com/repos/jomo/imgur-screenshot/releases" | grep -Em 1 --color 'tag_name":\s*".*"' | cut -d '"' -f 4)"
+  if ! [ -z "$remote_version" ]; then
     if [ ! "${current_version}" = "${remote_version}" ] && [ ! -z "${current_version}" ] && [ ! -z "${remote_version}" ]; then
       echo "Update found!"
       echo "Version ${remote_version} is available (You have ${current_version})"
@@ -249,7 +257,7 @@ function refresh_access_token() {
   token_url="https://api.imgur.com/oauth2/token"
   # exchange the refresh token for access_token and refresh_token
   response="$(curl --compressed -fsSL --stderr - -F "client_id=${imgur_acct_key}" -F "client_secret=${imgur_secret}" -F "grant_type=refresh_token" -F "refresh_token=${refresh_token}" "${token_url}")"
-  if [ ! "${?}" -eq "0" ]; then
+  if ! [ -z "$response" ]; then
     # curl failed
     handle_upload_error "${response}" "${token_url}"
     exit 1
@@ -265,9 +273,9 @@ function save_access_token() {
     exit 1
   fi
 
-  access_token="$(egrep -o 'access_token":".*"' <<<"${1}" | cut -d '"' -f 3)"
-  refresh_token="$(egrep -o 'refresh_token":".*"' <<<"${1}" | cut -d '"' -f 3)"
-  expires_in="$(egrep -o 'expires_in":[0-9]*' <<<"${1}" | cut -d ':' -f 2)"
+  access_token="$(grep -Eo 'access_token":".*"' <<<"${1}" | cut -d '"' -f 3)"
+  refresh_token="$(grep -Eo 'refresh_token":".*"' <<<"${1}" | cut -d '"' -f 3)"
+  expires_in="$(grep -Eo 'expires_in":[0-9]*' <<<"${1}" | cut -d ':' -f 2)"
   token_expire_time="$(( $(date +%s) + expires_in ))"
 
   # create dir if not exist
@@ -282,8 +290,8 @@ EOF
 
 function fetch_account_info() {
   response="$(curl --compressed --connect-timeout "${upload_connect_timeout}" -m "${upload_timeout}" --retry "${upload_retries}" -fsSL --stderr - -H "Authorization: Bearer ${access_token}" https://api.imgur.com/3/account/me)"
-  if egrep -q '"success":\s*true' <<<"${response}"; then
-    username="$(egrep -o '"url":\s*"[^"]+"' <<<"${response}" | cut -d "\"" -f 4)"
+  if grep -Eq '"success":\s*true' <<<"${response}"; then
+    username="$(grep -Eo '"url":\s*"[^"]+"' <<<"${response}" | cut -d "\"" -f 4)"
     echo "Logged in as ${username}."
     echo "https://${username}.imgur.com"
   else
@@ -293,7 +301,7 @@ function fetch_account_info() {
 
 function delete_image() {
   response="$(curl --compressed -X DELETE  -fsSL --stderr - -H "Authorization: Client-ID ${1}" "https://api.imgur.com/3/image/${2}")"
-  if egrep -q '"success":\s*true' <<<"${response}"; then
+  if grep -Eq '"success":\s*true' <<<"${response}"; then
     echo "Image successfully deleted (delete hash: ${2})." >> "${3}"
   else
     echo "The Image could not be deleted: ${response}." >> "${3}"
@@ -310,10 +318,10 @@ function upload_authenticated_image() {
   fi
 
   # JSON parser premium edition (not really)
-  if egrep -q '"success":\s*true' <<<"${response}"; then
-    img_id="$(egrep -o '"id":\s*"[^"]+"' <<<"${response}" | cut -d "\"" -f 4)"
-    img_ext="$(egrep -o '"link":\s*"[^"]+"' <<<"${response}" | cut -d "\"" -f 4 | rev | cut -d "." -f 1 | rev)" # "link" itself has ugly '\/' escaping and no https!
-    del_id="$(egrep -o '"deletehash":\s*"[^"]+"' <<<"${response}" | cut -d "\"" -f 4)"
+  if grep -Eq '"success":\s*true' <<<"${response}"; then
+    img_id="$(grep -Eo '"id":\s*"[^"]+"' <<<"${response}" | cut -d "\"" -f 4)"
+    img_ext="$(grep -Eo '"link":\s*"[^"]+"' <<<"${response}" | cut -d "\"" -f 4 | rev | cut -d "." -f 1 | rev)" # "link" itself has ugly '\/' escaping and no https!
+    del_id="$(grep -Eo '"deletehash":\s*"[^"]+"' <<<"${response}" | cut -d "\"" -f 4)"
 
     if [ ! -z "${auto_delete}" ]; then
       export -f delete_image
@@ -323,7 +331,7 @@ function upload_authenticated_image() {
 
     handle_upload_success "https://i.imgur.com/${img_id}.${img_ext}" "https://imgur.com/delete/${del_id}" "${1}"
   else # upload failed
-    err_msg="$(egrep -o '"error":\s*"[^"]+"' <<<"${response}" | cut -d "\"" -f 4)"
+    err_msg="$(grep -Eo '"error":\s*"[^"]+"' <<<"${response}" | cut -d "\"" -f 4)"
     test -z "${err_msg}" && err_msg="${response}"
     handle_upload_error "${err_msg}" "${1}"
   fi
@@ -338,10 +346,10 @@ function upload_anonymous_image() {
     response="$(curl --compressed --connect-timeout "${upload_connect_timeout}" -m "${upload_timeout}" --retry "${upload_retries}" -fsSL --stderr - -H "Authorization: Client-ID ${imgur_anon_id}" -F "title=${title}" -F "image=@\"${1}\"" https://api.imgur.com/3/image)"
   fi
   # JSON parser premium edition (not really)
-  if egrep -q '"success":\s*true' <<<"${response}"; then
-    img_id="$(egrep -o '"id":\s*"[^"]+"' <<<"${response}" | cut -d "\"" -f 4)"
-    img_ext="$(egrep -o '"link":\s*"[^"]+"' <<<"${response}" | cut -d "\"" -f 4 | rev | cut -d "." -f 1 | rev)" # "link" itself has ugly '\/' escaping and no https!
-    del_id="$(egrep -o '"deletehash":\s*"[^"]+"' <<<"${response}" | cut -d "\"" -f 4)"
+  if grep -Eq '"success":\s*true' <<<"${response}"; then
+    img_id="$(grep -Eo '"id":\s*"[^"]+"' <<<"${response}" | cut -d "\"" -f 4)"
+    img_ext="$(grep -Eo '"link":\s*"[^"]+"' <<<"${response}" | cut -d "\"" -f 4 | rev | cut -d "." -f 1 | rev)" # "link" itself has ugly '\/' escaping and no https!
+    del_id="$(grep -Eo '"deletehash":\s*"[^"]+"' <<<"${response}" | cut -d "\"" -f 4)"
 
     if [ ! -z "${auto_delete}" ]; then
       export -f delete_image
@@ -351,7 +359,7 @@ function upload_anonymous_image() {
 
     handle_upload_success "https://i.imgur.com/${img_id}.${img_ext}" "https://imgur.com/delete/${del_id}" "${1}"
   else # upload failed
-    err_msg="$(egrep -o '"error":\s*"[^"]+"' <<<"${response}" | cut -d "\"" -f 4)"
+    err_msg="$(grep -Eo '"error":\s*"[^"]+"' <<<"${response}" | cut -d "\"" -f 4)"
     test -z "${err_msg}" && err_msg="${response}"
     handle_upload_error "${err_msg}" "${1}"
   fi
@@ -456,6 +464,7 @@ while [ ${#} != 0 ]; do
     mode="full"
     shift;;
   -o | --open)
+    # shellcheck disable=SC2034
     open="${2}"
     shift 2;;
   -e | --edit)
@@ -511,23 +520,23 @@ if [ -n "${album_title}" ]; then
       -H "Authorization: Client-ID ${imgur_anon_id}" \
       https://api.imgur.com/3/album)"
   fi
-  if egrep -q '"success":\s*true' <<<"${response}"; then # Album creation successful
+  if grep -Eq '"success":\s*true' <<<"${response}"; then # Album creation successful
     echo "Album '${album_title}' successfully created"
-    album_id="$(egrep -o '"id":\s*"[^"]+"' <<<"${response}" | cut -d "\"" -f 4)"
-    del_id="$(egrep -o '"deletehash":\s*"[^"]+"' <<<"${response}" | cut -d "\"" -f 4)"
+    album_id="$(grep -Eo '"id":\s*"[^"]+"' <<<"${response}" | cut -d "\"" -f 4)"
+    del_id="$(grep -Eo '"deletehash":\s*"[^"]+"' <<<"${response}" | cut -d "\"" -f 4)"
     handle_album_creation_success "http://imgur.com/a/${album_id}" "${del_id}" "${album_title}"
 
     if [ "${login}" = "false" ]; then
       album_id="${del_id}"
     fi
   else # Album creation failed
-    err_msg="$(egrep -o '"error":\s*"[^"]+"' <<<"${response}" | cut -d "\"" -f 4)"
+    err_msg="$(grep -Eo '"error":\s*"[^"]+"' <<<"${response}" | cut -d "\"" -f 4)"
     test -z "${err_msg}" && err_msg="${response}"
     handle_album_creation_error "${err_msg}" "${album_title}"
   fi
 fi
 
-if [ -z "${upload_files}" ]; then
+if [ -z "${upload_files[*]}" ]; then
   upload_files[0]=""
 fi
 
@@ -545,11 +554,13 @@ for upload_file in "${upload_files[@]}"; do
   fi
 
   # get full path
-  img_file="$(cd "$( dirname "${img_file}")" && echo "$(pwd)/$(basename "${img_file}")")"
+  #cd "$(dirname "$(realpath "${img_file}")")"
+  #img_file="$(realpath "${img_file}")"
 
   # check if file exists
-  if [ ! -f "${img_file}" ]; then
+  if ! [ -f "${img_file}" ]; then
     echo "file '${img_file}' doesn't exist !"
+    read -r _
     exit 1
   fi
 
@@ -584,4 +595,4 @@ if [ "${check_update}" = "true" ]; then
   check_for_update
 fi
 
-read dummy
+read -r _
index 70b800762787c985ff9cb164f3e3e0c7681dbc3c..4ff6f415316b2342820f4e26e68bd7e97e0b2e79 100755 (executable)
@@ -5,9 +5,9 @@
 # Shell: POSIX compliant
 # Author: Arun Prakash Jana
 
-IP=`curl -s ifconfig.me`
+IP=$(curl -s ifconfig.me)
 
 whois "$IP"
 echo your external IP address is "$IP"
 
-read dummy
+read -r _
index 1bb0624d2cd85ea641c4d68f86e0174ea3957218..d9619f9709fbda7dde45204961f3f14e94b37ead 100755 (executable)
@@ -18,7 +18,7 @@ out="$(mocp -i)"
 
 # Check if anything is playing
 state=$(echo "$out" | grep "State:" | cut -d' ' -f2)
-if ! [ $state = 'PLAY' ]; then
+if ! [ "$state" = 'PLAY' ]; then
     exit
 fi
 
index 5f37c37773bf69c195671a68ffedc9e3ee8f7f0b..211a3db5fe43bbaa846a831d5ad788d5496b1843 100755 (executable)
@@ -18,7 +18,8 @@ ret=$cmd
 
 SHUFFLE=0
 
-mocp_add() {
+mocp_add ()
+{
     if [ $SHUFFLE = 1 ]; then
         if [ "$resp" = "y" ]; then
             arr=$(tr '\0' '\n' < "$selection")
@@ -38,7 +39,7 @@ mocp_add() {
         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 -v '\.m3u$\|\.pls$')" ]; then
+            if [ -f "$entry" ] &&  echo "$entry" | grep -qv '\.m3u$\|\.pls$' ; then
                 mocp -a "$entry"
             fi
         done
@@ -57,8 +58,8 @@ if [ ! -s "$selection" ] && [ -z "$1" ]; then
 fi
 
 if [ -s "$selection" ]; then
-    echo -n "Work with selection? Enter 'y' to confirm: "
-    read resp
+    printf "Work with selection? Enter 'y' to confirm: "
+    read -r resp
 fi
 
 if [ -z "$ret" ]; then
@@ -68,7 +69,7 @@ else
     # mocp running, check if it's playing
     state=$(mocp -i | grep "State:" | cut -d' ' -f2)
 
-    if [ $state = 'PLAY' ]; then
+    if [ "$state" = 'PLAY' ]; then
         # add to playlist and exit
         mocp_add "$1"
 
index f5ca0dc3f2985a5bf607eb1394f07fcaf94b7569..368062759673198ab69f10ee1812c5e766eae9dc 100755 (executable)
 
 selection=${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection
 
-if [ -s $selection ]; then
+if [ -s "$selection" ]; then
     arr=$(tr '\0' '\n' < "$selection")
     if [ "$(echo "$arr" | wc -l)" -gt 1 ]; then
          f1="$(echo "$arr" | sed -n '1p')"
          f2="$(echo "$arr" | sed -n '2p')"
          if [ -d "$f1" ] && [ -d "$f2" ]; then
-            dir1=$(mktemp "${TMPDIR:-/tmp}"/nnn-$(basename "$f1").XXXXXXXX)
-            dir2=$(mktemp "${TMPDIR:-/tmp}"/nnn-$(basename "$f2").XXXXXXXX)
+            dir1=$(mktemp "${TMPDIR:-/tmp}"/nnn-"$(basename "$f1")".XXXXXXXX)
+            dir2=$(mktemp "${TMPDIR:-/tmp}"/nnn-"$(basename "$f2")".XXXXXXXX)
             ls -A1 "$f1" > "$dir1"
             ls -A1 "$f2" > "$dir2"
             vimdiff "$dir1" "$dir2"
@@ -27,7 +27,7 @@ if [ -s $selection ]; then
             #     Vim: Warning: Input is not from a terminal
             # xargs -0 -o vimdiff < $selection
 
-            xargs -0 vimdiff +0 < $selection
+            xargs -0 vimdiff +0 < "$selection"
         fi
     else
         echo "needs at least 2 files or directories selected for comparison"
index 9fb4e9009f830eb910d56002dcb2220f0dfb782d..3f638bf45ed9ce1dad283dc4c38f030e290baee7 100755 (executable)
@@ -20,10 +20,9 @@ prompt="device name ['l' lists]: "
 
 lsblk
 
-echo
-echo "Make sure you aren't still in the mounted device."
-echo -n "$prompt"
-read dev
+printf "\nMake sure you aren't still in the mounted device."
+printf "%s" "$prompt"
+read -r dev
 
 while ! [ -z "$dev" ]
 do
@@ -34,11 +33,11 @@ do
     else
         if grep -qs "$dev " /proc/mounts; then
             sync
-            pumount "$dev"
-            if [ "$?" -eq "0" ]; then
+            if pumount "$dev"
+            then
                 echo "$dev" unmounted.
-                udisksctl power-off -b /dev/"$dev"
-                if [ "$?" -eq "0" ]; then
+                if udisksctl power-off -b /dev/"$dev"
+                then
                     echo "$dev" ejected.
                 fi
             fi
@@ -49,6 +48,6 @@ do
     fi
 
     echo
-    echo -n "$prompt"
-    read dev
+    printf "%s" "$prompt"
+    read -r dev
 done
index 2f18b0815f837323e37ee0cd6ce8cb10b3d5aa0f..32d0218593ddf267c8081c974d89413c659fab02 100755 (executable)
@@ -6,8 +6,8 @@
 # Author: juacq97
 
 if ! [ -z "$1" ]; then
-    if [ $(mimetype --output-format %m $1 | awk -F '/' '{print $1}') == "image" ]; then
-           nitrogen --set-zoom-fill --save $1
+    if [ "$(mimetype --output-format %m "$1" | awk -F '/' '{print $1}')" = "image" ]; then
+           nitrogen --set-zoom-fill --save "$1"
 # If you want a system notification, uncomment the next 3 lines.
 #           notify-send -a "nnn" "Wallpaper changed!"
 #    else
index 4b1740518b1f5f3391c4e1a67f304e4266608fd2..68f4bed82dc205696ba4a3877ef2eb8a3fa948d2 100755 (executable)
@@ -7,10 +7,10 @@
 # Shell: POSIX compliant
 # Author: Arun Prakash Jana
 
-echo -n "Min file size (MB): "
-read size
+printf "Min file size (MB): "
+read -r size
 
-find -size +"$size"M -type f -printf '%A+ %s %p\n' | sort
+find -size +"$size"M -type f -printf '%A+ %s %p\n' | sort
 
 echo "Press any key to exit"
-read dummy
+read -r _
index 13fb3e7326c8ccdf2e39b29b76e267ef26ddbb06..61039e662127c2ad7bc2dfbc25638dcd5cf8b05a 100755 (executable)
@@ -6,6 +6,6 @@
 # Author: Arun Prakash Jana
 
 if ! [ -z "$1" ]; then
-    curl -F "f:1=@"$1"" ix.io
-    read input
+    curl -F "f:1=@$1" ix.io
+    read -r _
 fi
index 17f45e0e1b6076eb9aae148f369c90dc4fdb1d68..2b953b5d85cb1330e903f0f88fc7498b96dcbb9e 100755 (executable)
@@ -10,7 +10,7 @@
 # Author: Arun Prakash Jana
 
 if ! [ -z "$1" ]; then
-    if [ $(head -c 4 "$1") = "%PDF" ]; then
+    if [ "$(head -c 4 "$1")" = "%PDF" ]; then
         # Convert using pdftotext
         pdftotext -nopgbrk -layout "$1" - | sed 's/\xe2\x80\x8b//g' | $PAGER
 
index dcec180cd368045bf7312c7ad2e8b1a812922d9f..d02c9fa44c71d183256395cc2b5a6ed8d564107d 100755 (executable)
@@ -20,10 +20,11 @@ else
     sucmd=: # noop
 fi
 
-echo -n "Enter process name ['defunct' for zombies]: "
-read psname
+printf "Enter process name ['defunct' for zombies]: "
+read -r psname
 
 if ! [ -z "$psname" ]; then
+    # shellcheck disable=SC2009
     cmd="$(ps -ax | grep -iw "$psname" | fzy | sed -e 's/^[ \t]*//' | cut -d' ' -f1)"
     $sucmd kill -9 "$cmd"
 fi
index 161bbb5c85fab947b73b7c9589868eb9c9830486..c8ec8671eff0f12e1f674e41834bcce92b0ff2a2 100755 (executable)
@@ -6,8 +6,8 @@
 # Author: juacq97
 
 if ! [ -z "$1" ]; then
-    if [ $(mimetype --output-format %m $1 | awk -F '/' '{print $1}') == "image" ]; then
-           wal -i $1
+    if [ "$(mimetype --output-format %m "$1" | awk -F '/' '{print $1}')" = "image" ]; then
+           wal -i "$1"
 # If you want a system notification, uncomment the next 3 lines.
 #           notify-send -a "nnn" "Wallpaper changed!"
 #    else
index e0058dbf3078864caa88fa36485b0bb750b3d29c..4f47992b2de4701c53655df4885fbcf0ff97b462 100755 (executable)
@@ -6,10 +6,10 @@
 # Author: Arun Prakash Jana
 
 if ! [ -z "$1" ]; then
-    tmpf=`basename "$1"`
+    tmpf="$(basename "$1")"
     tmpf="${TMPDIR:-/tmp}"/"${tmpf%.*}"
 
-    if [ $(head -c 4 "$1") = "%PDF" ]; then
+    if [ "$(head -c 4 "$1")" = "%PDF" ]; then
         # Convert using pdftotext
         pdftotext -nopgbrk -layout "$1" - | sed 's/\xe2\x80\x8b//g' > "$tmpf".txt
 
index d67a4092704842e0feea6b73200ad9a70b31c0e7..38c11bda0fc8e4498d16187228b5c4bfeb3a04ff 100755 (executable)
 # Author: Arun Prakash Jana
 
 if [ -n "$1" ]; then
-    echo -n "start (hh:mm:ss): "
-    read start
+    printf "start (hh:mm:ss): "
+    read -r start
     st=$(date -d "$start" +%s) || exit 1
 
-    echo -n "end (hh:mm:ss): "
-    read end
+    printf "end (hh:mm:ss): "
+    read -r end
     et=$(date -d "$end" +%s) || exit 1
 
-    if [ $st -ge $et ]; then
-        echo "error: start >= end"
+    if [ "$st" -ge "$et" ]; then
+        printf "error: start >= end "
+        read -r _
         exit 1
     fi
 
-    interval=$(( $et - $st ))
+    interval=$(( et - st ))
 
     outfile=$(basename "$1")
     outfile="${outfile%.*}"_ringtone.mp3
index 60a5408264263f622b2bc821e2379a50a38e21c9..fcd49de3b575298acf67d24005d0f5c28943f291 100755 (executable)
@@ -12,8 +12,8 @@ selection=${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection
 resp=s
 
 if [ -s "$selection" ]; then
-    echo -n "press 's' (split current file) or 'j' (join selection): "
-    read resp
+    printf "press 's' (split current file) or 'j' (join selection): "
+    read -r resp
 fi
 
 if [ "$resp" = "j" ]; then
@@ -37,8 +37,8 @@ if [ "$resp" = "j" ]; then
 elif [ "$resp" = "s" ]; then
     if [ -n "$1" ] && [ -f "$1" ]; then
         # a single file is passed
-        echo -n "split size in MB: "
-        read size
+        printf "split size in MB: "
+        read -r size
 
         if [ -n "$size" ]; then
             split -d -b "$size"M "$1" "$1"
index 2c677fe9e1f7cb4241582053bbc17708d7d851d2..1fe81b79428aaa3368d87fc280d09437e5ae1cef 100755 (executable)
@@ -16,5 +16,5 @@ if command -v sxiv >/dev/null 2>&1; then
     fi
 else
     echo "sxiv missing"
-    read dummy
+    read -r _
 fi
index 10bb6511b258033b5b16932b987efc084de684bb..88821152247638e3c3edbbd74d446675a8d1c31b 100755 (executable)
@@ -12,6 +12,6 @@ if ! [ -z "$1" ]; then
         lsix "$1"
     fi
 
-    echo -n "Press any key to exit..."
-    read dummy
+    printf "Press any key to exit..."
+    read -r _
 fi
index 7201b0b5aed5f6fa4e104e561f7fcf71827640b4..05992a3fd3156fcaffd287b47601e723e50eafe5 100755 (executable)
@@ -7,9 +7,9 @@
 
 if ! [ -z "$1" ]; then
     # Upload the file, show the download link and wait till user presses any key
-    curl -s --upload-file "$1" https://transfer.sh/`basename "$1"`
+    curl -s --upload-file "$1" https://transfer.sh/"$(basename "$1")"
     echo
-    read input
+    read -r _
 
     # To write download link to "$1".loc and exit
     # curl -s --upload-file "$1" https://transfer.sh/`basename "$1"` -o `basename "$1"`.loc
index 37d832defe5261d831538e96fdf7ddbf26ee5b3d..a73acae03e7f30b13a62a9c78045945976c815f4 100755 (executable)
@@ -5,4 +5,5 @@
 # Shell: POSIX compliant
 # Author: Arun Prakash Jana, superDuperCyberTechno
 
+# shellcheck disable=SC2012
 ls -lah --group-directories-first | less
index 8dd3b5a9cda2fa90af5479170eba42b6470f9bc1..d166991979a9170a3382376bf5ab1163c5c09104 100755 (executable)
@@ -6,10 +6,10 @@
 # Author: Arun Prakash Jana
 # NOTE: This script installs a package, should be issued with admin privilege
 
-cur=`nnn -v`
-new=`curl -s "https://github.com/jarun/nnn/releases/latest" | grep -Eo "[0-9]+\.[0-9]+"`
+cur="$(nnn -v)"
+new="$(curl -s "https://github.com/jarun/nnn/releases/latest" | grep -Eo "[0-9]+\.[0-9]+")"
 
-if [ $cur_ver == $new_ver ]; then
+if [ "$cur" = "$new" ]; then
     echo 'Already at latest version'
     exit 0
 fi
@@ -18,7 +18,7 @@ fi
 curl -Ls -O "https://github.com/jarun/nnn/releases/download/v$new/nnn_$new-1_debian9.amd64.deb"
 
 # install it
-sudo dpkg -i nnn_$new-1_debian9.amd64.deb
+sudo dpkg -i nnn_"$new"-1_debian9.amd64.deb
 
 # remove the file
-rm -rf nnn_$new-1_debian9.amd64.deb
+rm -rf nnn_"$new"-1_debian9.amd64.deb
index a6eb0e4383d904893de26113772fa42852872139..6411eb1c294a3161428d316d547993f1524aa1ba 100755 (executable)
@@ -23,5 +23,5 @@ lsix .nthumbs/*
 # remove the thumbnails
 rm -rf .nthumbs
 
-echo -n "Press any key to exit..."
-read dummy
+printf "Press any key to exit..."
+read -r _