#!/usr/bin/env zsh autoload -U zmv alias ?='since @$last' zman() { PAGER="less -g -s '+/^ "$1"'" man zshall; } # Compilers, interpretors 'n builders alias rk="noglob ${aliases[rk]:-rake}" alias rkg="noglob ${aliases[rkg]:-rake -g}" ## Named Directories ######################################################### W=~/Dropbox/work DL=~/Downloads LOGS=/var/log # Editors is-callable 'nvim' && alias vim=nvim alias v='vim' if is-callable 'emacs'; then if [[ "$OSTYPE" == darwin* ]]; then alias emacs='emacs -nw' e() { # Emacs version of v if pgrep Emacs 2>&1 >/dev/null; then emacsclient -n $@ else /Applications/Emacs.app/Contents/MacOS/Emacs $@ & fi } else alias e='emacsclient -n' fi ediff() { e --eval "(ediff-files \"$1\" \"$2\")"; } fi ## Fast folder navigation #################################################### alias b="back" back() { # Jump to a parent directory dir=$({ _path=$PWD while [[ -n "$_path" && "$_path" != "/" ]]; do _path=$(dirname "$_path") echo "$_path" done } | grep -i "$*" | tail -1) && cd "$dir" } ## Redefined tools ########################################################### # Always enable colored `grep` output # Note: `GREP_OPTIONS="--color=auto"` is deprecated, hence the alias usage. alias grep='grep --color=auto' alias fgrep='fgrep --color=auto' alias egrep='egrep --color=auto' alias ssh='ssh -C' # Compression for all ssh connections alias ag='noglob ag' alias l="ls -l" alias ll="ls -1" alias la="ls -la" alias ln="ln -v" # Verbose ln alias wget='wget -c' # Resume dl if possible alias rsyncd='rsync -va --delete' # Hard sync two directories alias mkdir='mkdir -p' alias gurl='curl --compressed' alias ydl='youtube-dl' take() { mkdir "$1" && cd "$1"; } ## pbcopy/pbpaste, ls & open ################################################# # Detect which `ls` flavor is in use if ls --color > /dev/null 2>&1; then # GNU `ls` colorflag="--color" else # OS X `ls` colorflag="-G" fi alias ls="command ls -F ${colorflag}" case $OSTYPE in "darwin"*) # is OSX alias ls="ls -G" alias date="gdate" ;; "linux"*) alias open='xdg-open' alias ls="ls --color=auto" if (( $+commands[xclip] )); then alias pbcopy='xclip -selection clipboard -in' alias pbpaste='xclip -selection clipboard -out' elif (( $+commands[xsel] )); then alias pbcopy='xsel --clipboard --input' alias pbpaste='xsel --clipboard --output' fi ;; "cygwin"*) alias open='cygstart' alias pbcopy='tee > /dev/clipboard' alias pbpaste='cat /dev/clipboard' ;; esac o() { open ${*:-.}; } # By default, open cwd alias y='pbcopy' # Yank to clipboard alias yy='tr -d '\n' | pbcopy' # Strip newlines + copy to clipboard alias p='pbpaste' # Echo clipboard contents ## New tools ################################################################# alias q='exit' alias clr='clear' # Enable aliases to be sudo’ed alias sudo='sudo ' alias ..="cd .." alias ...="cd ../.." alias ....="cd ../../.." alias -- -="cd -" # Intuitive map function # For example, to list all directories that contain a certain file: find . -name # .gitattributes | map dirname alias map="xargs -n1" hex() { echo -n $@ | xxd -psdu; } # Canonical hex dump; some systems have this symlinked is-callable hd || alias hd="hexdump -C" # OS X has no `md5sum`, so use `md5` as a fallback is-callable md5sum || alias md5sum="md5" # OS X has no `sha1sum`, so use `shasum` as a fallback is-callable sha1sum || alias sha1sum="shasum" ## Remote resources # URL-encode strings alias urlencode='python -c "import sys, urllib as ul; print ul.quote_plus(sys.argv[1]);"' # find conflicted dropbox files alias findc="find . -iname '*conflicted*' -type f -exec echo '\"{}\" ' \;" # Send to sprunge.us alias bin="curl -s -F 'sprunge=<-' http://sprunge.us | head -n 1 | tr -d '\r\n ' | y" # IP addresses alias ip="dig +short myip.opendns.com @resolver1.opendns.com" alias localip="ipconfig getifaddr en0" alias ips="ifconfig -a | grep -o 'inet6\? \(addr:\)\?\s\?\(\(\([0-9]\+\.\)\{3\}[0-9]\+\)\|[a-fA-F0-9:]\+\)' | awk '{ sub(/inet6? (addr:)? ?/, \"\"); print }'" # View HTTP traffic alias sniff="sudo ngrep -d 'en0' -t '^(GET|POST) ' 'tcp and port 80'" alias httpdump="sudo tcpdump -i en0 -n -s 0 -w - | grep -a -o -E \"Host\: .*|GET \/.*\"" # Make URL REQUEST shortcuts for method in GET HEAD POST PUT DELETE TRACE OPTIONS; do alias "$method"="lwp-request -m '$method'" done ## Compilers, interpretors 'n builders ####################################### alias va='vagrant' alias py='python' alias pye='pyenv' alias rb='ruby' alias rbe='rbenv' alias rdb='pry -r' alias bu='bundle' alias bue='bundle exec' alias bui='bundle install -path vendor' alias ans='ansible' alias ansp='ansible-playbook' alias fabg='noglob fab -f ~/.dotfiles/ansible/fabfile.py' alias rk='rake' alias rkg='rake -g' alias mk='make' alias exe='exercism' alias c11='clang++ -std=c++11' alias dk='docker' alias dkm='docker-machine' alias dkc='docker-compose' alias dki='eval $(docker-machine env)' case $OSTYPE in "darwin"*) # is OSX # Homebrew alias br='brew' alias bru='brew update && brew upgrade --all && brew cleanup' alias brc='brew cask' alias codekit='open -a CodeKit' ;; "linux"*) is-callable apt-get && \ alias apt='sudo apt-get' && \ alias aptu'sudo apt-get update && sudo apt-get upgrade' is-callable pacman && \ alias pac='sudo pacman' && \ alias pacu='sudo pacman -Syu' ;; "cygwin"*) ;; esac ## GIT ####################################################################### is-callable 'hub' && alias git='hub' g() { [ $# -eq 0 ] && git status --short || git $*; } alias gbr='git browse' alias gi='git init' alias gs='git status' alias gsu='git submodule' alias gsq='git rebase -i origin/master' alias gco='git checkout' alias gcoo='git checkout --' alias gc='git commit' alias gcl='git clone' alias gcm='noglob git commit -m' alias gcma='noglob git commit --amend -m' alias gcf='noglob git commit --fixup' alias gd='git diff' alias gp='git push' alias gpb='git push origin' alias gpt='git push --follow-tags' alias gpl='git pull' alias ga='git add' alias gau='git add -u' alias gb='git branch' alias gbd='git branch -D' alias gap='git add --patch' alias gr='git reset HEAD' alias gt='git tag' alias gtd='git tag -d' alias gta='git tag -a' alias gl='git log --oneline --decorate' alias gls='git ls-files' # transmission-remote if is-callable 'transmission-remote'; then alias bt='transmission-remote server' alias bt-clear='bt -t all -r' alias btl='transmission-list server' fi # Tmux if is-callable 'tmux'; then alias ta='tmux attach' alias tl='tmux ls' if [[ -n $TMUX ]]; then alias t='tmux' alias tf='tmux find-window' # Detach all other clients to this session alias mine='tmux detach -a' # Send command to other tmux window tt() { tmux send-keys -t .+ C-u && tmux set-buffer "$*" && tmux paste-buffer -t .+ && tmux send-keys -t .+ Enter; } # Create new session (from inside one) tn() { local name="${1:-`basename $PWD`}" TMUX= tmux new-session -d -s "$name" tmux switch-client -t "$name" tmux display-message "Session #S created" } else t() { if (( $# > 0 )); then tmux $@ || tmux attach -t main else tmux new -s main; fi } # Start grouped session so I can be in two different windows in one session tdup() { tmux new-session -t "${1:-`tmux display-message -p '#S'`}"; } fi fi