-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.functions
91 lines (76 loc) · 2.34 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
function highlight
{
declare -A fg_color_map
fg_color_map[black]=30
fg_color_map[red]=31
fg_color_map[green]=32
fg_color_map[yellow]=33
fg_color_map[blue]=34
fg_color_map[magenta]=35
fg_color_map[cyan]=36
fg_c=$(echo -e "\e[1;${fg_color_map[$1]}m")
c_rs=$'\e[0m'
sed -u s"/$2/$fg_c\0$c_rs/g"
}
function in_git_repository
{
depth=$(($(grep -o / <<< `pwd` | wc -l) + 1 ))
cur=0
while [ $cur -lt $depth ]; do
prefix=""
for ((i = 0; i < $cur; i++))
do
prefix="../$prefix"
done
if [ -d "$prefix.git" ]
then
return 0
fi
let cur+=1
done
return 1
}
function colors_palette
{
for i in $(seq 0 8); do printf "\x1b[38;5;${i}m%03d " $i; done
printf "\n"
for i in $(seq 8 16); do printf "\x1b[38;5;${i}m%03d " $i; done
printf "\n\n"
for g in $(seq 0 5); do
for r in $(seq 0 5); do
for b in $(seq 0 5); do
c=$[16 + $[r * 36] + $[g * 6] + $b];
printf "\x1b[38;5;${c}m%03d " $c
done
printf "\x1b[0m "
done
printf "\n"
done
printf "\n"
for i in $(seq 232 243); do printf "\x1b[38;5;${i}m%03d " $i; done
printf "\n"
for i in $(seq 244 255); do printf "\x1b[38;5;${i}m%03d " $i; done
printf "\x1b[0m\n"
}
function wiki
{
echo
encoded=`printf %s "$@" | jq -s -R -r @uri`
curl --data-urlencode "titles=$encoded" -s 'https://en.wikipedia.org/w/api.php?format=json&action=query&prop=extracts&exintro&explaintext&redirects=1' | jq -Mr '.query.pages | .[] | .extract' | tr -d '\n' | fold -w 76 -s | sed 's/^/ /'
echo
}
function make_cert
{
subj="/C=${SSL_COUNTRY:-US}/ST=${SSL_STATE:-New York}/L=${SSL_LOCALITY:-New York}/O=${SSL_ORGANIZATION:-Acme Heavy Industries}/OU=${SSL_ORGANIZATION_UNIT:-Bit-Shifting Department}/CN=$1"
echo Subject: "$subj"
openssl req -nodes -x509 -newkey rsa:4096 -keyout $1.key -out $1.pem -days 9001 -subj "$subj"
if [ $? -eq 0 ]; then
echo "Created $1.key and $1"
fi
}
function show_cert() {
echo | openssl s_client -showcerts -servername $1 -connect $1:443 2>/dev/null | openssl x509 -inform pem -noout -text
}
grep -qs Raspberry\ Pi /proc/device-tree/model
[[ $? -eq 0 ]] && [[ -e "$HOME/.functions_pi" ]] && source "$HOME/.functions_pi"
[[ -e "$HOME/.functions_local" ]] && source "$HOME/.functions_local"