diff --git a/.common.sh b/.common.sh index c96019b5..b253c350 100644 --- a/.common.sh +++ b/.common.sh @@ -8,9 +8,6 @@ is-interactive() { [[ $- == *i* ]]; } is-root() { [[ "$UID" -eq 0 ]]; } is-ssh() { [[ "$SSH_CONNECTION" != '' ]]; } -load() { source "$DOTFILES/$1"; } -iload() { is-interactive && load "$1"; } - cache() { if [[ -z "$CACHE_DIR" ]]; then >&2 echo "Cache not set!" @@ -28,3 +25,4 @@ cache() { source $cache } +source "$DOTFILES/aliases" diff --git a/aliases b/aliases deleted file mode 100755 index ae0289d5..00000000 --- a/aliases +++ /dev/null @@ -1,291 +0,0 @@ -#!/usr/bin/env bash -## aliases -# -# Aliases that apply regardless of shell. Loaded from ./.${SHELL}/aliases -# -## Named Directories ######################################################### - -W=~/Dropbox/work -O=~/Dropbox/org -LOGS=/var/log -DL=~/Downloads - -if [[ "$OSTYPE" == linux* ]]; then - WWW=/var/www - DL=~/dl -fi - -# Editors -is-callable 'nvim' && alias vim=nvim -if is-callable 'emacs'; then - alias emacs='emacs -nw' - ediff() { e --eval "(ediff-files \"$1\" \"$2\")"; } -fi - - -## Fast folder navigation #################################################### - -# Must be separate from the main body; which otherwise interferes with z() -alias zz='cd -P $(project-root)' - -# fzf/fasd -is-callable 'z' && unalias z -if is-callable 'fasd' && is-callable 'fzf'; then - # MRU for directories; if blank, bring up fzf, otherwise use fasd - z() { - if (($# == 0)); then - cd -P "$(fasd_cd -l 2>&1 | fzf-tmux +s --tac -1 -e | sed 's/^[0-9,.]* *//')" - else - _last_z_args="$@" - fasd_cd -d "$@" - fi - } - - # Fuzzy find for $EDITOR if no args - v() { - if (($# == 0)); then - local t - t=$(fasd -lf "$*" |\ - fzf --tac +s -m -1 -e --query="$*") && \ - ${EDITOR[@]} ${FLAGS:-} "${t[@]}" - else - $EDITOR ${FLAGS:-} $* - fi - } - - # Jump to a parent directory - b() { - (($#>0)) && local args="-f$*" - local dir - dir=$({ - local _path=$PWD - while [[ -n "$_path" && "$_path" != "/" ]]; do - _path=$(dirname "$_path") - echo "$_path" - done - } | fzf +s -e $args --query="$*" | tail -1) && cd "$dir" - } - - # Emacs version of v - e() { - if pgrep Emacs 2>&1 >/dev/null; then - EDITOR=emacsclient FLAGS=-n v $@ - else - EDITOR=/Applications/Emacs.app/Contents/MacOS/Emacs v $@ & - fi - } -else - alias v='vim' - alias e='emacs' -fi - - -## 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' -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 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' - -case $OSTYPE in - "darwin"*) # is OSX - # Homebrew - alias br='brew' - alias bru='brew update && brew upgrade --all' - alias brc='brew cask' - alias codekit='open -a CodeKit' - ;; - "linux"*) - alias apt='sudo apt-get' - alias aptu='sudo apt-get update && sudo apt-get upgrade' - ;; - "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 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' -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" - } - ts() { - local session=$(tmux list-sessions -F "#{session_name}" | \ - fzf --query="$1" --select-1 --exit-0) && - tmux switch-client -t "$session" - } - 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 diff --git a/bash/aliases b/bash/aliases deleted file mode 100755 index ab39093a..00000000 --- a/bash/aliases +++ /dev/null @@ -1 +0,0 @@ -load aliases diff --git a/bash/aliases b/bash/aliases new file mode 120000 index 00000000..fb2a4b83 --- /dev/null +++ b/bash/aliases @@ -0,0 +1 @@ +../zsh/aliases \ No newline at end of file diff --git a/bash_profile b/bash_profile index 2f449b81..7939444c 100644 --- a/bash_profile +++ b/bash_profile @@ -26,12 +26,13 @@ export PATH ## Bash rcfiles ########################### +source ~/.bash/config + cache rbenv init - --no-rehash cache pyenv init - --no-rehash -is-interactive && cache fasd --init posix-alias bash-hook bash-ccomp bash-ccomp-install -is-callable tmuxifier && is-interactive && cache tmuxifier init - +if is-interactive; then + cache fasd --init posix-alias bash-hook bash-ccomp bash-ccomp-install + cache tmuxifier init - + source ~/.bash/prompt +fi -iload bash/fzf -load bash/aliases -load bash/config -iload bash/prompt diff --git a/zsh/aliases b/zsh/aliases index 155ca7ae..1c6a9d73 100644 --- a/zsh/aliases +++ b/zsh/aliases @@ -1,24 +1,248 @@ -#!/usr/bin/env zsh - -load aliases - +## aliases +# +# Aliases that apply regardless of shell. Loaded from ./.${SHELL}/aliases +# autoload -U zmv alias ?='since @$last' -# Fast directory navigation -if is-callable 'fasd' && is-callable 'fzf'; then - # TODO Jump to folder in project - alias ,='fzf -d "$(project-root)"' - alias /='fzf -f "$(project-root)"' -fi -# see functions/commacd -alias ,,,='cd ${$(find ~/Dropbox/work -maxdepth 2 -type d | fzf):-.}' -# alias ,/='fzf_project_root' - 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 + 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 + } + ediff() { e --eval "(ediff-files \"$1\" \"$2\")"; } +fi + + +## Fast folder navigation #################################################### +alias b="back" + +## 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' +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 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' + +case $OSTYPE in + "darwin"*) # is OSX + # Homebrew + alias br='brew' + alias bru='brew update && brew upgrade --all' + alias brc='brew cask' + alias codekit='open -a CodeKit' + ;; + "linux"*) + alias apt='sudo apt-get' + alias aptu='sudo apt-get update && sudo apt-get upgrade' + ;; + "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 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' +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" + } + # ts() { + # local session=$(tmux list-sessions -F "#{session_name}" | \ + # fzf --query="$1" --select-1 --exit-0) && + # tmux switch-client -t "$session" + # } + 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 diff --git a/zsh/completion b/zsh/completion index 6e9d3719..0e1e72f9 100644 --- a/zsh/completion +++ b/zsh/completion @@ -123,7 +123,6 @@ zstyle ':completion:*:(ssh|scp|rsync):*:hosts-ipaddr' ignored-patterns '^(<->.<- mycompdef() { is-callable "$1" && compdef ${@[2,-1]} } -mycompdef fasd _fasd_zsh_word_complete_d z=fasd mycompdef g _hub g=hub mycompdef o o=open mycompdef take take=mkdir diff --git a/zshenv b/zshenv index 64b16222..7caca755 100644 --- a/zshenv +++ b/zshenv @@ -17,20 +17,18 @@ if [[ -x /usr/libexec/path_helper ]]; then fi path=( $DOTFILES/{bin,scripts} - $DOTFILES/tmux/tmuxifier/bin + $HOME/.tmuxifier/bin $HOME/.{rb,py}env/{bin,shims} $HOME/bin $GOPATH/bin $ANDROID_HOME/platform-tools $ANDROID_HOME/tools - /Library/TeX/texbin $path ) -local FUNC_DIR="$DOTFILES/zsh/functions" fpath=( ~/.zsh/completions - "$FUNC_DIR" + "$DOTFILES/zsh/functions" $fpath ) diff --git a/zshrc b/zshrc index 533dc760..a1222a65 100644 --- a/zshrc +++ b/zshrc @@ -30,14 +30,16 @@ fi cache rbenv init - --no-rehash cache pyenv init - --no-rehash if is-interactive; then - is-callable fasd && cache fasd --init posix-alias zsh-hook zsh-ccomp zsh-ccomp-install zsh-wcomp zsh-wcomp-install - is-callable tmuxifier && cache tmuxifier init - + cache fasd --init posix-alias zsh-hook zsh-ccomp zsh-ccomp-install zsh-wcomp zsh-wcomp-install + cache tmuxifier init - fi -load zsh/config -iload zsh/keybinds -iload zsh/prompt -load zsh/aliases -iload zsh/completion +source ~/.zsh/config +if is-interactive; then + source ~/.zsh/keybinds + source ~/.zsh/prompt + source ~/.zsh/completion +fi +source ~/.zsh/aliases # Done!