# ############################################################################# # zsh # ############################################################################# autoload -Uz compinit promptinit fpath=(~/.zsh/completions $fpath) compinit -u compctl -K tln muxa compdef mosh=ssh promptinit HISTFILE=~/.zshistory HISTSIZE=1000 SAVEHIST=1000 setopt completealiases setopt no_multios bindkey -v bindkey '^R' history-incremental-search-backward bindkey '^A' vi-beginning-of-line bindkey '^E' vi-end-of-line zstyle ':completion:*' completer _complete _ignored zstyle ':completion:*' menu select=2 zstyle :compinstall filename '~/.zshrc' zstyle '*' hosts # do not use /etc/hosts ZDIR=~/.zsh/ _HOST_TYPE=$(uname) # ############################################################################# # ssh-agent # ############################################################################# SSH_ENV="$HOME/.ssh/environment" function start_agent { echo "Initialising new SSH agent..." /usr/bin/ssh-agent | sed 's/^echo/#echo/' > "${SSH_ENV}" echo succeeded chmod 600 "${SSH_ENV}" . "${SSH_ENV}" > /dev/null /usr/bin/ssh-add; } if [ -f "${SSH_ENV}" ]; then . "${SSH_ENV}" > /dev/null ps -ef | grep ${SSH_AGENT_PID} | grep ssh-agent$ > /dev/null || { start_agent; } else start_agent; fi # ############################################################################# # functions # ############################################################################# diff () { if [[ -x $(which colordiff 2>/dev/null) ]]; then colordiff "$@" else command diff "$@" fi } irb () { which pry &>/dev/null if [[ $? -eq 0 ]]; then pry "$@" else command irb "$@" fi } lsof_kill () { lsof $1 | grep -v COMMAND | cut -d " " -f 2- | strips | cut -d " " -f 1 | xargs kill } tln () { reply=( $(tmux list-sessions | cut -d: -f1) ) } watch_pdflatex () { echo $1 ls $@ | entr pdflatex --interaction=batchmode $1 echo "tell application \"Preview\" to activate" | osascript - echo "tell application \"iTerm2\" to activate" | osascript - } pdfprevfile () { pdftoppm $1 -f 1 -l 1 -singlefile -png } getcert () { openssl s_client -showcerts -connect $1 $2 } on_gcloud () { curl metadata.google.internal -i --connect-timeout 0.25 &>/dev/null if [[ $? -eq 0 ]]; then echo "yes" else echo "no" fi } on_aws () { if [[ $(hostname -f | cut -d. -f 2) == "ec2" ]]; then echo "yes" else echo "no" fi } function chpwd { if [[ -e $ZDIR/functions ]] { source ~/.zsh/functions/rtab.zsh if [[ $(pwd) == $HOME ]]; then psvar[1]=$(print -P %~) else psvar[1]=$(rtab) fi } else { psvar[1]=$(print -P %~) } } chpwd zstyle ':prompt:rtab' fish yes zstyle ':prompt:rtab' nameddirs yes # ############################################################################# # exports # ############################################################################# umask 0077 export PATH=~/.local/bin:~/.local/sbin:$PATH export PATH=/usr/sbin:/usr/local/bin:/usr/local/sbin:$PATH if [[ -d ~/nlp_scripts ]]; then export PATH=~/nlp_scripts:$PATH fi if [[ -d /usr/lib/colorgcc/bin ]]; then PATH=/usr/lib/colorgcc/bin:$PATH fi which R &>/dev/null if [[ $? == 0 ]]; then export R_LIBS_USER=$HOME/.R fi if [[ -x $(which nvim) ]]; then export EDITOR='nvim -p' alias qmv='qmv -envim -fdo' else export EDITOR='vim -p' alias qmv='qmv -evim -fdo' fi export LC_ALL=en_US.UTF-8 export LANG=en_US.UTF-8 export LANGUAGE=en_US.UTF-8 export RUBYOPT=-Ku export PATH=~/.local/lib/ruby/bin:$PATH export GEM_HOME=$HOME/.local/lib/ruby/ export GEM_PATH=$HOME/.local/lib/ruby/:$GEM_PATH export PYTHONPATH=$PYTHONPATH:~/.local/lib/python/site-packages:~/.local/lib/python3/site-packages export PATH=~/.local/lib/python/site-packages:$PATH export PATH=~/.local/lib/node/bin:$PATH export TEXMFHOME='~/.texmf' export CFLAGS="-march=native -mtune=native" export CXXFLAGS="$CFLAGS" export CCACHE_PATH=/usr/bin case $_HOST_TYPE in Linux) case `whoami` in root) export PATH=/home/pks/.local/bin:$PATH ;; esac ;; esac # ############################################################################# # terminal # ############################################################################# case $TERM in screen-256color) ;; *) TERM=xterm-256color ;; esac stty -ixon # enable mapping of C-s in vim.. # ############################################################################# # prompt # ############################################################################# autoload -U colors && colors # possible colors: black, white, green, cyan, red, yellow, magenta case `hostname` in bryant|barkley|bogues*|curry*|durant*|iverson*|jordan*|ming*|nowitzki*|oneal*|robinson*) HOSTCOLOR_BG=magenta HOSTCOLOR_FG=black ;; *.uberspace.de) HOSTCOLOR_BG=blue HOSTCOLOR_FG=black ;; *) HOSTCOLOR_BG=black HOSTCOLOR_FG=white ;; esac # google cloud if [[ $(on_gcloud) == "yes" ]]; then HOSTCOLOR_BG=cyan HOSTCOLOR_FG=white alias tmux="tmux -f ~/.tmux.gcloud.conf" fi # aws #if [[ $(on_aws) == "yes" ]]; then # HOSTCOLOR_BG=yellow # HOSTCOLOR_FG=black # alias tmux="tmux -f ~/.tmux.aws.conf" #fi function chpwd { if [[ -e $ZDIR/functions ]] { source ~/.zsh/functions/rtab.zsh if [[ $(pwd) == $HOME ]]; then psvar[1]=$(print -P %~) else psvar[1]=$(rtab) fi } else { psvar[1]=$(print -P %~) } } chpwd zstyle ':prompt:rtab' fish yes zstyle ':prompt:rtab' nameddirs yes case `whoami` in root) PROMPT="%{$bg[red]%}%{$fg[black]%}%m:%1v#%{$reset_color%} " ;; *) PROMPT="%{$bg[$HOSTCOLOR_BG]%}%{$fg[$HOSTCOLOR_FG]%}%m%{$reset_color%}:%1v> " ;; esac case $TERM in *256color*) precmd () {print -Pn "\e]0;%n@%m%~\a"} preexec () {print -Pn "\e]0;%n@%m%~ -- $1\a"} ;; esac # ############################################################################# # aliases # ############################################################################# case $_HOST_TYPE in Darwin) alias ls='ls -h -G' export LD_LIBRARY_PATH=$HOME/.local/lib:$LD_LIBRARY_PATH alias afk="/System/Library/CoreServices/Menu\ Extras/User.menu/Contents/Resources/CGSession -suspend" if [[ -d /Library/TeX/texbin/ ]]; then export PATH=/Library/TeX/texbin:$PATH fi ;; Linux) alias ls='ls -h --color=auto' ;; esac alias l='ls' alias la='ls -lA' alias ll='ls -l' alias lla='ls -A' alias lsc='ls -1 | wc -l' alias less='less -R' alias lh='ls --color=always -lasth | less' alias equery='sudo equery -N' alias feh='feh -F' alias git='git -c color.status=always' alias grep='grep --color=auto' alias pdf='zathura' alias py='bpython' alias vi=$EDITOR alias jsonlint='python -mjson.tool' alias jpegtran='jpegtran -trim' alias pdfmerge='gs -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=/tmp/merged.pdf -dBATCH' alias thumb='convert -resize 200x200' alias radio='mocp ~/.moc/radio.m3u' alias muxn='tmux new -s' alias muxl='tmux list-sessions' alias muxa='tmux attach -t' alias easy_install_home='easy_install --install-dir=$HOME/.local/lib/python/site-packages' alias pip_home='pip install -t $HOME/.local/' alias npm_install_home='npm install -g --prefix ~/.local/lib/node' alias castnow_home='castnow --myip 192.168.0.100 --address 192.168.0.4' alias my_ip='echo "$(curl 'https://api.ipify.org' 2>/dev/null)"' alias t_timeline='while true; do clear; t timeline -n 16 -C icon; sleep 600; done' if [[ $_HOST_TYPE == "Linux" ]]; then alias cal='while true; do clear; echo; khal calendar; sleep 600; done' alias wifi_list='sudo iwlist wlan0 scan' alias always_on='xset dpms 0 0 0' if [[ $(hostname) == "bogues" ]]; then alias vgaoff='xrandr --output VGA1 --off && xrandr --output LVDS1 --mode 1024x768' alias vgaclone='xrandr --output VGA1 --mode 1024x768' elif [[ $(hostname) == "barkley" ]]; then alias vgaoff='xrandr --output DP2 --off && xrandr --output eDP1 --mode 1920x1080' alias vgaclone='xrandr --output DP2 --mode 1280x1024' alias presentation='xrandr --output eDP1 --mode 1024x768 && xrandr --output DP2 --mode 1024x768' alias presentation-off='xrandr --output DP2 --off && xrandr --output eDP1 --mode 1920x1080' fi alias vgaext='xrandr --output VGA1 --mode 1024x768 --left-of LVDS1 --rotate right' alias vga21='xrandr --output VGA1 --mode 1600x1200 --rate 60 --rotate right && xrandr --output LVDS1 --off' alias vga22w='xrandr --output VGA1 --mode 1680x1050 --rate 60 --rotate left && xrandr --output LVDS1 --off' alias reboot='sudo shutdown -r now' alias halt='sudo shutdown -h now' alias lp2p='/usr/bin/lp -o sides=two-sided-long-edge' alias lp4p='/usr/bin/lp -o sides=two-sided-short-edge -o number-up=2' alias lp8p='/usr/bin/lp -o sides=two-sided-short-edge -o number-up=4 -o landscape' alias lpimg='/usr/bin/lp -o fit-to-page' fi