Improve compatibility with older versions of zsh (part 2)

This commit is contained in:
Henrik Lissner 2018-01-01 01:33:49 -05:00
parent f26719d7ac
commit 8e372241d8
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
24 changed files with 40 additions and 40 deletions

View file

@ -24,7 +24,7 @@ case $dir in west|south|north|east) ;;
exit 1 exit 1
esac esac
if [[ $leap ]]; then if [[ -n $leap ]]; then
# jump to monitor in direction # jump to monitor in direction
bspc monitor -f "$dir" bspc monitor -f "$dir"
else else

View file

@ -26,7 +26,7 @@ case $dir in west|south|north|east) ;;
exit 1 exit 1
esac esac
if [[ $leap ]]; then if [[ -n $leap ]]; then
# move window to monitor in direction # move window to monitor in direction
old_id=$(bspc query -N -n focused) old_id=$(bspc query -N -n focused)
if [[ $(bspc query -M -m "$dir") ]]; then if [[ $(bspc query -M -m "$dir") ]]; then
@ -38,7 +38,7 @@ else
old_id=$(bspc query -N -n focused) old_id=$(bspc query -N -n focused)
if bspc node -s "$dir.local"; then if bspc node -s "$dir.local"; then
bspc node -f "$old_id" bspc node -f "$old_id"
elif [[ $(bspc query -M -m "$dir") ]]; then elif [[ -n $(bspc query -M -m "$dir") ]]; then
bspc node -m "$dir" bspc node -m "$dir"
bspc node -f "$old_id" bspc node -f "$old_id"
fi fi

View file

@ -7,7 +7,7 @@ if command -v xdg-open >/dev/null; then
open=xdg-open open=xdg-open
elif command -v open >/dev/null; then elif command -v open >/dev/null; then
open=open open=open
elif [[ $BROWSER ]]; then elif [[ -n $BROWSER ]]; then
open=firefox open=firefox
else else
>&2 echo "No program to open urls with" >&2 echo "No program to open urls with"

View file

@ -7,7 +7,7 @@
# Get firefox's current url; requires "Hostname in title" plugin for firefox # Get firefox's current url; requires "Hostname in title" plugin for firefox
win=$(xdotool getactivewindow) win=$(xdotool getactivewindow)
if [[ $win ]]; then if [[ -n $win ]]; then
winname=$(xdotool getwindowname $win) winname=$(xdotool getwindowname $win)
if [[ $winname =~ " - Mozilla Firefox$" ]]; then if [[ $winname =~ " - Mozilla Firefox$" ]]; then
url=${winname% - Mozilla*} url=${winname% - Mozilla*}
@ -26,4 +26,4 @@ urxvt -name urxvt-fuzzy \
-e $SHELL \ -e $SHELL \
-c "fzf-pass $@ $url" -c "fzf-pass $@ $url"
[[ $win ]] && xdotool windowactivate $win [[ -n $win ]] && xdotool windowactivate $win

View file

@ -3,7 +3,7 @@ SCRID=urxvt-scratch
focused=$(xdotool getactivewindow) focused=$(xdotool getactivewindow)
scratch=$(xdotool search --onlyvisible --classname $SCRID) scratch=$(xdotool search --onlyvisible --classname $SCRID)
if [[ $scratch ]]; then if [[ -n $scratch ]]; then
if [[ $focused == $scratch ]]; then if [[ $focused == $scratch ]]; then
tmux kill-session -t scratch tmux kill-session -t scratch
else else

View file

