helm/aliases

295 lines
8.5 KiB
Plaintext
Raw Normal View History

2015-12-22 23:23:09 -08:00
#!/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 sudoed
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 dk='docker'
2016-02-13 01:39:36 -08:00
alias dkm='docker-machine'
alias dkc='docker-compose'
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'
2016-01-06 21:57:17 -08:00
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