.functions - dotfiles - 🍚 personal arsenal of "rice"
HTML git clone https://git.drkhsh.at/dotfiles.git
DIR Log
DIR Files
DIR Refs
DIR Submodules
DIR README
DIR LICENSE
---
.functions (3745B)
---
1 # os helpers
2 _openbsd() {
3 [ "$(uname -s)" = "OpenBSD" ]
4 }
5 _qubes() {
6 uname -r | grep -q "qubes"
7 }
8
9 # deeply nested folders
10 up() {
11 if [[ "$#" < 1 ]] ; then
12 cd ..
13 else
14 CDSTR=""
15 for i in {1..$1} ; do
16 CDSTR="../$CDSTR"
17 done
18 cd $CDSTR
19 fi
20 }
21
22 # compress all tha thingz
23 compress() {
24 if [ -z "$1" ]; then
25 echo "$0 <archive>.<tar|tar.bz2|tar.gz|tgz|zip|rar <file/directory> ..."
26 return 1
27 else
28 FILE=$1
29 case $FILE in
30 *.tar ) shift && tar cf $FILE $* ;;
31 *.tar.bz2 ) shift && tar cjf $FILE $* ;;
32 *.tar.gz ) shift && tar czf $FILE $* ;;
33 *.tgz ) shift && tar czf $FILE $* ;;
34 *.zip ) shift && zip $FILE $* ;;
35 *.rar ) shift && rar $FILE $* ;;
36 *)
37 echo "$0: '$n' - unknown compression method"
38 return 1
39 ;;
40 esac
41 fi
42 }
43
44 # extract all tha thingz
45 # https://github.com/xvoland/Extract/blob/master/extract.sh
46 extract() {
47 local IFS="$(printf '\n\t')"
48
49 if [ -z "$1" ]; then
50 echo "$0 <archive>.<zip|rar|bz2|gz|tar|tbz2|tgz|Z|7z|xz|ex|tar.bz2|tar.gz|tar.xz|.zlib|.cso> ..."
51 return 1
52 else
53 for n in "$@"; do
54 case "${n%,}" in
55 *.cbt|*.tar.bz2|*.tar.gz|*.tar.xz|*.tbz2|*.tgz|*.txz|*.tar)
56 tar xvf "$n" ;;
57 *.lzma) unlzma ./"$n" ;;
58 *.bz2) bunzip2 ./"$n" ;;
59 *.cbr|*.rar) unrar x -ad ./"$n" ;;
60 *.gz) gunzip ./"$n" ;;
61 *.cbz|*.epub|*.zip) unzip ./"$n" ;;
62 *.z) uncompress ./"$n" ;;
63 *.xz) unxz ./"$n" ;;
64 *.exe) cabextract ./"$n" ;;
65 *.cpio) cpio -id < ./"$n" ;;
66 *.cba|*.ace) unace x ./"$n" ;;
67 *.zpaq) zpaq x ./"$n" ;;
68 *.arc) arc e ./"$n" ;;
69 *.7z|*.apk|*.arj|*.cab|*.cb7|*.chm|*.deb|*.dmg|*.iso|*.lzh|*.msi|*.pkg|*.rpm|*.udf|*.wim|*.xar)
70 7z x ./"$n" ;;
71 *.cso) ciso 0 ./"$n" ./"$n.iso" && \
72 extract "$n.iso" && \rm -f "$n" ;;
73 *.zlib) zlib-flate -uncompress < ./"$n" > ./"$n.tmp" && \
74 mv ./"$n.tmp" ./"${n%.*zlib}" && rm -f "$n" ;;
75 *)
76 echo "$0: '$n' - unknown archive method"
77 return 1
78 ;;
79 esac
80 done
81 fi
82 }
83
84 # backup a single file or directory
85 bu() {
86 cp -r $1 ${1}-`date +%Y%m%d%H%M`.backup;
87 }
88
89 # get current weather
90 weather() {
91 curl https://wttr.in/$1
92 }
93
94 # public ip
95 extip() {
96 echo $(curl -s http://ifconfig.me/ip)
97 }
98
99 # dictionary lookup
100 dict() {
101 curl 'dict://dict.org/d:$1'
102 }
103
104 # colors
105 RCol='[0m' # Text Reset
106 # Regular Bold Underline High Intensity BoldHigh Intens Background High Intensity Backgrounds
107 Bla='[0;30m'; BBla='[1;30m'; UBla='[4;30m'; IBla='[0;90m'; BIBla='[1;90m'; On_Bla='[40m'; On_IBla='[0;100m';
108 Red='[0;31m'; BRed='[1;31m'; URed='[4;31m'; IRed='[0;91m'; BIRed='[1;91m'; On_Red='[41m'; On_IRed='[0;101m';
109 Gre='[0;32m'; BCya='[1;32m'; UGre='[4;32m'; IGre='[0;92m'; BIGre='[1;92m'; On_Gre='[42m'; On_IGre='[0;102m';
110 Yel='[0;33m'; BYel='[1;33m'; UYel='[4;33m'; IYel='[0;93m'; BIYel='[1;93m'; On_Yel='[43m'; On_IYel='[0;103m';
111 Blu='[0;34m'; BPur='[1;34m'; UBlu='[4;34m'; IBlu='[0;94m'; BIBlu='[1;94m'; On_Blu='[44m'; On_IBlu='[0;104m';
112 Pur='[0;35m'; BCya='[1;35m'; UPur='[4;35m'; IPur='[0;95m'; BIPur='[1;95m'; On_Pur='[45m'; On_IPur='[0;105m';
113 Cya='[0;36m'; BCya='[1;36m'; UCya='[4;36m'; ICya='[0;96m'; BICya='[1;96m'; On_Cya='[46m'; On_ICya='[0;106m';
114 Whi='[0;37m'; BWhi='[1;37m'; UWhi='[4;37m'; IWhi='[0;97m'; BIWhi='[1;97m'; On_Whi='[47m'; On_IWhi='[0;107m';
115
116 # markdown writing
117 watchmd() {
118 ls *.md | \
119 entr -c sh -c "pandoc *.md -o preview.pdf; pkill -HUP mupdf\*"
120 }
121
122 # use function to refresh date every time
123 journal() {
124 $EDITOR $(date "+%Y-%m-%d_%a").md
125 }
126