-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.sh
More file actions
163 lines (138 loc) · 3.25 KB
/
utils.sh
File metadata and controls
163 lines (138 loc) · 3.25 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
#!/bin/bash
##################
# Useful functions - to be sourced in .bashrc
##################
# go up n levels
up()
{
TMP=$PWD
LEVELS=${1:-1}
for _ in $(seq "$LEVELS"); do
cd ..
done
# $OLDPWD allows for `cd -`
export OLDPWD=$TMP
}
# View a random man page
randman()
{
man "$(ls -1 /usr/share/man/man?/ | shuf -n1 | cut -d. -f1)"
}
# a convenience wrapper around window.py
window()
{
python3 ~/bin/window.py "$@"
}
# attempt to rhyme the given word
rhyme()
{
{ cat /usr/share/dict/words; printf %s\\n "$1"; } | rev | sort | rev | grep -FxC15 -e "${1?}" | grep -Fxve "$1" | shuf -n1;
}
# grabs the local IP
localip()
{
echo "local IP(s):"
echo ""
# ifconfig | perl -nle'/dr:(\S+)/ && print $1'
echo "local IP: $(hostname -I)"
}
# grabs the external IP
publicip()
{
echo "public IP:"
echo ""
curl -s 'ipecho.net/plain'
echo ""
}
# sorts directories by size
dsort()
{
du -a -d 1 -h | sort -h
}
# completely remove a package - probably shouldn't use
completely_remove_package()
{
apt-get purge "$("apt-cache depends $1 | awk '{ print $2 }' | tr '\n' ' '")"
}
# Gives number of additions author has made in current git repo
additions()
{
git log --author="$*" --pretty=tformat: --numstat | \
awk '{ add += $1; subs += $2; loc += $1 - $2 } END \
{ printf "added lines: %s removed lines: %s total lines: %s\n", add, subs, loc }' -
}
# converts CRLF endings to LF endings
dos2unix()
{
sed -i 's/.$//' "$1"
}
# converts LF endings to CRLF endings
unix2dos()
{
# requires GNU sed
sed -i 's/$/\r/' "$1"
}
# Browse git log
gl() {
git log --graph --color=always \
--format="%C(auto)%h%d %s %C(black)%C(bold)%an, %cr" "$@" |
fzf --ansi --no-sort --reverse --preview "echo {} | grep -o '[a-f0-9]\{7\}' | head -1 | xargs -I % sh -c 'git show --color=always %'" \
--bind "enter:execute:
(grep -o '[a-f0-9]\{7\}' | head -1 |
xargs -I % sh -c 'git show --color=always % | less -R') << 'FZF-EOF'
{}
FZF-EOF"
}
#source daisy toolchain
dey()
{
source /opt/dey/1.6.11/environment-setup-cortexa9hf-vfp-neon-dey-linux-gnueabi
}
#source fred toolchain
fred()
{
source /opt/muxos/0.2/environment-setup-armv7ahf-neon-mta-linux-gnueabi
}
#source idf toolchain
idf()
{
source ~/esp/esp-idf/export.sh
}
start_can()
{
sudo ip link set $1 type can bitrate 250000
sudo ip link set $1 up
}
# Good for removing build artifacts and shit
rinse_repo()
{
git clean -xfd
git submodule foreach --recursive git clean -xfd
git reset --hard
git submodule foreach --recursive git reset --hard
git submodule update --init --recursive
}
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
clean_up_branches(){
git branch --merged >/tmp/merged-branches
vim /tmp/merged-branches
xargs git branch -d </tmp/merged-branches
}
h2d() {
echo -n "Dec: "
echo "obase=10; ibase=16; $1" | bc
echo -n "Bin: "
echo "obase=2; ibase=16; $1" | bc
}
d2h() {
echo -n "Hex: "
echo "obase=16; ibase=10; $1" | bc
echo -n "Bin: "
echo "obase=2; ibase=10; $1" | bc
}
vpn()
{
sudo systemctl $1 ravenvpn
}