forked from nathanchance/env
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathos_utils
More file actions
executable file
·248 lines (207 loc) · 6.22 KB
/
os_utils
File metadata and controls
executable file
·248 lines (207 loc) · 6.22 KB
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
#!/usr/bin/env bash
#
# Utility and terminal setup functions (usually for .bashrc)
#
# Copyright (C) 2017 Nathan Chancellor
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>
# SOURCE OUR UNIVERSAL FUNCTIONS SCRIPT (DON'T MAC CHECK THOUGH)
source common -m
# SOURCE THE OS SPECIFIC FUNCTIONS
source ${SCRIPTS_FOLDER}/os_${OS}
function aliases() {
# tmux alias
alias tmux='tmux -u'
# Alias hub to git
alias git='hub'
alias gf='git fetch'
alias gcp='git cherry-pick'
alias gcpa='git cherry-pick --abort'
alias gcpe='git cherry-pick --edit'
alias gcpc='git cherry-pick --continue'
alias gcpq='git cherry-pick --quit'
alias gph='git push'
alias gpo='git push origin'
alias gpf='git push --force'
alias gpsu='git push --set-upstream origin'
alias gpl='git pull'
alias gm='git merge'
alias gmc='git merge --continue'
alias gma='git merge --abort'
alias ga='git add'
alias gaa='git add -A'
alias gam='git am'
alias gc='git commit --signoff'
alias gac='git commit --signoff --all'
alias gca='git commit --amend'
alias gcas='git commit --amend --signoff'
alias gcaa='git commit --amend --all'
alias grhe='git reset HEAD'
alias grh='git reset --hard'
alias grs='git reset --soft'
alias glg='git log'
alias glp="git log -p"
alias gl='git log --oneline'
alias gb='git branch -v'
alias gbd='git branch -D'
alias gs='git status'
alias grm='git remote'
alias gch='git checkout'
alias gcb='git checkout -b'
alias grb='git rebase'
alias grbi='git rebase -i'
alias grba='git rebase --abort'
alias grbc='git rebase --continue'
alias gdh='git diff HEAD'
alias gdc='git diff --cached'
alias gsh='git show'
alias gshs='git show --stat'
alias gshss='git show --stortstat'
}
# Try to attach via tmux
function tmux_attach() {
if [[ -z ${TMUX} ]]; then
ID=$(tmux ls | grep -vm1 attached | cut -d: -f1)
[[ -z ${ID} ]] && tmux -u new-session \
|| tmux -u attach-session -t ${ID}
fi
}
# Add something to PATH but only if it isn't already there
function add_to_path_pre() {
[[ ! $(echo ${PATH} | ag -s --nocolor ${1}) ]] && export PATH="${1}:${PATH}"
}
function add_to_path_post() {
[[ ! $(echo ${PATH} | ag -s --nocolor ${1}) ]] && export PATH="${PATH}:${1}"
}
function bash_setup() {
aliases
${OS}_aliases
tmux_attach
${OS}_prompt
${OS}_setup
add_to_path_pre "${SCRIPTS_FOLDER}"
}
# bashrc update function
function buf() {
source ${SCRIPTS_FOLDER}/os_utils
bash_setup
}
# EXKM to RC converter
function exkm2rc {
sed -e 's/^/ write /' ${1} > ${2}
}
function gerrit-push {
local ROM=${1}
local PROJECT=${2}
local URL
local USER=nathanchance
case ${1} in
"du")
URL=gerrit.dirtyunicorns.com
BRANCH=n7x ;;
"du-caf")
URL=gerrit.dirtyunicorns.com
BRANCH=n7x-caf ;;
"omni")
URL=gerrit.omnirom.org
BRANCH=android-7.1 ;;
"subs")
URL=substratum.review
if [[ ${PROJECT} = "substratum/interfacer" ]]; then
BRANCH=n-rootless
else
BRANCH=n-mr2
fi ;;
esac
if [[ -z ${PROJECT} ]]; then
PROJECT=$(grep "projectname" .git/config | sed 's/\tprojectname = //')
fi
if [[ -n ${PROJECT} ]]; then
PROJECT=$(echo ${PROJECT} | sed 's/DirtyUnicorns\///')
echo "Executing git push ssh://${USER}@${URL}:29418/${PROJECT} HEAD:refs/for/${BRANCH}"
git push ssh://${USER}@${URL}:29418/${PROJECT} HEAD:refs/for/${BRANCH}
else
echo "wtf happened?"
fi
}
function ex () {
if [[ -f ${1} ]]; then
case ${1} in
*.tar.bz2)
tar xjf ${1} ;;
*.tar.gz)
tar xzf ${1} ;;
*.bz2)
bunzip2 ${1} ;;
*.rar)
unrar x ${1} ;;
*.gz)
gunzip ${1} ;;
*.tar)
tar xf ${1} ;;
*.tbz2)
tar xjf ${1} ;;
*.tgz)
tar xzf ${1} ;;
*.zip)
unzip ${1} ;;
*.Z)
uncompress ${1} ;;
*.7z)
7z x ${1} ;;
*)
echo "'${1}' cannot be extracted via ex()" ;;
esac
else
echo "'${1}' is not a valid file"
fi
}
function transfer() {
echo
curl --upload-file ${1} https://transfer.sh/$(basename ${1})
echo
echo
}
function haste() {
local OUTPUT CONTENTS
if (( $# == 0 )) && [[ $(printf "%s" "$0" | wc -c) > 0 ]]; then
CONTENTS=${0}
elif (( $# != 1 )) || [[ $1 =~ ^(-h|--help)$ ]]; then
echo "Usage: ${0} FILE"
echo "Upload contents of plaintext document to hastebin."
echo "\nInvocation with no arguments takes input from stdin or pipe."
echo "Terminate stdin by EOF (Ctrl-D)."
return 1
elif [[ -e ${1} && ! -f ${1} ]]; then
echo "Error: Not a regular file."
return 1
elif [[ ! -e ${1} ]]; then
echo "Error: No such file."
return 1
elif (( $(stat -c %s ${1}) > (512*1024**1) )); then
echo "Error: File must be smaller than 512 KiB."
return 1
fi
if [[ -n "${CONTENTS}" ]] || [[ $(printf "%s" "${CONTENTS}" | wc -c) < 1 ]]; then
CONTENTS=$(cat ${1})
fi
OUTPUT=$(curl -X POST -s -d "${CONTENTS}" https://hastebin.com/documents |\
awk -F '"' '{print "https://hastebin.com/"$4}')
if [[ -n ${OUTPUT} ]]; then
echo "${OUTPUT}"
return 0
fi
echo "Upload failed."
return 1
}