[zsh] use syntastic sugar for function that creates subshell

This commit is contained in:
Simon Bruder 2019-06-14 14:59:16 +00:00
parent 9c352f8f40
commit b7f226cd4e
No known key found for this signature in database
GPG key ID: 6F03E0000CC5B62F

View file

@ -27,7 +27,7 @@ export PATH="$HOME/bin:$PATH"
alias batt="upower -i /org/freedesktop/UPower/devices/battery_BAT0|grep percentage|awk '{print $2}'" alias batt="upower -i /org/freedesktop/UPower/devices/battery_BAT0|grep percentage|awk '{print $2}'"
## Upload to transfer.sh ## Upload to transfer.sh
transfer() { transfer() (
if [ $# -eq 0 ];then if [ $# -eq 0 ];then
echo -e "No arguments specified. Usage:\necho transfer /tmp/test.md\ncat /tmp/test.md | transfer test.md" echo -e "No arguments specified. Usage:\necho transfer /tmp/test.md\ncat /tmp/test.md | transfer test.md"
return 1 return 1
@ -41,7 +41,7 @@ transfer() {
fi fi
cat $tmpfile cat $tmpfile
rm -f $tmpfile rm -f $tmpfile
} )
## Touchpad enabling/disabling ## Touchpad enabling/disabling
@ -59,22 +59,18 @@ function touchpad() {
## Terminal font ## Terminal font
function tfont() { function tfont() (
( [ -z "$1" ] && font="Terminess Powerline" || font="$1"
[ -z "$1" ] && font="Terminess Powerline" || font="$1" [ -z "$2" ] && fontsize=18 || fontsize="$2"
[ -z "$2" ] && fontsize=18 || fontsize="$2" echo -en "\033]710;xft:$font:pixelsize=$fontsize\007"
echo -en "\033]710;xft:$font:pixelsize=$fontsize\007" )
)
}
## resync pulseaudio bluetooth connection ## resync pulseaudio bluetooth connection
function btsync() { function btsync() (
( card=$(pactl list cards short|grep -E -o 'bluez_card.*[[:space:]]')
card=$(pactl list cards short|grep -E -o 'bluez_card.*[[:space:]]') pacmd set-card-profile $card off
pacmd set-card-profile $card off pacmd set-card-profile $card a2dp_sink
pacmd set-card-profile $card a2dp_sink )
)
}
# Fancy stuff # Fancy stuff
@ -89,64 +85,58 @@ eval "$(dircolors -b $HOME/.dircolors)"
alias dynamic-colors="~/.dynamic-colors/bin/dynamic-colors" alias dynamic-colors="~/.dynamic-colors/bin/dynamic-colors"
## Timer ## Timer
function timer() { function timer() (
( if [ -z "$1" ] || [ -z "$2" ]; then
if [ -z "$1" ] || [ -z "$2" ]; then echo "USAGE: $0 [u|f] TIME/DURATION" >&2
echo "USAGE: $0 [u|f] TIME/DURATION" >&2 return 1
return 1 fi
fi
if [ "$1" != "u" ] && [ "$1" != "f" ]; then if [ "$1" != "u" ] && [ "$1" != "f" ]; then
echo "Invalid mode “$1” supplied. Valid modes are: u|f" >&2 echo "Invalid mode “$1” supplied. Valid modes are: u|f" >&2
return 2 return 2
fi fi
[ "$1" = "u" ] && mode="until" [ "$1" = "u" ] && mode="until"
[ "$1" = "f" ] && mode="for" [ "$1" = "f" ] && mode="for"
gosleep --${mode} "$2" gosleep --${mode} "$2"
if [ "$?" = 0 ]; then if [ "$?" = 0 ]; then
echo "Press CTRL-C to stop the alarm…" >&2 echo "Press CTRL-C to stop the alarm…" >&2
echo -en "\a" # highlight window echo -en "\a" # highlight window
paplay ~/Dokumente/sound/ringtones/Bergentrückung.wav paplay ~/Dokumente/sound/ringtones/Bergentrückung.wav
else else
echo "The sleep command failed. Please check the options." >&2 echo "The sleep command failed. Please check the options." >&2
return 3 return 3
fi fi
) )
}
## Wallpaper switcher ## Wallpaper switcher
function wp() { function wp() (
( if [ -z "$1" ] || ([ "$1" = "rand" ] && [ -z "$2" ]); then
if [ -z "$1" ] || ([ "$1" = "rand" ] && [ -z "$2" ]); then echo "USAGE: $0 rand|restore|default [path]"
echo "USAGE: $0 rand|restore|default [path]" return 1
return 1 fi
fi if [ "$1" = "default" ];then
if [ "$1" = "default" ];then feh --bg-fill /usr/share/wallpapers/wallpaper.jpg
feh --bg-fill /usr/share/wallpapers/wallpaper.jpg fi
fi if [ "$1" = "rand" ]; then
if [ "$1" = "rand" ]; then base="$HOME/Bilder/wallpaper"
base="$HOME/Bilder/wallpaper" rand=$(shuf -n1 -e $base/$2/*)
rand=$(shuf -n1 -e $base/$2/*) [ -z "$rand" ] || feh --bg-fill "$rand"
[ -z "$rand" ] || feh --bg-fill "$rand" fi
fi if [ "$1" = "restore" ]; then
if [ "$1" = "restore" ]; then ~/.fehbg
~/.fehbg fi
fi )
)
}
function currency() { function currency() (
( amount=${1:-1}
amount=${1:-1} fromcurrency=${2:-USD}
fromcurrency=${2:-USD} tocurrency=${3:-EUR}
tocurrency=${3:-EUR} rate=$(curl -s "https://api.exchangeratesapi.io/latest?base=$fromcurrency&symbols=$tocurrency"|jq ".rates.$tocurrency")
rate=$(curl -s "https://api.exchangeratesapi.io/latest?base=$fromcurrency&symbols=$tocurrency"|jq ".rates.$tocurrency") printf "$amount $fromcurrency: %.02f $tocurrency\n" $(($amount * $rate))
printf "$amount $fromcurrency: %.02f $tocurrency\n" $(($amount * $rate)) )
)
}
function urlencode() { function urlencode() {
python3 -c 'import urllib.parse; print(urllib.parse.quote(open(0, "rb").read()))' python3 -c 'import urllib.parse; print(urllib.parse.quote(open(0, "rb").read()))'
@ -157,12 +147,10 @@ function mkvextract-all-attachments() {
} }
# Audacious does not support symlinks; hack around that # Audacious does not support symlinks; hack around that
function audacious-hack() { function audacious-hack() (
( IFS=$'\n'
IFS=$'\n' audacious $(/bin/ls -1 $1/**/*(@)|sort -Vd)
audacious $(/bin/ls -1 $1/**/*(@)|sort -Vd) )
)
}
# Program aliases/env # Program aliases/env
@ -212,12 +200,10 @@ function drone-add-s3() {
drone secret add --name aws_secret_access_key --data "$(pass show data/minio/personal|head -n 1)" "$1" drone secret add --name aws_secret_access_key --data "$(pass show data/minio/personal|head -n 1)" "$1"
} }
function drone() { function drone() (
(
source ~/.drone-env source ~/.drone-env
~/bin/drone $@ ~/bin/drone $@
) )
}
function docker-ls() { function docker-ls() {
DOCKER_LS_PASSWORD=$(pass show accounts/sbruderldap|head -n 1) ~/bin/docker-ls $@ DOCKER_LS_PASSWORD=$(pass show accounts/sbruderldap|head -n 1) ~/bin/docker-ls $@
@ -228,10 +214,8 @@ function docker-rm() {
} }
## lexicon ## lexicon
function lecicon() { function lecicon() (
(
LEXICON_HENET_USERNAME="$(pass management/he|grep User|cut -d: -f2|tr -d ' ')" LEXICON_HENET_USERNAME="$(pass management/he|grep User|cut -d: -f2|tr -d ' ')"
LEXICON_HENET_PASSWORD="$(pass management/he|head -n 1)" LEXICON_HENET_PASSWORD="$(pass management/he|head -n 1)"
lexicon $@ lexicon $@
) )
}