This repository has been archived by the owner on Nov 21, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmenu.sh
329 lines (262 loc) · 5.39 KB
/
menu.sh
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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
#! /usr/bin/env sh
py="python3.6"
music_player="audacious"
dotfiles="$HOME/packages/src/github.com/bozso/dotfiles"
set -e
opt="-fn -adobe-helvetica-bold-r-normal-*-25-180-100-100-p-138-iso8859-1"
alias mymenu="dmenu $opt -i"
alias dpass="dmenu $opt -nf \"black\" -nb \"black\" <&-"
temu="lxterminal"
debug() {
notify-send -i "$icons/debug.png" "Debug" "$1" -t 2500
}
perr() {
printf "%s\n" "$*" >&2
}
check_narg() {
if [ "$1" -lt "$2" ]; then
perr "error: Wrong number of arguments!"
return 1
fi
}
dprompt() {
[ "$(printf 'No\nYes' | mymenu -p "$1")" = "Yes" ] && "$2"
}
notify() {
return
if [ -n "$3" ]; then
notify-send -i "$icons/$3" "$1" "$2" -t 1500
else
notify-send "$1" "$2" -t 1500
fi
}
extract_music() {
for zipfile in /tmp/*.zip; do
local outpath="/home/istvan/Zenék/$(basename "$zipfile" .zip)"
# mkdir -p "$outpath"
notify "Extracting file" "$zipfile"
unzip "$zipfile" -d "$outpath"
done
}
update_clean() {
notify "Updating..."
local o1="$(sudo apt-get update)"
local o2="$(sudo apt-get upgrade)"
local o3="$(sudo apt-get dist-update)"
# notify "Update complete." "$o1\n$o2\n$3"
local o1="$(sudo apt-get clean)"
local o2="$(sudo apt-get autoremove)"
notify "Cleaning..."
notify "Cleaning complete." "$o1\n$o2"
}
last_field() {
awk -F '/' '{print $NF}'
}
playlists() {
local path="/home/istvan/Zenék/playlists"
local sel="$(ls -1 "$path"/* | last_field |
mymenu -p "Select playlist:")"
if [ -n "$sel" ]; then
local path="$path/$sel"
notify "Playing music" "$sel" "music_note.png"
"$music_player" "$path" &
fi
}
workspace() {
check_narg $# "2"
local name="$1"
local path="$2"
tmux start-server
echo "$name $(tmux ls)"
local bool="$(in_str "$name" "$(tmux ls)")"
echo "$bool"
if [ "$bool" = "false" ]; then
notify "tmux" "Starting session $name"
tmux new-session -d -t "$name"
tmux send-keys "cd $path" C-m
tmux split-window -h -c "$path"
tmux select-pane -t 2
tmux send-keys "mc" C-m
tmux split-window -v -c "$path"
tmux select-pane -t 1
fi
"$temu" -e "tmux attach-session -d -t \"$name\""
}
work() {
local sel="$(dselect "$repos" "Select repo:")"
local path="$(mget "$sel" "$repos")"
workspace "$sel" "$path"
}
bitwarden() {
local sel="$(rbw list | mymenu -p \"Select password:\")"
rbw get "$sel" | xclip -i -selection clipboard
}
mc() {
local sel="$(ls -d -1 "$HOME"/*/ |
awk -F '/' '{print $(NF - 1)}' |
mymenu -p "Select directory:")"
if [ -n "$sel" ]; then
local path="$HOME/$sel"
notify "Started Midnight Commander." "$path" "mc.png"
"$temu" -e "mc $path"
fi
}
servers="\
robosztus : robosztus.ggki.hu
zafir : zafir.ggki.hu
eejit : eejit.geo.uu.nl
"
_ssh_select() {
echo "$(printf '%s\n' "$servers" |
mymenu -p "Select server" -l 3)"
}
_ssh_calc_address() {
local addr="$(printf '%s' "$1" |
cut -d ':' -f 2 |
tr -d ' ')"
echo "$(printf 'istvan@%s' "$addr")"
}
_ssh_mount() {
local name="$(printf '%s' "$1" |
cut -d ':' -f 1 |
tr -d ' ')"
local path="$HOME/mount/$name"
local cmd="$(printf 'sshfs %s: %s' "$2" "$path")"
"$cmd"
}
_ssh_join() {
local cmd="$(printf 'ssh %s' "$1")"
"$cmd"
}
manage_ssh() {
local mode="$1"
local server="$(_ssh_select)"
local addr="$(_ssh_calc_address "$server")"
case "$mode" in
"mount")
_ssh_mount "$server" "$addr"
;;
"join")
_ssh_join "$addr"
;;
*)
printf 'Unknown option: %s!\n' "{mode}"
;;
esac
}
storage() {
local mount_dir="/home/istvan/mount/storage"
# local prog="${HOME}/packages/usr/bin/mount.cifs"
local prog="mount.cifs"
local url="//storage.ggki.hu/bozsoi/"
mkdir -p "$mount_dir"
echo "sudo $prog $url $mount_dir -o username=bozsoi,vers=2.1,rw"
sudo "$prog" "$url" "$mount_dir" -o username=bozsoi,vers=2.1,rw
}
connect() {
manage_ssh "join"
}
mount() {
manage_ssh "mount"
}
mcon() {
local server="$(_ssh_select)"
local addr="$(_ssh_calc_address "$server")"
_ssh_mount "$server" "$addr"
_ssh_join "$addr"
}
poweroff() {
notify-send "Did you push all git repositories?" \
"Check git repositories!" -u "critical" -i "$icons/warning.png"
dprompt "Shutdown?" "shutdown -h now"
}
gamma() {
local path="/home/istvan/Dokumentumok/gamma_doc"
local sel="$(ls -1 "$path"/*.html | last_field |
mymenu -p "Select program:" -l 10)"
if [ -n "$sel" ]; then
local path="$path/$sel"
notify "Opening documentation" "$sel" "music_note.png"
"$BROWSER" "$path"
fi
}
notebook() {
"$miniconda"/bin/jupyter notebook
}
rotp() {
java -jar plz-out/bin/prebuilt/rotp/Remnants.jar
}
dog() {
houndd -conf="/home/istvan/packages/src/github.com/bozso/dotfiles/configs/repos.json"
}
modules="
bitwarden
notebook
poweroff
playlists
git
mc
connect
repos_all
extract_music
work
gamma
mount
dog
mcon
wincap
selcap
storage
rotp
"
select_module() {
local sel="$(printf "%s\n" "$modules" | mymenu -p "Select from modules:")"
for module in "$(printf "%s\n" "$modules")"; do
case $sel in
$module)
"$module"
;;
*) ;;
esac
done
}
Basename() {
while IFS= read -r line; do
printf '%s\n' "$(basename "$line" .png)"
done
}
import() {
"$py" "$dotfiles"/bin/import.py "$@"
}
wincap() {
import screen
}
selcap() {
import select
}
programs() {
PATH="$PATH:$HOME/packages/usr/bin"
dmenu_run "$opt"
}
main() {
check_narg $# 1
case $1 in
"programs")
programs
;;
"modules")
select_module
;;
"import")
import select
;;
"screen")
import screen
;;
*)
printf "Unrecognized option %s!\n" "$1" >&2
return 1
;;
esac
}
main "$@"