-
Notifications
You must be signed in to change notification settings - Fork 0
/
.bash_functions
58 lines (47 loc) · 1.48 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
#!/bin/sh
# change github protocol from https to git
function fix_github_urls {
for file in $(find ~/projects -type f -iname config | grep '\.git'); do
file_replace_str "url = https://github.com/stefaniuk" "url = [email protected]:stefaniuk" $file
done
}
# execute functions that requite higher privileges
function please {
local func="$1"
local params=( "$@" ) # array containing all parameters
unset params[0] # remove first element
local content="#!/bin/bash\n\n"
content="${content}params=(\n"
local regex="\s+"
for param in "${params[@]}"; do
if [[ "$param" =~ $regex ]]; then
content="${content}\t\"${param}\"\n"
else
content="${content}\t${param}\n"
fi
done
content="$content)\n"
local file="$HOME/_sudo.$$"
echo -e "$content" > $file
echo "#$( type "$func" )" >> $file
echo -e "\n$func \"\${params[@]}\"\n" >> $file
sudo bash $file
rm $file
}
# convert bytes to human readable text
function byteme {
local list="bytes,KB,MB,GB,TB,PB,EB,ZB,YB"
local p=1
local data=$(cat)
local v=$(echo "scale=2; $data / 1" | bc)
local i=$(echo $v / 1024 | bc)
while [ ! $i = "0" ]; do
let p=p+1
v=$(echo "scale=2; $v / 1024" | bc)
i=$(echo $v / 1024 | bc)
done
echo $v$(echo $list | cut -f$p -d,)
}
function jcurl {
curl -ksSL -H "Accept: application/json" -H "Content-Type: application/json" $1 | json | pygmentize -l json
}