@ -4,7 +4,7 @@ if (($# == 0)); then
data=$(amixer get Master) data=$(amixer get Master)
vol=$(echo "$data" | sed -n 's/^.*\[\([0-9]\+\)%.*$/\1/p' | uniq) vol=$(echo "$data" | sed -n 's/^.*\[\([0-9]\+\)%.*$/\1/p' | uniq)
state=$(echo "$data" | grep '\[on\]') state=$(echo "$data" | grep '\[on\]')
[[ $state ]] && echo $vol || echo 0 [[ -n $state ]] && echo $vol || echo 0
exit exit
fi fi

View file

@ -41,13 +41,13 @@ pac dosfstools ntfs-3g exfat-utils hfsprogs
# networking support # networking support
WIRELESS_DEV=$(ip link | grep wlp | awk '{print $2}'| sed 's/://' | sed '1!d') WIRELESS_DEV=$(ip link | grep wlp | awk '{print $2}'| sed 's/://' | sed '1!d')
if [[ $WIRELESS_DEV ]]; then if [[ -n $WIRELESS_DEV ]]; then
echo "==> ${WIRELESS_DEV} interface detected" echo "==> ${WIRELESS_DEV} interface detected"
pac iw wireless_tools wpa_actiond wpa_supplicant dialog netctl pac iw wireless_tools wpa_actiond wpa_supplicant dialog netctl
fi fi
WIRED_DEV=$(ip link | grep "en[sop]" | awk '{print $2}'| sed 's/://' | sed '1!d') WIRED_DEV=$(ip link | grep "en[sop]" | awk '{print $2}'| sed 's/://' | sed '1!d')
if [[ $WIRED_DEV ]]; then if [[ -n $WIRED_DEV ]]; then
echo "==> ${WIRED_DEV} interface detected" echo "==> ${WIRED_DEV} interface detected"
arch "systemctl enable dhcpcd@${WIRED_DEV}.service" arch "systemctl enable dhcpcd@${WIRED_DEV}.service"
fi fi

View file

@ -46,14 +46,14 @@ done
shift $((OPTIND-1)) shift $((OPTIND-1))
cmds=( optipng jpegtran gifsicle ) cmds=( optipng jpegtran gifsicle )
[[ $lossy ]] && cmds=( $cmds pngquant jpegoptim ) [[ -n $lossy ]] && cmds=( $cmds pngquant jpegoptim )
for cmd in ${cmds[@]}; do for cmd in ${cmds[@]}; do
if ! command -v $cmd >/dev/null; then if ! command -v $cmd >/dev/null; then
>&2 echo "$cmd isn't installed" >&2 echo "$cmd isn't installed"
error=1 error=1
fi fi
done done
if [[ $error ]]; then if [[ -n $error ]]; then
>&2 echo "There were errors, aborting" >&2 echo "There were errors, aborting"
exit 1 exit 1
fi fi
@ -65,14 +65,14 @@ for file in $@; do
pre_size=$(_filesize "$file") pre_size=$(_filesize "$file")
case ${file##*.} in case ${file##*.} in
png) png)
[[ $lossy ]] && pngquant $file [[ -n $lossy ]] && pngquant $file
optipng -nc -nb -o7 $file optipng -nc -nb -o7 $file
;; ;;
gif) gif)
gifsicle --batch --optimize=3 "$file" gifsicle --batch --optimize=3 "$file"
;; ;;
jpg|jpeg) jpg|jpeg)
[[ $lossy ]] && jpegoptim --max=90 "$file" [[ -n $lossy ]] && jpegoptim --max=90 "$file"
jpegtran -copy none -optimize -progressive -outfile "$file" "$file" jpegtran -copy none -optimize -progressive -outfile "$file" "$file"
;; ;;
*) *)

View file

@ -6,7 +6,7 @@ if [[ $1 == -w ]]; then
shift shift
fi fi
if [[ $wan ]]; then if [[ -n $wan ]]; then
dig +short myip.opendns.com @resolver1.opendns.com dig +short myip.opendns.com @resolver1.opendns.com
else else
IF=$(netstat -rn | awk '/^0.0.0.0/ {thif=substr($0,74,10); print thif;} /^default.*UG/ {thif=substr($0,65,10); print thif;}') IF=$(netstat -rn | awk '/^0.0.0.0/ {thif=substr($0,74,10); print thif;} /^default.*UG/ {thif=substr($0,65,10); print thif;}')

View file

