-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdvol
executable file
·82 lines (72 loc) · 2.29 KB
/
dvol
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
#!/bin/bash
#
# volume - dzen volume bar
#
interface=${3:-$(amixer scontrols|awk -F\' 'NR==1{print $2}')} # audio channel
card="${4:-0}"
secs="1" # sleep $secs
xpos=$(xdotool getmouselocation|sed 's/:/ /g'|awk '{print $2}') # h position
ypos=$(xdotool getmouselocation|sed 's/:/ /g'|awk '{print $4}') # v position
height="40" # window height
width="200" # window width
dzen_bg="#151515" # background colour of window
dzen_fg="#eeeeee" # foreground colour of text/icon
bar_fg_muteon="#808080" # foreground colour of volume bar
bar_fg_muteoff="#aa3333" # foreground colour of volume bar
bar_bg="#090909" # background colour of volume bar
bar_width="170" # width of volume bar
#Probably do not customize
pipe="/tmp/dvolpipe"
err() {
echo "$1"
exit 1
}
usage() {
echo "usage: dvol [option] [argument] [interface] [card]"
echo
echo "Options:"
echo " -i, --increase - increase volume by \`argument'"
echo " -d, --decrease - decrease volume by \`argument'"
echo " -t, --toggle - toggle mute on and off"
echo " -h, --help - display this"
exit
}
#Argument Parsing
case "$1" in
'-i'|'--increase')
[ -z "$2" ] && err "No argument specified for increase."
[ -n "$(tr -d [0-9] <<<$2)" ] && err "The argument needs to be an integer."
amixarg="${2}%+"
;;
'-d'|'--decrease')
[ -z "$2" ] && err "No argument specified for decrease."
[ -n "$(tr -d [0-9] <<<$2)" ] && err "The argument needs to be an integer."
amixarg="${2}%-"
;;
'-t'|'--toggle')
amixarg="toggle"
;;
''|'-h'|'--help')
usage
;;
*)
err "Unrecognized option \`$1', see dvol --help"
;;
esac
#Actual volume changing (readability low)
amixout="$(amixer set "$interface" "$amixarg" | tail -n 1)"
mute="$(awk -F"[][{}]" '{print $4}' <<<"$amixout")"
vol="$(awk -F '[][{}]|%' '{print $2}' <<<"$amixout")"
#Using named pipe to determine whether previous call still exists
#Also prevents multiple volume bar instances
if [ ! -e "$pipe" ]; then
mkfifo "$pipe"
(dzen2 -tw "$width" -h "$height" -x "$xpos" -y\
"$ypos" -bg "$dzen_bg" -fg "$dzen_fg" < "$pipe"
rm -f "$pipe") &
fi
#Feed the pipe!
bar_fg=bar_fg_mute$mute
bar_fg=${!bar_fg}
(echo "$vol" | gdbar -fg "$bar_fg" -bg "$bar_bg" -w "$bar_width"
sleep "$secs") > "$pipe"