# Arun Prakash Jana <engineerarun@gmail.com>
#
-_nnn () {
+_nnn ()
+{
COMPREPLY=()
local IFS=$' \n'
local cur=$2 prev=$3
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
-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
}
-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
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
}
exit 1
}
-mkdir -p outdir && cd outdir
+mkdir -p outdir && cd outdir || exit 1
echo 'It works!' > normal.txt
echo 'Με δουλέβει;' > 'κοινό.txt'
# 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.
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 () {
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
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
}
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
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
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
}
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
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
# 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 _
# 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
exit 1
fi
-if [ "$?" -eq "0" ]; then
+if ! [ -z "$sel" ]; then
case "$(file -bi "$sel")" in
*directory*) ;;
*) sel=$(dirname "$sel") ;;
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
# 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*)
}
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"
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
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
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
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"
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
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})"
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
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
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
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}"
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
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
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
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
mode="full"
shift;;
-o | --open)
+ # shellcheck disable=SC2034
open="${2}"
shift 2;;
-e | --edit)
-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
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
check_for_update
fi
-read dummy
+read -r _
# 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 _
# Check if anything is playing
state=$(echo "$out" | grep "State:" | cut -d' ' -f2)
-if ! [ $state = 'PLAY' ]; then
+if ! [ "$state" = 'PLAY' ]; then
exit
fi
SHUFFLE=0
-mocp_add() {
+mocp_add ()
+{
if [ $SHUFFLE = 1 ]; then
if [ "$resp" = "y" ]; then
arr=$(tr '\0' '\n' < "$selection")
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
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
# 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"
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"
# 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"
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
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
fi
echo
- echo -n "$prompt"
- read dev
+ printf "%s" "$prompt"
+ read -r dev
done
# 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
# 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 _
# 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
# 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
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
# 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
# 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
# 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
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
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"
fi
else
echo "sxiv missing"
- read dummy
+ read -r _
fi
lsix "$1"
fi
- echo -n "Press any key to exit..."
- read dummy
+ printf "Press any key to exit..."
+ read -r _
fi
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
# Shell: POSIX compliant
# Author: Arun Prakash Jana, superDuperCyberTechno
+# shellcheck disable=SC2012
ls -lah --group-directories-first | less
# 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
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
# remove the thumbnails
rm -rf .nthumbs
-echo -n "Press any key to exit..."
-read dummy
+printf "Press any key to exit..."
+read -r _