@ -33,7 +33,7 @@ done
shift $((OPTIND-1)) shift $((OPTIND-1))
target="$1" target="$1"
if [[ $target ]]; then if [[ -n $target ]]; then
if [[ -t 0 ]]; then if [[ -t 0 ]]; then
pb | $bin $target pb | $bin $target
else else

10
bin/sup
View file

@ -65,17 +65,17 @@ delay() {
} }
screenshot() { screenshot() {
if [[ $doFullscreen ]]; then if [[ -n $doFullscreen ]]; then
cap_fullscreen cap_fullscreen
elif [[ $doSelection ]]; then elif [[ -n $doSelection ]]; then
cap_selection &>/dev/null cap_selection &>/dev/null
if ! [[ -s $local_file ]]; then if ! [[ -s $local_file ]]; then
$(rm "$local_file" 2> /dev/null) $(rm "$local_file" 2> /dev/null)
exit exit
fi fi
elif [[ $doWindow ]]; then elif [[ -n $doWindow ]]; then
cap_window cap_window
elif [[ $doURL ]]; then elif [[ -n $doURL ]]; then
local urlext local urlext
if [[ -f /usr/share/mime/globs ]]; then if [[ -f /usr/share/mime/globs ]]; then
urlext=$(curl -sf --head "${remoteURL}" | grep 'Content-Type: ' | head -1 | grep -Po '(?<=\ )[^\;]*') urlext=$(curl -sf --head "${remoteURL}" | grep 'Content-Type: ' | head -1 | grep -Po '(?<=\ )[^\;]*')
@ -147,7 +147,7 @@ upload() {
shortenerResult="$(curl -sf -F c=@- "${shortenerURL}" <<< "${uploadResult}")" shortenerResult="$(curl -sf -F c=@- "${shortenerURL}" <<< "${uploadResult}")"
fi fi
if [[ $shortener ]]; then if [[ -n $shortener ]]; then
finalResult="$shortenerResult" finalResult="$shortenerResult"
else else
finalResult="$uploadResult" finalResult="$uploadResult"

View file

@ -9,7 +9,7 @@ install() {
} }
update() { update() {
if [[ $LUAENV_ROOT ]]; then if [[ -n $LUAENV_ROOT ]]; then
cd $LUAENV_ROOT && git pull cd $LUAENV_ROOT && git pull
for ver in $LUAENV_ROOT/plugins/*(/); do for ver in $LUAENV_ROOT/plugins/*(/); do
cd $ver && git pull cd $ver && git pull

View file

@ -8,7 +8,7 @@ install() {
} }
update() { update() {
if [[ $NODENV_ROOT ]]; then if [[ -n $NODENV_ROOT ]]; then
cd $NODENV_ROOT && git pull cd $NODENV_ROOT && git pull
for ver in $NODENV_ROOT/plugins/*(/); do for ver in $NODENV_ROOT/plugins/*(/); do
cd $ver && git pull cd $ver && git pull

View file

@ -7,7 +7,7 @@ install() {
} }
update() { update() {
if [[ $PYENV_ROOT ]]; then if [[ -n $PYENV_ROOT ]]; then
cd $PYENV_ROOT && git pull cd $PYENV_ROOT && git pull
for ver in $PYENV_ROOT/plugins/*(/N); do for ver in $PYENV_ROOT/plugins/*(/N); do
cd $ver && git pull cd $ver && git pull

View file

@ -8,7 +8,7 @@ install() {
} }
update() { update() {
if [[ $RBENV_ROOT ]]; then if [[ -n $RBENV_ROOT ]]; then
cd $RBENV_ROOT && git pull cd $RBENV_ROOT && git pull
for ver in $RBENV_ROOT/plugins/*(/N); do for ver in $RBENV_ROOT/plugins/*(/N); do
cd $ver && git pull cd $ver && git pull

View file

@ -8,11 +8,11 @@ FZF_DEFAULT_OPTS="--prompt='open > ' $FZF_DEFAULT_OPTS"
case $OSTYPE in case $OSTYPE in
darwin*) darwin*)
cmd=$(find -L {,~}/Applications -iname '*.app' -maxdepth 2 -type d 2>/dev/null | sort -u | fzf) cmd=$(find -L {,~}/Applications -iname '*.app' -maxdepth 2 -type d 2>/dev/null | sort -u | fzf)
[[ $cmd ]] && open "$cmd" [[ -n $cmd ]] && open "$cmd"
;; ;;
linux*) linux*)
cmd=$(echo -n "$PATH" | xargs -d: -I{} -r -- find -L {} -maxdepth 1 -mindepth 1 -type f -executable -printf '%P\n' 2>/dev/null | sort -u | fzf) cmd=$(echo -n "$PATH" | xargs -d: -I{} -r -- find -L {} -maxdepth 1 -mindepth 1 -type f -executable -printf '%P\n' 2>/dev/null | sort -u | fzf)
if [[ ! $cmd ]]; then if [[ -z $cmd ]]; then
return return
elif [[ $cmd == fzf-* ]]; then elif [[ $cmd == fzf-* ]]; then
$cmd $cmd

View file

@ -4,6 +4,6 @@
pid=$(ps -ef | sed 1d | fzf -m | awk '{print $2}') pid=$(ps -ef | sed 1d | fzf -m | awk '{print $2}')
if [[ $pid ]]; then if [[ -n $pid ]]; then
xargs kill -${1:-9} <<< "$pid" xargs kill -${1:-9} <<< "$pid"
fi fi

View file

@ -8,4 +8,4 @@ set -e
song=$(mpc -f "%position%) %artist% - %title%" playlist) song=$(mpc -f "%position%) %artist% - %title%" playlist)
song_index=$(fzf --query="$1" --select-1 --exit-0 --prompt='play > ' <<<"$song" | sed -n 's/^\([0-9]\+\)).*/\1/p') song_index=$(fzf --query="$1" --select-1 --exit-0 --prompt='play > ' <<<"$song" | sed -n 's/^\([0-9]\+\)).*/\1/p')
[[ $song_index ]] && mpc -q play "$song_index" [[ -n $song_index ]] && mpc -q play "$song_index"

View file

@ -16,7 +16,7 @@ fi
url=$@ url=$@
LAST_ENTRY_FILE=/tmp/_upm LAST_ENTRY_FILE=/tmp/_upm
if [[ $resume && -f $LAST_ENTRY_FILE ]]; then if [[ -n $resume && -f $LAST_ENTRY_FILE ]]; then
entry="$(<$LAST_ENTRY_FILE)" entry="$(<$LAST_ENTRY_FILE)"
last=1 last=1
else else
@ -34,7 +34,7 @@ fi
echo "$entry" >/tmp/_upm echo "$entry" >/tmp/_upm
secrets="$(pass show "$entry")" secrets="$(pass show "$entry")"
if [[ $secrets ]]; then if [[ -n $secrets ]]; then
fields=$(awk -F': ' 'NR>1 && !/^otpauth:/ {print $1}' <<<"$secrets") fields=$(awk -F': ' 'NR>1 && !/^otpauth:/ {print $1}' <<<"$secrets")
field=$(printf "password\n%s\notp\n" "${fields[@]}" | fzf --prompt="pass ($entry) > ") field=$(printf "password\n%s\notp\n" "${fields[@]}" | fzf --prompt="pass ($entry) > ")
case $field in case $field in

View file

@ -34,7 +34,7 @@ case $(grep "$file" "$playlist_dir"/*-star.m3u) in
*/4-star.m3u:*) starn=4 ;; */4-star.m3u:*) starn=4 ;;
*/5-star.m3u:*) starn=5 ;; */5-star.m3u:*) starn=5 ;;
esac esac
if [[ $starn ]]; then if [[ -n $starn ]]; then
star_filled_icon="★" star_filled_icon="★"
star_empty_icon="☆" star_empty_icon="☆"
if [[ $OSTYPE == linux* ]]; then if [[ $OSTYPE == linux* ]]; then
@ -53,12 +53,12 @@ fi
case $OSTYPE in case $OSTYPE in
darwin*) darwin*)
[[ $rating ]] && rating="[$rating] " [[ -n $rating ]] && rating="[$rating] "
killall terminal-notifier killall terminal-notifier
terminal-notifier -title "$rating$title" -message "by $artist :: $album" -appIcon "/Applications/iTunes.app/Contents/Resources/iTunes.icns" & terminal-notifier -title "$rating$title" -message "by $artist :: $album" -appIcon "/Applications/iTunes.app/Contents/Resources/iTunes.icns" &
;; ;;
linux*) linux*)
[[ $rating ]] && rating="$rating<br />" [[ -n $rating ]] && rating="$rating<br />"
notify-send --urgency=low --icon="media-playback-start" --app-name="ncmpcpp" "$rating<b>$title</b>" "${artist}\n<i>${album}</i>" & notify-send --urgency=low --icon="media-playback-start" --app-name="ncmpcpp" "$rating<b>$title</b>" "${artist}\n<i>${album}</i>" &
;; ;;
esac >/dev/null 2>&1 esac >/dev/null 2>&1

