-
Notifications
You must be signed in to change notification settings - Fork 0
/
.functions
executable file
·157 lines (132 loc) · 3.66 KB
/
.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
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
# Open things in Sublime Text
subl () {
subl="/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl"
if [[ $# -eq 0 ]] ; then
TO_OPEN="."
else
TO_OPEN="$1"
fi
"$subl" "$TO_OPEN"
}
# Open things in VS Code
vscode () {
local vscode="/Applications/Visual Studio Code.app/Contents/Resources/app/bin/code"
if [[ $# -eq 0 ]] ; then
TO_OPEN="."
else
TO_OPEN="$1"
fi
"$vscode" "$TO_OPEN"
}
extract () {
if [ -f $1 ] ; then
case $1 in
*.tar.bz2)tar xjf $1;;
*.tar.gz)tar xzf $1;;
*.bz2)bunzip2 $1;;
*.rar)rar x $1;;
*.gz)gunzip $1;;
*.tar)tar xf $1;;
*.tbz2)tar xjf $1;;
*.tgz)tar xzf $1;;
*.zip)unzip $1;;
*.Z)uncompress $1;;
*)echo "'$1' cannot be extracted via extract()" ;;
esac
else
echo "'$1' is not a valid file"
fi
}
announce() {
input=$1
length=${#input}
borderchar="*"
border_length=$(( $length + 12 ))
top_bottom=$(printf "$borderchar%.0s" $(seq 1 $border_length))
middle="***** ${input} *****";
printf "%s\n%s\n%s\n\n" "$top_bottom" "$middle" "$top_bottom"
}
psgrep() {
if [ ! -z $1 ] ; then
echo "Grepping for processes matching $1..."
ps aux | grep $1 | grep -v grep
else
echo "!! Need name to grep for"
fi
}
vncp() {
host=$1
action=$2
case "$action" in
start)
echo "proxying into $host";
ssh -M -S vncsocket -L 5901:localhost:5900 -N -f $host
open "vnc://localhost:5901"
;;
check)
ssh -S vncsocket -O check $host
;;
stop)
ssh -S vncsocket -O exit $host
;;
esac
}
trash() {
for f in "$@"; do
bn=$(basename "$f")
while [ -e ~/.Trash/"$bn" ]; do
bn="$bn $(date +%H.%M.%S %p)"
done
mv "$f" ~/.Trash/"$bn"
done
}
# make a directory and then move into it
take(){
mkdir -p $1; cd $1
}
function ga_code_search() {
# alias todo='ga_code_search "TODO\(`whoami`\)"'
SCREEN_WIDTH=`stty size | awk '{print $2}'`
SCREEN_WIDTH=$((SCREEN_WIDTH-4))
# Given a spooky name so you can alias to whatever you want.
# (cs for codesearch)
# AG is WAY faster but requires a binary
# (try brew install the_silver_searcher)
AG_SEARCH='ag "$1" | sort -k1 | cat -n | cut -c 1-$SCREEN_WIDTH'
# egrep is installed everywhere and is the default.
GREP_SEARCH='egrep -nR "$1" * | sort -k1 | cat -n'
SEARCH=$AG_SEARCH
if [ $# -eq 0 ]; then
echo "Usage: ga_code_search <search> <index_to_edit>"
echo ""
echo "Examples:"
echo " ga_code_search TODO"
echo " ga_code_search TODO 1"
echo " ga_code_search \"TODO\\(graham\\)\""
echo " ga_code_search \"TODO\\(graham\\)\" 4"
echo ""
return
fi
if [ $# -eq 1 ]; then
# There are no command line argumnets.
eval $SEARCH
else
# arg one should be a line from the output of above.
#LINE="$SEARCH | sed '$2q;d' | awk -F':' '{print +\$2 \" \" \$1}' | awk -F' ' '{print \$1 \" \" \$3}'"
LINE="$SEARCH | sed '$2q;d' | awk -F':' '{print +\$2 \" \" \$1}' | awk -F' ' '{print \$3 \":\" \$1}'"
# Modify with your editor here.
subl `eval $LINE`
fi
}
function gogo() {
_start_tmux
}
function giturl() {
git remote -v | grep fetch | awk '{print $2}' | sed 's/git@/http:\/\//' | sed 's/com:/com\//' | sed s'|\/\/|\/|g'
}
function gitopen() {
open "$(git config --get remote.origin.url)/tree/$(prompt_git)";
}
function gitpr() {
open "$(git config --get remote.origin.url)/compare/$(prompt_git)?expand=1";
}