Some of the shell script fixes as per discussion (#389)

* Improved completion support for files with spaces

Filenames with spaces, both generally and for session names, will now
complete as expected.

* Misc shell script improvements

See discussion on:
1cca9e4b72
This commit is contained in:
Vidar Holen 2019-11-26 04:36:31 -08:00 committed by Mischievous Meerkat
parent e81efdb5e6
commit 1bf49c80e7
7 changed files with 30 additions and 35 deletions

View File

@ -8,7 +8,7 @@
_nnn ()
{
COMPREPLY=()
local IFS=$' \n'
local IFS=$'\n'
local cur=$2 prev=$3
local -a opts
opts=(
@ -37,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=( $(cd "$sessions_dir" && compgen -f -d -- "$cur") )
elif [[ $cur == -* ]]; then
COMPREPLY=( $(compgen -W "${opts[*]}" -- "$cur") )
else

View File

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

View File

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

View File

@ -24,8 +24,7 @@ fi
add_file ()
{
printf "%s" "$@" >> "$selection"
printf "\0" >> "$selection"
printf '%s\0' "$@" >> "$selection"
}
use_all ()
@ -57,7 +56,7 @@ elif [ "$resp" = "d" ]; then
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

View File

@ -18,18 +18,17 @@ if [ "$(cmd_exists fzy)" -eq "0" ]; 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

View File

@ -19,29 +19,29 @@
# 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

View File

@ -77,23 +77,16 @@ upload_connect_timeout="5"
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"
@ -169,8 +162,7 @@ function take_screenshot() {
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
@ -256,8 +248,13 @@ function refresh_access_token() {
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