View file

@ -9,7 +9,7 @@ install() {
debian) sudo apt-get install -y tmux ;; debian) sudo apt-get install -y tmux ;;
esac esac
[[ $TMUXIFIER ]] && _ensure_repo jimeh/tmuxifier $TMUXIFIER [[ -n $TMUXIFIER ]] && _ensure_repo jimeh/tmuxifier $TMUXIFIER
} }
update() { update() {

View file

@ -3,7 +3,7 @@ alias tmux='tmux -f "$TMUX_HOME/tmux.conf"'
alias ta='tmux attach' alias ta='tmux attach'
alias tl='tmux ls' alias tl='tmux ls'
if [[ $TMUX ]]; then # From inside tmux if [[ -n $TMUX ]]; then # From inside tmux
alias tf='tmux find-window' alias tf='tmux find-window'
# Detach all other clients to this session # Detach all other clients to this session
alias mine='tmux detach -a' alias mine='tmux detach -a'

View file

@ -3,5 +3,5 @@
id=$(echo $TMUX | sed 's/.*,//g') id=$(echo $TMUX | sed 's/.*,//g')
res=$(tmux ls -F '#{session_id}:#{session_name}' | grep -e "^\$$id:") res=$(tmux ls -F '#{session_id}:#{session_name}' | grep -e "^\$$id:")
[[ $res ]] || exit 1 [[ -z $res ]] && exit 1
echo "${res#\$$id:}" echo "${res#\$$id:}"

View file

@ -23,13 +23,13 @@ prompt_git_dirty() {
prompt_hook_precmd() { prompt_hook_precmd() {
vcs_info # get git info vcs_info # get git info
# Newline before prompt, except on init # Newline before prompt, except on init
[[ $PROMPT_DONE ]] && print ""; PROMPT_DONE=1 [[ -n $PROMPT_DONE ]] && print ""; PROMPT_DONE=1
} }
## Initialization ###################### ## Initialization ######################
prompt_init() { prompt_init() {
# prevent the extra space in the rprompt # prevent the extra space in the rprompt
[[ $EMACS ]] || ZLE_RPROMPT_INDENT=0 [[ -n $EMACS ]] || ZLE_RPROMPT_INDENT=0
# prevent percentage showing up # prevent percentage showing up
# if output doesn't end with a newline # if output doesn't end with a newline
export PROMPT_EOL_MARK= export PROMPT_EOL_MARK=
@ -59,7 +59,7 @@ prompt_init() {
zstyle ':vcs_info:git*' actionformats ' %b (%a)' zstyle ':vcs_info:git*' actionformats ' %b (%a)'
# show username@host if logged in through SSH # show username@host if logged in through SSH
if [[ $SSH_CONNECTION ]]; then if [[ -n $SSH_CONNECTION ]]; then
prompt_username='%m ' prompt_username='%m '
if [[ $(whoami) != hlissner ]]; then if [[ $(whoami) != hlissner ]]; then
prompt_username="%n.$prompt_username" prompt_username="%n.$prompt_username"