_nnn ()
{
COMPREPLY=()
- local IFS=$' \n'
+ local IFS=$'\n'
local cur=$2 prev=$3
local -a opts
opts=(
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=( $(cd "$sessions_dir" && compgen -f -d -- "$cur") )
elif [[ $cur == -* ]]; then
COMPREPLY=( $(compgen -W "${opts[*]}" -- "$cur") )
else
n ()
{
# Block nesting of nnn in subshells
- if [ "$((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
+ 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
n ()
{
# Block nesting of nnn in subshells
- if [ "$((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
+ 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
add_file ()
{
- printf "%s" "$@" >> "$selection"
- printf "\0" >> "$selection"
+ printf '%s\0' "$@" >> "$selection"
}
use_all ()
use_all
"$dnd" "$all" "$PWD/"* &
elif [ "$resp" = "r" ]; then
- printf > "$selection"
+ true > "$selection"
"$dnd" --print-path --target | while read -r f
do
if printf "%s" "$f" | grep '^\(https\?\|ftps\?\|s\?ftp\):\/\/' ; then
sel=$($fd | fzy)
elif [ "$(cmd_exists fzf)" -eq "0" ]; then
- sel=$(fzf --print0)
+ sel=$(fzf)
else
exit 1
fi
-if ! [ -z "$sel" ]; then
- case "$(file -bi "$sel")" in
- *directory*) ;;
- *) sel=$(dirname "$sel") ;;
- esac
+if [ -n "$sel" ]; then
+ if ! [ -d "$sel" ]; then
+ sel=$(dirname "$sel")
+ fi
- # Remove "./" prefix
- sel="$(echo "$sel" | cut -c 3-)"
+ # Remove "./" prefix if it exists
+ sel="${sel#./}"
nnn_cd "$PWD/$sel"
fi
# Author: Arun Prakash Jana
EBOOK_ID=
-DIR=${XDG_CACHE_HOME:-$HOME/.cache}/nnn/gutenbooks/"$EBOOK_ID"
+DIR="${XDG_CACHE_HOME:-$HOME/.cache}/nnn/gutenbooks/$EBOOK_ID"
BROWSE_LINK="http://www.gutenberg.org/ebooks/search/?sort_order=downloads"
BROWSER=w3m
READER=
-if [ ! -z "$EBOOK_ID" ]; then
+if [ -n "$EBOOK_ID" ]; then
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 [ -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
upload_timeout="120"
upload_retries="1"
+# shellcheck disable=SC2034
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="screenshot_${mode}_command"
cmd=${!cmd//\%img/${1}}
- shot_err="$(${cmd} &>/dev/null)" #takes a screenshot with selection
- if ! [ -z "$shot_err" ]; then
+ if ! shot_err="$(${cmd} &>/dev/null)"; then #takes a screenshot with selection
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
check_oauth2_client_secrets
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 ! [ -z "$response" ]; then
+ if ! 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}"
+ )"; then
# curl failed
handle_upload_error "${response}" "${token_url}"
exit 1