diff --git a/.circleci/config.yml b/.circleci/config.yml index 7724129e..8b1f5633 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -70,7 +70,7 @@ jobs: echo "########## clang-tidy-10 ##########" clang-tidy-10 src/* -- -I/usr/include -I/usr/include/ncursesw echo "########## shellcheck ##########" - find plugins/ -type f -not -name "*.md" -exec shellcheck -e SC1090 {} + + find plugins/ -type f -not -name "*.md" -exec shellcheck -e SC1090,SC2230 {} + package-and-publish: machine: true diff --git a/plugins/README.md b/plugins/README.md index a3d3700d..d802cffd 100644 --- a/plugins/README.md +++ b/plugins/README.md @@ -41,7 +41,7 @@ Plugins extend the capabilities of `nnn`. They are _executable_ scripts (or bina | [kdeconnect](kdeconnect) | Send selected files to an Android device | sh | kdeconnect-cli | | [launch](launch) | GUI application launcher | sh | fzf | | [mediainf](mediainf) | Show media information | sh | mediainfo | -| [mimelist](mimelist) | List files by mime in subtree | sh | fd/find | +| [mimelist](mimelist) | List files by mime in subtree | sh | - | | [moclyrics](moclyrics) | Show lyrics of the track playing in moc | sh | [ddgr](https://github.com/jarun/ddgr), [moc](http://moc.daper.net/) | | [mocplay](mocplay) | Append (and/or play) selection/dir/file in moc | sh | [moc](http://moc.daper.net/) | | [mp3conv](mp3conv) | Extract audio from multimedia as mp3 | sh | ffmpeg | diff --git a/plugins/boom b/plugins/boom index 5debfad7..10f14f60 100755 --- a/plugins/boom +++ b/plugins/boom @@ -9,7 +9,7 @@ GUIPLAYER="${GUIPLAYER}" NUMTRACKS="${NUMTRACKS:-100}" -if [ ! -z "$GUIPLAYER" ]; then +if [ -n "$GUIPLAYER" ]; then 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 diff --git a/plugins/diffs b/plugins/diffs index 294c5e77..d20cc5da 100755 --- a/plugins/diffs +++ b/plugins/diffs @@ -41,7 +41,7 @@ if [ -s "$selection" ]; then eval xargs -0 "$diffcmd" < "$selection" fi - elif ! [ -z "$1" ]; then + elif [ -n "$1" ]; then f1="$(echo "$arr" | sed -n '1p')" if [ -d "$f1" ] && [ -d "$1" ]; then dirdiff "$f1" "$1" diff --git a/plugins/finder b/plugins/finder index 649b7113..bd34d5d9 100755 --- a/plugins/finder +++ b/plugins/finder @@ -22,7 +22,7 @@ printf " fzf -m | tr %s %s\n\n" "'\n'" "'\0'" printf "cmd: " read -r cmd -if ! [ -z "$cmd" ]; then +if [ -n "$cmd" ]; then printf "%s" "+l" > "$NNN_PIPE" eval "$cmd" > "$NNN_PIPE" fi diff --git a/plugins/fzhist b/plugins/fzhist index a3aac3a3..e824fc2f 100755 --- a/plugins/fzhist +++ b/plugins/fzhist @@ -22,7 +22,7 @@ elif [ "$shellname" = "fish" ]; then entry="$(grep "\- cmd: " "$hist_file" | cut -c 8- | "$fuzzy")" fi -if ! [ -z "$entry" ]; then +if [ -n "$entry" ]; then tmpfile=$(mktemp) echo "$entry" >> "$tmpfile" $EDITOR "$tmpfile" diff --git a/plugins/hexview b/plugins/hexview index ce17a60d..22936bc8 100755 --- a/plugins/hexview +++ b/plugins/hexview @@ -6,7 +6,7 @@ # Shell: POSIX compliant # Author: Arun Prakash Jana -if ! [ -z "$1" ]; then +if [ -n "$1" ]; then if which hx >/dev/null 2>&1; then hx "$1" else diff --git a/plugins/imgresize b/plugins/imgresize index d85d4b51..f04a883b 100755 --- a/plugins/imgresize +++ b/plugins/imgresize @@ -25,6 +25,6 @@ if [ -z "$res" ]; then read -r res fi -if ! [ -z "$res" ] && ! [ -z "$MINSIZE" ]; then +if [ -n "$res" ] && [ -n "$MINSIZE" ]; then imgp -ackx "$res" -s "$MINSIZE" fi diff --git a/plugins/imgthumb b/plugins/imgthumb index 88821152..8e217077 100755 --- a/plugins/imgthumb +++ b/plugins/imgthumb @@ -5,7 +5,7 @@ # Shell: POSIX compliant # Author: Arun Prakash Jana -if ! [ -z "$1" ]; then +if [ -n "$1" ]; then if [ -d "$1" ]; then lsix "$1"/* else diff --git a/plugins/imgur b/plugins/imgur index e95360c7..9115c480 100755 --- a/plugins/imgur +++ b/plugins/imgur @@ -172,8 +172,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" | 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 + if [ -n "$remote_version" ]; then + if [ ! "${current_version}" = "${remote_version}" ] && [ -n "${current_version}" ] && [ -n "${remote_version}" ]; then echo "Update found!" echo "Version ${remote_version} is available (You have ${current_version})" notify ok "Update found" "Version ${remote_version} is available (You have ${current_version}). https://github.com/jomo/imgur-screenshot" @@ -209,7 +209,7 @@ function load_access_token() { current_time="$(date +%s)" preemptive_refresh_time="$((10*60))" expired="$((current_time > (token_expire_time - preemptive_refresh_time)))" - if [ ! -z "${refresh_token}" ]; then + if [ -n "${refresh_token}" ]; then # token already set if [ "${expired}" -eq "0" ]; then # token expired @@ -320,7 +320,7 @@ function upload_authenticated_image() { 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 + if [ -n "${auto_delete}" ]; then export -f delete_image echo "Deleting image in ${auto_delete} seconds." nohup /bin/bash -c "sleep ${auto_delete} && delete_image ${imgur_anon_id} ${del_id} ${log_file}" & @@ -348,7 +348,7 @@ function upload_anonymous_image() { 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 + if [ -n "${auto_delete}" ]; then export -f delete_image echo "Deleting image in ${auto_delete} seconds." nohup /bin/bash -c "sleep ${auto_delete} && delete_image ${imgur_anon_id} ${del_id} ${log_file}" & diff --git a/plugins/launch b/plugins/launch index 19855f98..c131235e 100755 --- a/plugins/launch +++ b/plugins/launch @@ -34,7 +34,7 @@ get_selection() { if selection=$( get_selection ); then setsid "$selection" 2>/dev/null 1>/dev/null & - if ! [ -z "$1" ]; then + if [ -n "$1" ]; then sleep "$1" else sleep 1 diff --git a/plugins/mediainf b/plugins/mediainf index 15640b4d..22ae8240 100755 --- a/plugins/mediainf +++ b/plugins/mediainf @@ -7,7 +7,7 @@ # Shell: POSIX compliant # Author: Arun Prakash Jana -if ! [ -z "$1" ] && [ -f "$1" ]; then +if [ -n "$1" ] && [ -f "$1" ]; then mediainfo "$1" | $PAGER # exiftool "$1" | $PAGER fi diff --git a/plugins/mimelist b/plugins/mimelist index 743d3056..586cc7cd 100755 --- a/plugins/mimelist +++ b/plugins/mimelist @@ -1,21 +1,14 @@ #!/usr/bin/env sh -# Description: Run fd/find in subtree and list files by mime type in smart context -# Dependencies: fd/find +# Description: Find and list files by mime type in smart context # # Shell: POSIX compliant # Author: Arun Prakash Jana . "$(dirname "$0")"/.nnn-plugin-helper -if [ "$(cmd_exists fd)" -eq "0" ]; then - fd=fd -else - fd=find -fi - printf "mime (e.g., video/audio/image): " read -r mime printf "%s" "+l" > "$NNN_PIPE" -$fd | file -if- | grep "$mime" | awk -F: '{printf "%s\0", $1}' > "$NNN_PIPE" +find . | file -if- | grep "$mime" | awk -F: '{printf "%s\0", $1}' > "$NNN_PIPE" diff --git a/plugins/moclyrics b/plugins/moclyrics index 04e899ea..0dc3cd79 100755 --- a/plugins/moclyrics +++ b/plugins/moclyrics @@ -26,14 +26,14 @@ fi ARTIST="$(echo "$out" | grep 'Artist:' | cut -d':' -f2 | sed 's/^[[:blank:]]*//;s/[[:blank:]]*$//')" TITLE="$(echo "$out" | grep 'SongTitle:' | cut -d':' -f2 | sed 's/^[[:blank:]]*//;s/[[:blank:]]*$//')" -if ! [ -z "$ARTIST" ] && ! [ -z "$TITLE" ]; then +if [ -n "$ARTIST" ] && [ -n "$TITLE" ]; then ddgr -w azlyrics.com --ducky "$ARTIST" "$TITLE" else # Try by file name FILENAME="$(basename "$(echo "$out" | grep 'File:' | cut -d':' -f2)")" FILENAME="$(echo "${FILENAME%%.*}" | tr -d -)" - if ! [ -z "$FILENAME" ]; then + if [ -n "$FILENAME" ]; then ddgr -w azlyrics.com --ducky "$FILENAME" fi fi diff --git a/plugins/nmount b/plugins/nmount index 566119ec..6a9ed8ce 100755 --- a/plugins/nmount +++ b/plugins/nmount @@ -24,7 +24,7 @@ printf "\nEnsure you aren't still in the mounted device.\n" printf "%s" "$prompt" read -r dev -while ! [ -z "$dev" ] +while [ -n "$dev" ] do if [ "$dev" = "l" ]; then lsblk diff --git a/plugins/pdfread b/plugins/pdfread index 4f47992b..1e889be1 100755 --- a/plugins/pdfread +++ b/plugins/pdfread @@ -5,7 +5,7 @@ # Shell: POSIX compliant # Author: Arun Prakash Jana -if ! [ -z "$1" ]; then +if [ -n "$1" ]; then tmpf="$(basename "$1")" tmpf="${TMPDIR:-/tmp}"/"${tmpf%.*}" diff --git a/plugins/pdfview b/plugins/pdfview index 2b953b5d..262e34fe 100755 --- a/plugins/pdfview +++ b/plugins/pdfview @@ -9,7 +9,7 @@ # Shell: POSIX compliant # Author: Arun Prakash Jana -if ! [ -z "$1" ]; then +if [ -n "$1" ]; then if [ "$(head -c 4 "$1")" = "%PDF" ]; then # Convert using pdftotext pdftotext -nopgbrk -layout "$1" - | sed 's/\xe2\x80\x8b//g' | $PAGER diff --git a/plugins/pskill b/plugins/pskill index 979492ab..89008097 100755 --- a/plugins/pskill +++ b/plugins/pskill @@ -13,7 +13,7 @@ printf "Enter process name ['defunct' for zombies]: " read -r psname # shellcheck disable=SC2009 -if ! [ -z "$psname" ]; then +if [ -n "$psname" ]; then if which sudo >/dev/null 2>&1; then sucmd=sudo elif which doas >/dev/null 2>&1; then diff --git a/plugins/upload b/plugins/upload index 196e8f70..56ed0a31 100755 --- a/plugins/upload +++ b/plugins/upload @@ -9,7 +9,7 @@ # Shell: POSIX compliant # Author: Arun Prakash Jana -if ! [ -z "$1" ] && [ -s "$1" ]; then +if [ -n "$1" ] && [ -s "$1" ]; then if which ffsend >/dev/null 2>&1; then ffsend -iq u "$1" elif [ "$(mimetype --output-format %m "$1" | awk -F '/' '{print $1}')" = "text" ]; then diff --git a/plugins/wall b/plugins/wall index 0fc6de78..a35412fa 100755 --- a/plugins/wall +++ b/plugins/wall @@ -11,7 +11,7 @@ cmd_exists () { echo $? } -if ! [ -z "$1" ]; then +if [ -n "$1" ]; then if [ "$(mimetype --output-format %m "$1" | awk -F '/' '{print $1}')" = "image" ]; then if [ "$(cmd_exists nitrogen)" -eq "0" ]; then nitrogen --set-zoom-fill --save "$1"