From b7f226cd4e5b4b3a0bf5fc09df5e13ba0d48d9e7 Mon Sep 17 00:00:00 2001 From: Simon Bruder Date: Fri, 14 Jun 2019 14:59:16 +0000 Subject: [PATCH] [zsh] use syntastic sugar for function that creates subshell --- home/.zshrc.local | 146 +++++++++++++++++++++------------------------- 1 file changed, 65 insertions(+), 81 deletions(-) diff --git a/home/.zshrc.local b/home/.zshrc.local index 8daadde..99c2b25 100644 --- a/home/.zshrc.local +++ b/home/.zshrc.local @@ -27,7 +27,7 @@ export PATH="$HOME/bin:$PATH" alias batt="upower -i /org/freedesktop/UPower/devices/battery_BAT0|grep percentage|awk '{print $2}'" ## Upload to transfer.sh -transfer() { +transfer() ( if [ $# -eq 0 ];then echo -e "No arguments specified. Usage:\necho transfer /tmp/test.md\ncat /tmp/test.md | transfer test.md" return 1 @@ -41,7 +41,7 @@ transfer() { fi cat $tmpfile rm -f $tmpfile -} +) ## Touchpad enabling/disabling @@ -59,22 +59,18 @@ function touchpad() { ## Terminal font -function tfont() { - ( - [ -z "$1" ] && font="Terminess Powerline" || font="$1" - [ -z "$2" ] && fontsize=18 || fontsize="$2" - echo -en "\033]710;xft:$font:pixelsize=$fontsize\007" - ) -} +function tfont() ( + [ -z "$1" ] && font="Terminess Powerline" || font="$1" + [ -z "$2" ] && fontsize=18 || fontsize="$2" + echo -en "\033]710;xft:$font:pixelsize=$fontsize\007" +) ## resync pulseaudio bluetooth connection -function btsync() { - ( - card=$(pactl list cards short|grep -E -o 'bluez_card.*[[:space:]]') - pacmd set-card-profile $card off - pacmd set-card-profile $card a2dp_sink - ) -} +function btsync() ( + card=$(pactl list cards short|grep -E -o 'bluez_card.*[[:space:]]') + pacmd set-card-profile $card off + pacmd set-card-profile $card a2dp_sink +) # Fancy stuff @@ -89,64 +85,58 @@ eval "$(dircolors -b $HOME/.dircolors)" alias dynamic-colors="~/.dynamic-colors/bin/dynamic-colors" ## Timer -function timer() { - ( - if [ -z "$1" ] || [ -z "$2" ]; then - echo "USAGE: $0 [u|f] TIME/DURATION" >&2 - return 1 - fi +function timer() ( + if [ -z "$1" ] || [ -z "$2" ]; then + echo "USAGE: $0 [u|f] TIME/DURATION" >&2 + return 1 + fi - if [ "$1" != "u" ] && [ "$1" != "f" ]; then - echo "Invalid mode “$1” supplied. Valid modes are: u|f" >&2 - return 2 - fi + if [ "$1" != "u" ] && [ "$1" != "f" ]; then + echo "Invalid mode “$1” supplied. Valid modes are: u|f" >&2 + return 2 + fi - [ "$1" = "u" ] && mode="until" - [ "$1" = "f" ] && mode="for" + [ "$1" = "u" ] && mode="until" + [ "$1" = "f" ] && mode="for" - gosleep --${mode} "$2" + gosleep --${mode} "$2" - if [ "$?" = 0 ]; then - echo "Press CTRL-C to stop the alarm…" >&2 - echo -en "\a" # highlight window - paplay ~/Dokumente/sound/ringtones/Bergentrückung.wav - else - echo "The sleep command failed. Please check the options." >&2 - return 3 - fi - ) -} + if [ "$?" = 0 ]; then + echo "Press CTRL-C to stop the alarm…" >&2 + echo -en "\a" # highlight window + paplay ~/Dokumente/sound/ringtones/Bergentrückung.wav + else + echo "The sleep command failed. Please check the options." >&2 + return 3 + fi +) ## Wallpaper switcher -function wp() { - ( - if [ -z "$1" ] || ([ "$1" = "rand" ] && [ -z "$2" ]); then - echo "USAGE: $0 rand|restore|default [path]" - return 1 - fi - if [ "$1" = "default" ];then - feh --bg-fill /usr/share/wallpapers/wallpaper.jpg - fi - if [ "$1" = "rand" ]; then - base="$HOME/Bilder/wallpaper" - rand=$(shuf -n1 -e $base/$2/*) - [ -z "$rand" ] || feh --bg-fill "$rand" - fi - if [ "$1" = "restore" ]; then - ~/.fehbg - fi - ) -} +function wp() ( + if [ -z "$1" ] || ([ "$1" = "rand" ] && [ -z "$2" ]); then + echo "USAGE: $0 rand|restore|default [path]" + return 1 + fi + if [ "$1" = "default" ];then + feh --bg-fill /usr/share/wallpapers/wallpaper.jpg + fi + if [ "$1" = "rand" ]; then + base="$HOME/Bilder/wallpaper" + rand=$(shuf -n1 -e $base/$2/*) + [ -z "$rand" ] || feh --bg-fill "$rand" + fi + if [ "$1" = "restore" ]; then + ~/.fehbg + fi +) -function currency() { - ( - amount=${1:-1} - fromcurrency=${2:-USD} - tocurrency=${3:-EUR} - rate=$(curl -s "https://api.exchangeratesapi.io/latest?base=$fromcurrency&symbols=$tocurrency"|jq ".rates.$tocurrency") - printf "$amount $fromcurrency: %.02f $tocurrency\n" $(($amount * $rate)) - ) -} +function currency() ( + amount=${1:-1} + fromcurrency=${2:-USD} + tocurrency=${3:-EUR} + rate=$(curl -s "https://api.exchangeratesapi.io/latest?base=$fromcurrency&symbols=$tocurrency"|jq ".rates.$tocurrency") + printf "$amount $fromcurrency: %.02f $tocurrency\n" $(($amount * $rate)) +) function urlencode() { 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 -function audacious-hack() { - ( - IFS=$'\n' - audacious $(/bin/ls -1 $1/**/*(@)|sort -Vd) - ) -} +function audacious-hack() ( + IFS=$'\n' + audacious $(/bin/ls -1 $1/**/*(@)|sort -Vd) +) # 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" } -function drone() { - ( +function drone() ( source ~/.drone-env ~/bin/drone $@ - ) -} +) function docker-ls() { DOCKER_LS_PASSWORD=$(pass show accounts/sbruderldap|head -n 1) ~/bin/docker-ls $@ @@ -228,10 +214,8 @@ function docker-rm() { } ## lexicon -function lecicon() { - ( +function lecicon() ( LEXICON_HENET_USERNAME="$(pass management/he|grep User|cut -d: -f2|tr -d ' ')" LEXICON_HENET_PASSWORD="$(pass management/he|head -n 1)" lexicon $@ - ) -} +)