shellcheck fixes

This commit is contained in:
Arun Prakash Jana 2019-11-22 02:14:25 +05:30
parent ee2dcb1de7
commit 1cca9e4b72
No known key found for this signature in database
GPG Key ID: A75979F35C080412
36 changed files with 187 additions and 170 deletions

View 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

View 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
}

View 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
}

View File

@ -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'

View 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 () {

View File

@ -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

View File

@ -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

View File

@ -16,21 +16,22 @@
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

View File

@ -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 _

View File

@ -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") ;;

View File

@ -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

View File

@ -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*)

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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 _

View File

@ -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 _

View File

@ -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

View File

@ -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"

View File

@ -10,14 +10,14 @@
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"

View File

@ -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

View File

@ -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

View File

@ -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 _

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -13,20 +13,21 @@
# 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

View File

@ -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"

View File

@ -16,5 +16,5 @@ if command -v sxiv >/dev/null 2>&1; then
fi
else
echo "sxiv missing"
read dummy
read -r _
fi

View File

@ -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

View File

@ -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

View File

@ -5,4 +5,5 @@
# Shell: POSIX compliant
# Author: Arun Prakash Jana, superDuperCyberTechno
# shellcheck disable=SC2012
ls -lah --group-directories-first | less

View File

@ -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

View File

@ -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 _