-
Notifications
You must be signed in to change notification settings - Fork 0
/
bash_aliases
173 lines (142 loc) · 6.36 KB
/
bash_aliases
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#!/bin/bash
# Color aliases
RED="\033[0;31m"
YELLOW="\033[0;33m"
GREEN="\033[2;32m"
NORMAL="\033[0m"
BLUE="\033[2;34m"
BOLDCYAN="\033[1;36m"
# Make sure mac picks up git completion/prompts
if [ -a /Applications/Xcode.app/Contents/Developer/usr/share/git-core/git-completion.bash ]; then
source /Applications/Xcode.app/Contents/Developer/usr/share/git-core/git-completion.bash
source /Applications/Xcode.app/Contents/Developer/usr/share/git-core/git-prompt.sh
fi
# mac directory highlighting for ls commands
export CLICOLOR=1
export LSCOLORS=ExFxCxDxBxegedabagacad
# PS1 is prompt format - add git and set correct colors
export PS1="${debian_chroot:+($debian_chroot)}\[$BOLDCYAN\]\w\[$NORMAL\]\$(__git_ps1 \"\[$YELLOW\](%s)\[$NORMAL\]\")\$ "
# if under jhbuild, show it
if [ -n "$UNDER_JHBUILD" ]; then
export PS1="\[$BLUE\][jh]\[$NORMAL\]$PS1"
fi
# command just before prompt is shown
export PROMPT_COMMAND=""
# enable git showing when working directory is dirty
export GIT_PS1_SHOWDIRTYSTATE=1
# Git aliases
alias gst='git status'
alias gl='git pull'
alias gp='git push'
alias gd='git diff'
alias gau='git add --update'
alias gc='git commit -v'
alias gca='git commit -v -a'
alias gb='git branch'
alias gba='git branch -a'
alias gco='git checkout'
alias gcob='git checkout -b'
alias gcot='git checkout -t'
alias gcotb='git checkout --track -b'
alias glog='git log'
alias glogp='git log --pretty=format:"%h %s" --graph'
alias ggrep='git grep'
# cd aliases
alias ..='cd ..'
alias ...='cd ../..'
alias ....='cd ../../..'
alias .....='cd ../../../..'
alias ......='cd ../../../../..'
# some more ls aliases
alias ll='ls -alF'
alias la='ls -A'
alias l='ls -CF'
# Human-readable file sizes
alias du='du -h'
alias df='df -h'
# Alias tmux
alias t='tmux -2'
# Show status of a dd command from adifferent terminal
alias ddst='ps -ef | grep dd | grep sudo | awk "{print \$2}" | xargs sudo kill -USR1'
# Add an "alert" alias for long running commands. Use like so:
# sleep 10; alert
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'
# enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
alias ls='ls --color=auto'
alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
fi
# Alias some commonly used functions
function psgrep() { ps axuf | grep -v grep | grep "$@" -i --color=auto; }
function fname() { find . -iname "*$@*"; }
# Alias creating a sublime project from the command line
function sublimeproject() {
~/.update_project.py $@
}
# don't put duplicate lines or lines starting with space in the history.
# See bash(1) for more options
HISTCONTROL=ignoreboth
# append to the history file, don't overwrite it
shopt -s histappend
# Automatically add completion for all aliases to commands having completion functions
function alias_completion {
local namespace="alias_completion"
# parse function based completion definitions, where capture group 2 => function and 3 => trigger
local compl_regex='complete( +[^ ]+)* -F ([^ ]+) ("[^"]+"|[^ ]+)'
# parse alias definitions, where capture group 1 => trigger, 2 => command, 3 => command arguments
local alias_regex="alias ([^=]+)='(\"[^\"]+\"|[^ ]+)(( +[^ ]+)*)'"
# create array of function completion triggers, keeping multi-word triggers together
eval "local completions=($(complete -p | sed -Ene "/$compl_regex/s//'\3'/p"))"
(( ${#completions[@]} == 0 )) && return 0
# create temporary file for wrapper functions and completions
rm -f "/tmp/${namespace}-*.tmp" # preliminary cleanup
local tmp_file="$(mktemp "/tmp/${namespace}-${RANDOM}XXX.tmp")" || return 1
# read in "<alias> '<aliased command>' '<command args>'" lines from defined aliases
local line; while read line; do
eval "local alias_tokens=($line)" 2>/dev/null || continue # some alias arg patterns cause an eval parse error
local alias_name="${alias_tokens[0]}" alias_cmd="${alias_tokens[1]}" alias_args="${alias_tokens[2]# }"
# skip aliases to pipes, boolan control structures and other command lists
# (leveraging that eval errs out if $alias_args contains unquoted shell metacharacters)
eval "local alias_arg_words=($alias_args)" 2>/dev/null || continue
# skip alias if there is no completion function triggered by the aliased command
[[ " ${completions[*]} " =~ " $alias_cmd " ]] || continue
local new_completion="$(complete -p "$alias_cmd")"
# create a wrapper inserting the alias arguments if any
if [[ -n $alias_args ]]; then
local compl_func="${new_completion/#* -F /}"; compl_func="${compl_func%% *}"
# avoid recursive call loops by ignoring our own functions
if [[ "${compl_func#_$namespace::}" == $compl_func ]]; then
local compl_wrapper="_${namespace}::${alias_name}"
echo "function $compl_wrapper {
(( COMP_CWORD += ${#alias_arg_words[@]} ))
COMP_WORDS=($alias_cmd $alias_args \${COMP_WORDS[@]:1})
$compl_func
}" >> "$tmp_file"
new_completion="${new_completion/ -F $compl_func / -F $compl_wrapper }"
fi
fi
# replace completion trigger by alias
new_completion="${new_completion% *} $alias_name"
echo "$new_completion" >> "$tmp_file"
done < <(alias -p | sed -Ene "s/$alias_regex/\1 '\2' '\3'/p")
source "$tmp_file" && rm -f "$tmp_file"
}; alias_completion
if [ -a /Users/dwinegar/base/phacility/arcanist/resources/shell/bash-completion ]; then
# set up Arcanist
export PATH=~/base/phacility/arcanist/bin:$PATH
source /Users/dwinegar/base/phacility/arcanist/resources/shell/bash-completion
fi
if [ -a ~/base/coursera/puppet/modules/coursera-people/files/shared/bash/.bash_profile ]; then
# set up coursera bash profile
source ~/base/coursera/puppet/modules/coursera-people/files/shared/bash/.bash_profile
source ~/base/coursera/puppet/modules/coursera-people/files/shared/bash/.bashrc
fi
export VAGRANT_DEFAULT_PROVIDER=vmware_fusion
if hash brew 2>/dev/null; then
if [ -f $(brew --prefix)/etc/bash_completion ]; then
. $(brew --prefix)/etc/bash_completion
fi
fi