You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

14 KiB

My .zshrc file

zshrc   @zsh

All posts in here will have the category set to zsh.

zshrc

This is my .zshrc; it will be used in many environments:

  • daily driver (gentoo box with kde)
  • blender box (gentoo box with no gui)
  • android box in termux
  • raspberry pi
  • mips box

Each environment has slightly different setups, which will be tangled to different files according to the function `org-tags-to-filenames', which checks the tags of the current headline and returns a list of corresponding filenames. For instance if the tags are daily and pi, the function returns '(".zshrc" ".zshrc.pi")

#+name:def-tag

  (setq tag-to-filenames-alist '(("daily" . ".zshrc")
                                 ("pi" . ".zshrc.pi")))
  (defun org-tags-to-filenames ()
    (remove nil (mapcar
                 (lambda (tag)
                   (cdr (assoc tag tag-to-filenames-alist)))
                 (org-split-string (car (last (org-heading-components))) ":"))))

Include   daily pi android

First, include a script that sets a number of confidential data (e.g. API keys and such)

  source ~/.config/confidential.sh
  # This defines a number of env variables:
  # ANDROID_A3=xxxx
  # ANDROID_BLU=xxx
  # ANDROID_IP=xxx.xxx.xxx.xxx
  # ifttt_apikey=xyz

Then, add helper directory to fpath

fpath=(~/clones/zshrc/ $fpath)

KDE helpers   daily

Define a number of KDE helpers.

  • kde-current-activity returns the id of the current activity
  • kde-current-activity-name returns the name of the current activity

The other two swap between build and src dirs on my local git checkout

   kde-current-activity () {
     qdbus org.kde.ActivityManager /ActivityManager/Activities org.kde.ActivityManager.Activities.CurrentActivity
   }

   kde-current-activity-name () {
     qdbus org.kde.ActivityManager /ActivityManager/Activities org.kde.ActivityManager.Activities.ActivityName `kde-current-activity`
   }

   kde-cd-build () {
       cd $(pwd | sed -e 's+scratch/src/kde+scratch/src/kde/build+')
   }

   kde-cd-src () {
       cd $(pwd | sed -e 's+scratch/src/kde/build+scratch/src/kde+')
   }
TODO Factor the KDE tree dir
TODO See if we can use zsh expansion instead of sed

Android helpers   daily

These are various helpers to drive my current Android phone when connected to the box.


  run-task () {
      adb shell am broadcast --user 0 -a net.dinglish.tasker.run_task -e task "$1"
  }

  android-remote-keyboard()
  {
      # should set this up in a tmux session
      adb -s $ANDROID_CUR shell ime set de.onyxbits.remotekeyboard/.RemoteKeyboardService;
      adb -s $ANDROID_CUR forward tcp:6023 tcp:2323;
      sleep 1;
      telnet 127.0.0.1 6023
  }
  android-remote-keyboard-wifi()
  {
      # should set this up in a tmux session
      adb -s $ANDROID_IP:5555 shell ime set de.onyxbits.remotekeyboard/.RemoteKeyboardService;
      adb -s $ANDROID_IP:5555 forward tcp:6023 tcp:2323;
      sleep 1;
      telnet 127.0.0.1 6023
  }


  android-remote-keyboard-blu()
  {
      # should set this up in a tmux session
      adb -s $ANDROID_BLU shell ime set de.onyxbits.remotekeyboard/.RemoteKeyboardService;
      adb -s $ANDROID_BLU forward tcp:6028 tcp:2323;
      sleep 1;
      telnet 127.0.0.1 6028
  }

  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()
{
 ffmpeg  -i http://192.168.0.41:8080/stream/video.mjpeg -map 0:v -pix_fmt yuv420p -f v4l2 /dev/video2
}
TODO The last bit is really pi material

Misc helpers   pi daily android

  • wttr.in
 wttr()
 {
     local location=Toronto
     [[ $(tput cols) -le 124 ]] && local narrow=n;
     curl -H "Accept-Language: ${LANG%_*}" wttr.in/"${1:-$location}?T$narrow"
 }
  • ifttt helper This sends the first argument as a maker event to IFTTT; the function defines some completions; is there a way to retrieve them from IFTTT?
    curl -X POST https://maker.ifttt.com/trigger/$1/with/key/$ifttt_apikey

Define the completions (by hand for the time being)

  #compdef ifttt

  _ifttt() {
      integer ret=1
      local -a args
      args+=(
          '1:event to be sent:(table-light table-light-off wu1 wu2 goodnight wind-down)'
      )
      _arguments $args[@] && ret=0
      return ret
  }

  _ifttt

Load the function

  autoload ifttt

konsole helpers   daily

   function set-terminal-title() {
       echo -en "\e]2;$@\a"
   }

   function get-konsole-title() {
       qdbus  "${KONSOLE_DBUS_SERVICE}" "${KONSOLE_DBUS_SESSION}" tabTitleFormat 0
   }

   function set-konsole-title() {
       qdbus  "${KONSOLE_DBUS_SERVICE}" "${KONSOLE_DBUS_SESSION}" setTabTitleFormat 0 $1
   }

   function set-konsole-pomo-title() {
       previous_title=$(get-konsole-title)
       set-konsole-title "pomodoro";
   }

   function restore-konsole-title() {
       set-konsole-title ${previous_title}
   }

emacs helpers   daily

  SOLARIZED="true"
  export EMACS="/home/jacopods/.emacs.d/emacsclient-activities"

  # Emacs stuff
  eca()
  {
      if [[ "$SSH_CONNECTION" != '' ]]; then
          EMACS_ARGUMENTS="-t"
      else
          EMACS_ARGUMENTS="-n"
      fi
      $EMACS $EMACS_ARGUMENTS $@
  }

  magit() {
      # TODO: add parameter just in case
      eca -e "(magit-status \"$(pwd)\")"
  }
  bindkey -s '^X^G' 'magit\n'

  agenda() {
      # TODO: add parameter just in case
      eca -e "(org-agenda-list)"
  }

  kill-emacs() {
      eca -e "(kill-emacs)"
  }

oh-my-zsh setup   daily pi android


  # Path to your oh-my-zsh configuration.
  ZSH=$HOME/.oh-my-zsh

  # Set name of the theme to load.
  # Look in ~/.oh-my-zsh/themes/
  ZSH_THEME="gentoo-wilder"

  # Set to this to use case-sensitive completion
  CASE_SENSITIVE="true"

  # Uncomment this to disable bi-weekly auto-update checks
  # DISABLE_AUTO_UPDATE="true"

  # Uncomment to change how often before auto-updates occur? (in days)
  # export UPDATE_ZSH_DAYS=13

  # Uncomment following line if you want to disable colors in ls
  # DISABLE_LS_COLORS="true"

  # Uncomment following line if you want to disable autosetting terminal title.
  DISABLE_AUTO_TITLE="true"

  # Uncomment following line if you want to disable command autocorrection
  # DISABLE_CORRECTION="true"

  # Uncomment following line if you want red dots to be displayed while waiting for completion
  # COMPLETION_WAITING_DOTS="true"

  # Uncomment following line if you want to disable marking untracked files under
  # VCS as dirty. This makes repository status check for large repositories much,
  # much faster.

  DISABLE_UNTRACKED_FILES_DIRTY="true"

  eval `dircolors ~/.dir_colors`

  setopt AUTO_PUSHD
  setopt PUSHD_MINUS
  setopt BASH_AUTO_LIST
  setopt RM_STAR_WAIT

  setopt AUTO_NAME_DIRS
  setopt CDABLE_VARS
  # Uncomment following line if you want to  shown in the command execution time stamp
  # in the history command output. The optional three formats: "mm/dd/yyyy"|"dd.mm.yyyy"|
  # yyyy-mm-dd
  # HIST_STAMPS="mm/dd/yyyy"

  # Which plugins would you like to load? (plugins can be found in ~/.oh-my-zsh/plugins/*)
  # Custom plugins may be added to ~/.oh-my-zsh/custom/plugins/
  # Example format: plugins=(rails git textmate ruby lighthouse)
  plugins=(git colorize wd history-substring-search)

  source $ZSH/oh-my-zsh.sh
  #source $ZSH/z.sh

  if [[ "$TERM" == "dumb" ]]
  then
    unsetopt zle
    unsetopt prompt_cr
    unsetopt prompt_subst
    unfunction precmd
    unfunction preexec
    PS1='$ '
  fi

  # try to use system colors for completion
  zstyle ':completion:*' list-colors "${(@s.:.)LS_COLORS}"

  # reset default oh-my-zsh matcher-list
  zstyle ':completion:*' matcher-list ''

  # smart: ignore parent directory when completing ../<TAB>

  zstyle ':completion:*:(cd|mv|cp):*' ignore-parents parent pwd
  zstyle ':completion:*:(rm|kill|diff):*' ignore-line yes

  autoload -U compinit && compinit

  # User configuration

  export PATH="/usr/local/bin:/usr/bin:/bin:/opt/bin:/usr/games/bin"

  # rationalise-dot; useful for cd ......./whatever
  rationalise-dot() {
    if [[ $LBUFFER = *.. ]]; then
      LBUFFER+=/..
    else
      LBUFFER+=.
    fi
  }
  zle -N rationalise-dot
  bindkey . rationalise-dot

  bindkey -s '^[(' '()^B'
  bindkey -s '^[{' '{}^B'
  # Make ctrl-Backspace work
  bindkey "\e[9;5~" backward-delete-word

  autoload zmv

TODO editor env variables   daily

This needs to be diff'd among the versions


  # editor stuff

  export EDITOR="$EMACS -n"
  export VISUAL=$EDITOR
  export GIT_EDITOR=$EMACS
  export SUDO_EDITOR=$EMACS

git helpers   daily

  git-create-pi-remote () {
      REPO_NAME=$(basename "`pwd`")
      source ~/scripts/git-init-pi4.sh "$REPO_NAME.git"
      git remote add π "git@pi4spoon.local:repos/$REPO_NAME.git"
  }

  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 () {
    git status -b | head -n 1 | awk {'print $3'}
  }
TODO Create a script to add an arbitrary remote

Aliases   pi android daily

  ## Aliases
  alias emacs="eca"
  alias e="eca"
  alias E=sudoedit
  alias mplayer="mpv"
  alias mpv="mpv --no-audio-display"
  alias mpv-pomodoro="mpv --script=~/scripts/mpv/auto-pomodoro.lua"
  alias top="urxvt -e htop &"
  alias mk="~/scripts/latex-mk $@"
  alias neofetch="~/clones/neofetch/neofetch --source ~/clones/neofetch/ascii/gentoo-one --separator ' ▏' --bold off --colors 13 12 5 1 12 12 |  sed -e 's/bree/Bree/g' | sed -e 's/2560x/2560×/'"
  alias dock="~/scripts/dock-a3.sh"
  alias xou="source /home/jacopods/scripts/setwacom.sh;/home/jacopods/clones/xournalpp/build/src/xournalpp"
  alias xmp="/home/jacopods/clones/xmp-cli/src/xmp"

Pomodoro helpers   daily pi android

  termdown_bin=/home/jacopods/.local/bin/termdown

  alias pomo="$termdown_bin 25m -aW -f 3x5 -c 180 -b -q 10 -s $@"
  alias heirloom="$termdown_bin -s 37m -aW -f 3x5 -c 300 -b -q 10 $@"
  alias pomodorino="$termdown_bin 14m -aW -f 3x5 -c 120 -b -q 10 -s $@"
  alias pomodoro=pomo
  alias pomo-break="$termdown_bin 5m -aW -f 3x5 -c 60 -b -q 10 $@"
  alias pomodorino-break="$termdown_bin 2m30s -aW -f 3x5 -c 45 -b -q 10 $@"

  alias kb=/home/jacopods/hack/kb/kb
  alias unlock-android='~/scripts/unlock-android.sh' #$(cat ~/scripts/unlock-android.gpg | gpg 2>/dev/null)'
  alias kbd-android=""
  alias K=/home/jacopods/tmp/keymaps/remap-keyboard

  alias quercus="falkon q.utoronto.ca"

  #alias portal="chromium portal.utoronto.ca"
  alias ls=' exa'
  alias sl=' exa' # a frequent typo
  alias c=' cd'
  alias cd=' cd'

  alias o="okular"

  alias skype="skypeforlinux"
  alias ta="tmux attach"
  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() {
    "$@" 2>/dev/null
  }

  alias git-init-coxeter="source ~/scripts/git-init-coxeter.sh"

  alias -s pdf='run-silent okular'
  alias -s djvu='run-silent okular'
  alias -s tex=emacs

  alias d.u='ssh dropbox.utoronto "~/dropbox.py"'

  alias -g C='| xclip'

  # 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%_}
      else
        mv -i $1 $1_
      fi
    else
      echo $0: \'$1\': no such file or directory
      return 1
    fi
  }


  hash -d Papers="/home/jacopods/work/Papers"
  hash -d Books="/home/jacopods/work/Books"
  hash -d kde="/scratch/kde/src"
  hash -d kde5="/scratch/kde/src5"
TODO Rearrange this bit