#+TITLE: My .zshrc file #+AUTHOR: Jacopo De Simoi #+HUGO_BASE_DIR: /ssh:ssh.jacopods.xyz:gists/ #+HUGO_SECTION: zshrc #+OPTIONS: creator:t toc:nil * zshrc :@zsh: All posts in here will have the category set to /zsh/. ** zshrc :PROPERTIES: :EXPORT_FILE_NAME: zshrc-file :EXPORT_DATE: 2020-08-05 :EXPORT_HUGO_MENU: :menu "main" :END: 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 *** Include First, include a number of confidential data (such as API keys and such) #+BEGIN_SRC sh :tangle ".zshrc" 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 #+end_src *** KDE helpers #+BEGIN_SRC sh :tangle ".zshrc" 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+') } #+end_src *** Android helpers #+begin_src sh :tangle ".zshrc" 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_A3 shell ime set de.onyxbits.remotekeyboard/.RemoteKeyboardService; adb -s $ANDROID_A3 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 } #+end_src *** Misc helpers #+begin_src sh :tangle ".zshrc" wttr() { local location=Toronto [[ $(tput cols) -le 124 ]] && local narrow=n; curl -H "Accept-Language: ${LANG%_*}" wttr.in/"${1:-$location}?T$narrow" } #ifttt ifttt () { curl -X POST https://maker.ifttt.com/trigger/$1/with/key/$ifttt_apikey } #+end_src *** emacs helpers #+begin_src sh :tangle ".zshrc" SOLARIZED="true" # Emacs stuff eca() { if [[ "$SSH_CONNECTION" != '' ]]; then EMACS_ARGUMENTS="-t" else EMACS_ARGUMENTS="-n" fi /home/jacopods/.emacs.d/emacsclient-activities $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)" } #+end_src *** oh-my-zsh setup #+begin_src sh :tangle ".zshrc" # 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 ../ zstyle ':completion:*:(cd|mv|cp):*' ignore-parents parent pwd zstyle ':completion:*:(rm|kill|diff):*' ignore-line yes # User configuration #export PATH="/usr/local/bin:/usr/bin:/bin:/opt/bin:/usr/x86_64-pc-linux-gnu/gcc-bin/4.7.3:/usr/x86_64-pc-linux-gnu/gnat-gcc-bin/4.3:/usr/libexec/gnat-gcc/x86_64-pc-linux-gnu/4.3:/usr/games/bin:/usr/games/bin:/usr/games/bin:/usr/games/bin" 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 #+end_src *** editor env variables #+begin_src sh :tangle ".zshrc" # editor stuff #export ALTERNATE_EDITOR="/usr/bin/emacs" export EMACS="/home/jacopods/.emacs.d/emacsclient-activities -n" export EDITOR=$EMACS export VISUAL=$EMACS export GIT_EDITOR="/home/jacopods/.emacs.d/emacsclient-activities" export SUDO_EDITOR=$EMACS #+end_src *** git helpers #+begin_src sh :tangle ".zshrc" 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'} } #+end_src *** Aliases #+begin_src sh :tangle ".zshrc" ############################################################################## ## Aliases ############################################################################## alias emacs="eca" alias e="eca" alias E=sudoedit alias mplayer="mpv" alias mpv="mpv --no-audio-display" 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 4 12 5 3 12 6 | sed -e 's/bree/Bree/' | sed -e 's/2560x/2560×/'" alias dock="~/scripts/dock-a3.sh" #+end_src *** Pomodoro helpers #+begin_src sh :tangle ".zshrc" 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" #+END_SRC