-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy path.functions
186 lines (169 loc) · 5.15 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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
function http-vcloud-login {
http --session=vcloud-ss-vagrant \
--verify=no -a vagrant@ss \
POST https://roecloud001/api/sessions \
'Accept:application/*+xml;version=5.5' \
--pretty colors
}
function http-vcloud {
if [[ $@ =~ ^http ]]; then
http --session=vcloud-ss-vagrant --verify=no --pretty colors --print hb "$@";
else
http --session=vcloud-ss-vagrant --verify=no --pretty colors --print hb "https://roecloud001$@";
fi
}
function gitcloneall {
if [ "$#" -lt 1 ]; then
echo "Usage: gitcloneall [email protected]:YOUR_ORG [user[:pass]]"
echo "Clones all repos of a GitHub org or user."
return
fi
org=$(echo $1 | sed -e s/.*://)
user=""
if [ -f ~/.config/hub ]; then
user=`awk '/- user:/{print $NF}' ~/.config/hub`
oauth=`awk '/oauth_token:/{print $NF}' ~/.config/hub`
user="-H 'Authorization: token $oauth'"
fi
if [ "$#" -eq 2 ]; then
user="-u $2"
fi
curl $user -s https://api.github.com/users/$org/repos?per_page=200 | jq '.[] | .ssh_url' | sed -e s/git.*$org/$1/ | xargs -I % git clone %
}
function gitall {
if [ "$#" -lt 1 ]; then
echo "Usage: gitall pull|push|commit ..."
echo "Starts a git command for each directory found in current dir."
return
fi
if tput setaf 1 &> /dev/null; then
BOLD=$(tput bold)
RESET=$(tput sgr0)
else
BOLD=""
RESET="\033[m"
fi
dirs="."
for DIR in `find $dirs -name ".git"`; do
echo $BOLD"Entering $(dirname $DIR)"$RESET
pushd $DIR/.. >/dev/null
git "$@"
popd >/dev/null
done
}
function gitls {
if [ "$#" -lt 1 ]; then
dirs="*"
else
dirs=$*
fi
if tput setaf 1 &> /dev/null; then
tput sgr0
if [[ $(tput colors) -ge 256 ]] 2>/dev/null; then
RED=$(tput setaf 1)
ORANGE=$(tput setaf 172)
GREEN=$(tput setaf 70)
PURPLE=$(tput setaf 141)
else
GREEN=$(tput setaf 2)
PURPLE=$(tput setaf 1)
fi
BOLD=$(tput bold)
RESET=$(tput sgr0)
else
GREEN="\033[1;32m"
PURPLE="\033[1;35m"
BOLD=""
RESET="\033[m"
fi
for d in $(ls -1d $dirs/.git); do
# check if we're in a git repo
git --git-dir=$d --work-tree=$d/.. rev-parse --is-inside-work-tree &>/dev/null # || return
# quickest check for what branch we're on
branch=$(git --git-dir=$d --work-tree=$d/.. symbolic-ref -q HEAD | sed -e 's|^refs/heads/||')
# check if it's dirty (via github.com/sindresorhus/pure)
dirty=$(git --git-dir=$d --work-tree=$d/.. diff --quiet --ignore-submodules HEAD &>/dev/null; [ $? -eq 1 ]&& echo -e "*")
dir=`echo $d | sed -e 's|^\.\/||' -e 's|\/.git||'`
FOLDER=$GREEN
BRANCH=$PURPLE
if [ "$branch" != "master" ]; then
FOLDER=$ORANGE
BRANCH=$ORANGE
fi
if [ "$dirty" = "*" ]; then
FOLDER=$RED
BRANCH=$RED
fi
echo $RESET$BOLD$FOLDER"$dir$RESET$BOLD on "$BRANCH$branch$dirty$RESET
done
}
function eachdir {
if [ "$#" -lt 1 ]; then
echo "Usage: eachdir command ..."
echo "Starts a command for each directory found in current dir."
return
fi
if tput setaf 1 &> /dev/null; then
BOLD=$(tput bold)
RESET=$(tput sgr0)
else
BOLD=""
RESET="\033[m"
fi
for DIR in `ls --color=never`;
do
if [ -d $DIR/.git ]; then
echo $BOLD"Entering "$DIR$RESET
pushd $DIR >/dev/null
"$@"
popd >/dev/null
fi
done
}
function gi() { curl -L -s https://www.gitignore.io/api/$@ ; }
function ssh-me() {
ssh-copy-id $@
ssh $@ "mkdir -p code && cd code && git clone https://github.com/StefanScherer/dotfiles && cd dotfiles && ./sync.sh -f"
}
function dmhelper() {
commands=(env inspect ip kill ls regenerate-certs restart rm ssh scp start status stop upgrade url help)
if [ -d /mnt/c ]; then
case "${commands[@]}" in *"$1"*) docker-machine.exe $* ; return ;; esac
eval $(docker-machine.exe env -shell bash $1 | sed 's/C://' | sed 's/\\/\//g')
else
case "${commands[@]}" in *"$1"*) docker-machine $* ; return ;; esac
eval $(docker-machine env $1)
fi
}
function vg() {
pushd ~/code/windows-docker-machine
vagrant $*
popd
}
function vagrantdm() {
if [ "$1" == "start" ]; then vg up $2; return; fi
if [ "$1" == "restart" ]; then vg reload $2; return; fi
if [ "$1" == "stop" ]; then vg halt $2; return; fi
if [ "$1" == "rm" ]; then vg destroy $2 $3; return; fi
if [ "$1" == "status" ]; then vg status $2; return; fi
if [ "$1" == "rdp" ]; then vg rdp $2; return; fi
if [ "$1" == "regenerate-certs" ]; then vg provision $2; return; fi
dmhelper $*
}
function azuredm() {
if [ "$1" == "start" ]; then az vm start -n $2 -g $2; return; fi
if [ "$1" == "restart" ]; then az vm restart -n $2 -g $2; return; fi
if [ "$1" == "stop" ]; then az vm stop -n $2 -g $2; az vm deallocate -n $2 -g $2; return; fi
if [ "$1" == "status" ]; then az vm show -n $2 -g $2; return; fi
dmhelper $*
}
function dm() {
vagrantmachines=(2016 2016-box 1709 1803 1809 1903 2019 2019-box insider lcow)
case "${vagrantmachines[@]}" in *"${!#}"*) vagrantdm $* ; return ;; esac
azuremachines=(az2019 az2016 az1709 az1803 az1903)
case "${azuremachines[@]}" in *"${!#}"*) azuredm $* ; return ;; esac
dmhelper $*
}
function whoseport() {
lsof -i ":$1" | grep LISTEN
}