-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfunctions.sh
159 lines (142 loc) · 4.39 KB
/
functions.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#!/bin/bash
#create a new directory and enter it
function md() {
mkdir -p "$@" && cd "$@"
}
function pushd_quiet() {
pushd "$1" >/dev/null 2>&1
}
function popd_quiet() {
popd >/dev/null 2>&1
}
function is_git_installed() {
if test ~ $(which git)
then return 0
else return 1
fi
}
#typing pbpaste & pbcopy is a pain.
#I think what this does is checks if there's anything in the clipboard, and
#paste it if it is, else copy what follows
function clip() {
[ -t 0 ] && pbpaste || pbcopy;
}
function is_sudo(){
if [$(id -u) -eq 0]
then
return 0
else
return 1
fi
}
#using arcanist? Then you may end up with a bunch of branches named
#Arcpath-XXX-N littering your repos
#delete them from your local repo with this
function clean_arcpatch(){
if is_git_installed
then
echo "Git is not installed. What is wrong with you?"
return 0
fi
for ref in $(git for-each-ref --format='%(refname)' refs/heads/arcpatch*); do
branch_name=$(echo "$ref" | cut -f 3 -d '/')
echo $(git branch -D $branch_name)
done
}
function clean_hotfixes(){
if is_git_installed
then
echo "Git is not installed. What is wrong with you?"
return 0
fi
branches=$(git for-each-ref --format='%(refname)' refs/heads/hotfix*)
branch_count=${#branches[@]}
echo "There were ${branch_count} branches found."
echo "${branches[@]}"
#why is this returning an array of length 1, but the first entry is an empty string?
echo "|${branches[0]}|"
exit 1
#TODO: count number of refs that match, and how many are deleted
#TODO: if there are no branches matching the name/pattern, say so
for ref in $branches; do
branch_name=$(echo "$ref" | cut -f 3 -d '/')
$(git branch -D "$branch_name")
done
}
#TODO: allow
function grb() {
#commit_range = [[ -n $2 ]]
# conditionally assign value to commit_range if one is supplied via function args
#echo `git rebase --interactive HEAD~${commit_range}`
exit 0
}
#TODO: a function to go through, branch by branch, and delete, skip, or quit
# which would make it easier to delete multiple git branches with one command.
# Very similar to how `git add -p` works, allowing you to choose which changes
# will be staged for commit
function clean_branches() {
exit 0
}
#should operate very similar to pushd
#allow you to switch between git branches quickly
function pushbr(){
#TODO: where/how does pushd/popd store the directory stack?
#Cheat by putting it in an environment variable for now?
#
# verify that destination branch exists
# lookup in local branches
# stash current changes
# store the id/ref of the stash
# get current branch name
# switch to branch specified by arg
#
#http://stackoverflow.com/questions/9916551/pushd-popd-global-directory-stac
echo "pushbr()"
}
#should operate very similar to pushd
#allow you to switch between git branches quickly
function popbr(){
# reverse of pushbr
echo "popbr()"
}
# far too clever way to do what should be a simple task
# TODO: make sure this works!
function open_files_matching(){
SEARCH_REGEX=$1
SEARCH_PATH=$2
#TODO: only open if there are matches, else give an error message
#TODO: why is this failing on a "ag: command not found" error?
FILE_LIST=$(ag -l "$SEARCH_REGEX" "$SEARCH_PATH")
echo "$FILE_LIST"
#| xargs -o vim -p
}
#TODO quick conversion from hex to decimal for colours, and vice-versa
# though this is probably more fun to write in ruby or python
#
#colourized man pages
# http://boredzo.org/blog/archives/2016-08-15/colorized-man-pages-understood-and-customized
man() {
env \
LESS_TERMCAP_mb="$(printf "\e[1;31m")" \
LESS_TERMCAP_md="$(printf "\e[1;31m")" \
LESS_TERMCAP_me="$(printf "\e[0m")" \
LESS_TERMCAP_se="$(printf "\e[0m")" \
LESS_TERMCAP_so="$(printf "\e[1;44;33m")" \
LESS_TERMCAP_ue="$(printf "\e[0m")" \
LESS_TERMCAP_us="$(printf "\e[1;32m")" \
man "$@"
}
function output_dot() {
command -v dot >/dev/null 2>&1 || { echo >&2 "The Dot tool (Graphviz) is not installed. Install it and try again."; return 1; }
#verify that the file has a .dot extension?
#verify that dot exists on this system?
FILEPATH=$1
FILENAME=${FILEPATH%.*}
`dot $FILEPATH -Tpng -o $FILENAME.png && open $FILENAME.png`
}
function 2leet() {
echo "$@" | tr [:upper:] [:lower:] | tr "lreasgtbo"
}
function network_connection_history(){
echo $(defaults read /Library/Preferences/SystemConfiguration/com.apple.airport.preferences)
}