-
Notifications
You must be signed in to change notification settings - Fork 20
/
bash_tricks.sh
140 lines (109 loc) · 3.16 KB
/
bash_tricks.sh
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
# Aliases
#========
# I'm a bad typist
alias sl=ls
alias mdkir=mkdir
alias soruce=source
alias souce=source
# Short things are better
alias v=vagrant
alias g=git
alias d=docker
# Short things are better (git)
alias gs='git show --pretty=oneline'
alias gpom='git push origin master'
alias gpod='git push origin development'
alias grom='git reset --hard origin/master'
alias gp='git pull'
# Env Overload
alias utcdate='TZ=utc date'
# Just fun
alias fucking=sudo
# Stored Regular Expressions
alias reg_mac='echo [0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}'
alias grep_mac='grep -E `reg_mac`'
alias reg_email='echo "[^[:space:]]+@[^[:space:]]+"'
alias reg_ip='echo "\b([0-9]{1,3}\.){3}[0-9]{1,3}\b"'
# Reference
alias alphabet='echo a b c d e f g h i j k l m n o p q r s t u v w x y z'
alias unicode='echo ✓ ™ ♪ ♫ ☃ ° Ɵ ∫'
alias numalphabet='alphabet; echo 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6'
alias ascii='man ascii | grep -m 1 -A 63 --color=never Oct'
# Simple but easy
alias ssh300='ssh-add -t 300'
# Validate things
alias yamlcheck='python -c "import sys, yaml as y; y.safe_load(open(sys.argv[1]))"'
alias jsoncheck='jq "." >/dev/null <'
alias ppv='puppet parser validate'
# Misc
alias urlencode='python -c "import sys, urllib as ul; print ul.quote_plus(sys.argv[1])"'
alias bsc='git add .; git commit -a -m "Bull Shit Commit"; git push origin master'
# Functions
#==========
# Get to the top of a git tree
cdp () {
TEMP_PWD=`pwd`
while ! [ -d .git ]; do
cd ..
done
OLDPWD=$TEMP_PWD
}
# Interact with gerrit
gerrit () {
if [ $1 = "wip" ]; then
commit_sha=`git rev-parse HEAD`
if [ -z $commit_sha ]; then
echo "Not in git directory?"
return 1
fi
gerrit review $commit_sha --workflow -1
return $?
fi
username=`git config gitreview.username`
#username='[email protected]'
ssh -o VisualHostKey=no -p 29418 [email protected] gerrit $*
}
export -f gerrit
# Check out a Pull request from github
function pr() {
id=$1
if [ -z $id ]; then
echo "Need Pull request number as argument"
return 1
fi
git fetch origin pull/${id}/head:pr_${id}
git checkout pr_${id}
}
# I used to run this every now and then, now I don't have to think
function cleanfloat() {
for ip in `nova floating-ip-list | awk '/ - / {print $4}'`
do echo $ip
nova floating-ip-delete $ip
done
}
# Connect to windows for fun
gobook() {
ssh -N -f -L 3389:localhost:3389 telescope.fqdn
rdesktop -K -u nibz -p $WINDOWS_PASSWORD -g 95% localhost
}
# Have vim inspect command history
# Requires line numbering to be turned on in your .gitconfig
# git config --global grep.lineNumber true
vim () {
last_command=$(history | tail -n 2 | head -n 1)
if [[ $last_command =~ 'git grep' ]] && [[ "$*" =~ :[0-9]+:$ ]]; then
line_number=$(echo $* | awk -F: '{print $(NF-1)}')
/usr/bin/vim +${line_number} ${*%:${line_number}:}
else
/usr/bin/vim "$@"
fi
}
# maybe this can be used like 'bc' ?
pcp () {
python -c "print $@"
}
# Eject after burning
wodim () {
/usr/bin/wodim -v $1
eject -T
}