From 37f564018a9f34b7dfca4e7a8b23de1c58c8d680 Mon Sep 17 00:00:00 2001 From: Jacopo De Simoi Date: Sun, 17 Dec 2023 23:37:20 -0500 Subject: [PATCH] Declare functions with the ~function~ keyword --- zshrc.org | 105 +++++++++++++++++++++++++++--------------------------- 1 file changed, 52 insertions(+), 53 deletions(-) diff --git a/zshrc.org b/zshrc.org index be3a672..08b9dff 100644 --- a/zshrc.org +++ b/zshrc.org @@ -80,21 +80,21 @@ The other two swap between build and src dirs on my local git checkout #+begin_src sh :tangle kde-utils.sh #!/bin/zsh - kde-current-activity () { - qdbus >/dev/null && kactivities-cli --current-activity | awk {'print $2'} + function kde-current-activity () { + qdbus >/dev/null && kactivities-cli --current-activity | awk {'print $2'} } - kde-current-activity-name () { - qdbus >/dev/null && kactivities-cli --current-activity | awk {'print $3'} + function kde-current-activity-name () { + qdbus >/dev/null && kactivities-cli --current-activity | awk {'print $3'} } local kde_src_basedir="/scratch/src/kde" local kde_build_basedir="/scratch/src/kde/build" - kde-cd-build () { + function kde-cd-build () { cd ${PWD/$kde_src_basedir/$kde_build_basedir/} } - kde-cd-src () { + function kde-cd-src () { cd ${PWD/$kde_build_basedir/$kde_src_basedir/} } #+end_src @@ -102,13 +102,13 @@ The other two swap between build and src dirs on my local git checkout Send a message through OSD #+begin_src sh :tangle kde-utils.sh - kde-osd-message() { - qdbus org.freedesktop.Notifications /org/kde/osdService org.kde.osdService.showText alert $1 + function kde-osd-message() { + qdbus org.freedesktop.Notifications /org/kde/osdService org.kde.osdService.showText alert $1 } #+end_src #+begin_src sh -source ~/scripts/kde-utils.sh + source ~/scripts/kde-utils.sh #+end_src *** Do not litter :daily: #+begin_src sh @@ -124,11 +124,11 @@ source ~/scripts/kde-utils.sh These are various helpers to drive my current Android phone when connected to the box. #+begin_src sh - run-task () { + function run-task () { adb -s $ANDROID_CUR shell am broadcast --user 0 -a net.dinglish.tasker.run_task -e task "$1" } - android-remote-keyboard() + function android-remote-keyboard() { # should set this up in a tmux session adb -s $ANDROID_CUR shell ime set de.onyxbits.remotekeyboard/.RemoteKeyboardService; @@ -136,7 +136,7 @@ These are various helpers to drive my current Android phone when connected to th sleep 1; telnet 127.0.0.1 6023 } - android-remote-keyboard-wifi() + function android-remote-keyboard-wifi() { # should set this up in a tmux session adb -s $ANDROID_IP:5555 shell ime set de.onyxbits.remotekeyboard/.RemoteKeyboardService; @@ -145,8 +145,7 @@ These are various helpers to drive my current Android phone when connected to th telnet 127.0.0.1 6023 } - - android-remote-keyboard-blu() + function android-remote-keyboard-blu() { # should set this up in a tmux session adb -s $ANDROID_BLU shell ime set de.onyxbits.remotekeyboard/.RemoteKeyboardService; @@ -155,14 +154,14 @@ These are various helpers to drive my current Android phone when connected to th telnet 127.0.0.1 6028 } - setup-ipwebcam() + function setup-ipwebcam() { adb -s $ANDROID_BLU forward tcp:8097 tcp:8080 ffmpeg -i http://localhost:8097/video -map 0:v -pix_fmt yuv420p -f v4l2 /dev/video2 adb -s $ANDROID_BLU forward --remove tcp:8097 } - setup-pi-webcam() + function setup-pi-webcam() { ffmpeg -i http://192.168.0.41:8080/stream/video.mjpeg -map 0:v -pix_fmt yuv420p -f v4l2 /dev/video2 } @@ -171,7 +170,7 @@ These are various helpers to drive my current Android phone when connected to th This is an autoremote helper #+begin_src sh - autoremote () { + function autoremote () { curl "https://autoremotejoaomgcd.appspot.com/sendmessage?key=cVRJiHQtxGk:APA91bGQz3O3Z5RUkgvq6hXzlIiLvyC8ZVW5XlgIBhLO5Li3QwZausSkoaK48D3jyhFcJAi3pqB-T4fI45rICR0Rld9ikeTHMZp2m6w05FxaSvQcdofJ3blyxJGLT9B-6oGruLenXdrM&message=$(echo $1 | sed -e 's/ /\%20/g')&password=$(pass autoremote)" } #+end_src @@ -182,18 +181,18 @@ This is an autoremote helper This function checks if we are in a tmux session before executing the command; otherwise print an error and bail out #+begin_src sh - tmux-guard() - { - if [[ -v TMUX ]]; then - $@ - else - echo tmux-guard: ensure you are in a tmux session to run $@ - fi - } + function tmux-guard() + { + if [[ -v TMUX ]]; then + $@ + else + echo tmux-guard: ensure you are in a tmux session to run $@ + fi + } #+end_src - wttr.in #+begin_src sh - wttr() + function wttr() { local location=Toronto [[ $(tput cols) -le 124 ]] && local narrow=n; @@ -207,7 +206,7 @@ This is an autoremote helper BIG FAT WARNING: this needs to specify an actual file as a destination (similar to ln) adding a directory would not work. #+begin_src sh - bl() + function bl() { mv $1 $2 ln $2 $1 @@ -237,21 +236,21 @@ BIG FAT WARNING: this needs to specify an actual file as a destination } #+end_src *** shell helpers :daily:pi:android: -Underscore filename +This function is a poor-man eselect for configuration files it mv's + filename to filename_ or viceversa #+begin_src sh - # this function is a poor-man eselect for configuration files - # it mv's filename to filename_ or viceversa - uv() { - if [[ -f $1 ]]; then - if [[ ${1:(-1)} == '_' ]]; then - mv -i $1 ${1%_} + function uv() + { + if [[ -f $1 ]]; then + if [[ ${1:(-1)} == '_' ]]; then + mv -i $1 ${1%_} + else + mv -i $1 $1_ + fi else - mv -i $1 $1_ + echo $0: \'$1\': no such file or directory + return 1 fi - else - echo $0: \'$1\': no such file or directory - return 1 - fi } #+end_src *** emacs helpers :daily:pi: @@ -290,18 +289,18 @@ Underscore filename #+end_src **** mu4e + agenda :daily: #+begin_src sh - μ() { - eca -e "(mu4e)" - } + function μ() { + eca -e "(mu4e)" + } - agenda() { - # TODO: add parameter just in case - eca -e "(org-agenda-list)" - } + function agenda() { + # TODO: add parameter just in case + eca -e "(org-agenda-list)" + } - kill-emacs() { - eca -e "(kill-emacs)" - } + function kill-emacs() { + eca -e "(kill-emacs)" + } #+end_src *** oh-my-zsh setup :daily:pi:android: @@ -427,19 +426,19 @@ This needs to be diff'd among the versions #+end_src *** git helpers :daily: #+begin_src sh - git-create-pi-remote () { + function git-create-pi-remote () { REPO_NAME=$(basename "`pwd`") source ~/scripts/git-init-pi4.sh "$REPO_NAME.git" git remote add π "git@ssh.jacopods.xyz:repos/$REPO_NAME.git" } - git-create-thinkspoon-remote () { + function git-create-thinkspoon-remote () { REPO_NAME=$(basename "`pwd`") source ~/scripts/git-init-thinkspoon.sh "$REPO_NAME.git" git remote add thinkspoon "git@thinkspoon.local:repos/$REPO_NAME.git" } - git-current-branch () { + function git-current-branch () { git status -b | head -n 1 | awk {'print $3'} } #+end_src @@ -530,7 +529,7 @@ technique alias acroread="env WINEPREFIX=$HOME/.wine32 WINEARCH='win32' wine ~/.wine32/drive_c/Program\ Files/Adobe/Reader\ 11.0/Reader/AcroRd32.exe >/dev/null 2>/dev/null" - run-silent() { + function run-silent() { "$@" 2>/dev/null }