-
Notifications
You must be signed in to change notification settings - Fork 0
/
bash_functions
84 lines (76 loc) · 2.16 KB
/
bash_functions
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
# bash_functions: user-defined functions for bash
# Moving around
up() {
if [ $# -eq 0 ]; then
cd ..
elif [ $# -eq 1 ]; then
# Figure out how many directories up we're moving
DIRECTORY=""
for ((i=0; i<$1; i++)); do
DIRECTORY="../${DIRECTORY}"
done
# Execute the directory change
if [ -n "$DIRECTORY" ]; then
cd "$DIRECTORY"
fi
fi
}
# Grab the git branch
git_current_branch() {
# List the branches, find the one starting with an asterisk, then strip out
# the asterisk, the leading space and any parentheses
branch=$(git branch 2> /dev/null | grep "^\*" | cut -c 3- | tr -d "()")
if [ -z "$branch" ]; then
echo ""
else
echo "[$branch]"
fi
}
magic() {
if [ -d "$HOME/incantations" ]; then
export PATH="$HOME/incantations:$PATH"
echo "Magic spells available:"
ls "$HOME/incantations"
fi
}
goto() {
workspace="$HOME/code"
mongo="$workspace/$mongo"
if [ $# -gt 1 ]; then
echo "$0: error: expected only one argument"
elif [ $# -eq 1 ]; then
case $1 in
c|code)
cd "$workspace" ;;
cfg|config)
cd "$workspace/config-files" ;;
d|docs)
cd "$workspace/docs" ;;
db)
cd "$mongo/src/mongo/db" ;;
enterprise)
cd "$workspace/enterprise-modules" ;;
js|jstests)
cd "$mongo/jstests" ;;
m|mongo)
cd "$mongo" ;;
mmap|mmapv1)
cd "$mongo/src/mongo/db/storage/mmap_v1" ;;
src)
cd "$mongo/src/mongo" ;;
storage)
cd "$mongo/src/mongo/db/storage" ;;
wt|wiredtiger|wiredTiger)
cd "$mongo/src/mongo/db/storage/wiredtiger" ;;
*)
echo "Undefined label." ;;
esac
fi
}
please() {
# Get the last command run and strip the history number plus whitespace
CMD=$(history -1 | awk '{$1=""; print $0}' | sed -e 's/^[ ]*//')
echo "sudo $CMD"
eval "sudo $CMD"
}
#" vim: filetype=sh