-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpandora
65 lines (52 loc) · 1.26 KB
/
pandora
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
#!/usr/bin/env bash
PANDORA_FIFO="${HOME}/.config/pianobar/ctl"
pandora() {
[[ $1 == "quit" ]] && { quit_pandora; return; }
is_pandora_running && { resume_pandora; return; }
start_pandora
login_to_pandora
}
start_pandora() {
remove_pandora_fifo
mkfifo "${PANDORA_FIFO}"
screen -dmS pandora bash -c pianobar
}
login_to_pandora() {
! is_op_logged_in && op_login
! is_op_logged_in && { op_login_failed; return 1; }
send_to_pandora $(get_pandora_login username)
send_to_pandora $(get_pandora_login password)
printf "Started Pandora.\n"
}
is_op_logged_in() {
op account get &> /dev/null
}
op_login() {
eval $(op signin 2> /dev/null)
}
op_login_failed() {
printf "Failed to login.\n"
quit_pandora
}
send_to_pandora() {
echo "$1" > "${PANDORA_FIFO}"
}
get_pandora_login() {
op item get 4wrr4xvuwzfgpayczrmsnefihy --fields "${1}"
}
is_pandora_running() {
screen -list | grep -q "pandora"
}
resume_pandora() {
screen -rd pandora &> /dev/null
}
quit_pandora() {
is_pandora_running && echo "q" > "${PANDORA_FIFO}"
is_pandora_running && screen -X -S pandora quit
is_pandora_running && printf "Error: Failed to q" || printf "Q"
printf "uit Pandora.\n"
remove_pandora_fifo
}
remove_pandora_fifo() {
rm "${PANDORA_FIFO}" &> /dev/null
}