summaryrefslogtreecommitdiff
path: root/volsv
blob: 960481a5cfb77c406c7f9b111344b2fa6ea67fd0 (plain)
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
#!/bin/sh
# print error message
printerror () {
  echo "$1 is not a recognized command or flag"
}
# if sndio
sndiosv () {
  case "$1" in
    "up" | "-i") sndioctl output.level=+0.05 ;;
    "down" | "-d") sndioctl output.level=-0.05 ;;
    "toggle" | "-t") sndioctl output.mute=! ;;
    "mic" | "-m") sndioctl input.mute=! ;;
    "getv" | "-v") printf "%s%%" `sndioctl output.level | rev | cut -d'.' -f1 | rev | cut -c 1,2` ;;
    "getm" | "-g") sndioctl output.mute | cut -d'=' -f2 | sed 's/1/[off]/;s/0/[on]/' ;;
    "getvm" | "-vg") printf "%s%s%%" `sndioctl output.mute | cut -d'=' -f2 | sed 's/1/[off]/;s/0/[on]/'` `sndioctl output.level | rev | cut -d'.' -f1 | rev | cut -c 1,2` ;;
    *) printerror "$1" ;;
  esac
}
# if pulseaudio
pulsesv () {
  case "$1" in
    "up" | "-i") pamixer -i 5 ;;
    "down" | "-d") pamixer -d 5 ;;
    "toggle" | "-t") pamixer -t ;;
    "mic" | "-m") pamixer --source 1 -t ;;
    "getv" | "-v") printf "%s%%\n" "$(pamixer --get-volume)" ;;
    "getm" | "-g") pamixer --get-mute | sed 's/[Ff]alse/\[on\]/;s/[Tt]rue/\[off\]/' ;;
    "getvm" | "-vg") printf "%s%s%%\n" `pamixer --get-mute | sed 's/[Ff]alse/\[on\]/;s/[Tt]rue/\[off\]/'` "$(pamixer --get-volume)" ;;
    *) printerror "$1" ;;
  esac
}
# if pipewire
pwiresv () {
  case "$1" in
    "up" | "-i") pamixer -i 5 ;;
    "down" | "-d") pamixer -d 5 ;;
    "toggle" | "-t") pamixer -t ;;
    "mic" | "-m") amixer sset Capture toggle ;;
    "getv" | "-v") printf "%s%%\n" "$(pamixer --get-volume)" ;;
    "getm" | "-g") pamixer --get-mute | sed 's/[Ff]alse/\[on\]/;s/[Tt]rue/\[off\]/' ;;
    "getvm" | "-vg") printf "%s%s%%\n" `pamixer --get-mute | sed 's/[Ff]alse/\[on\]/;s/[Tt]rue/\[off\]/'` "$(pamixer --get-volume)" ;;
    *) printerror "$1" ;;
  esac
}
# if alsa
alsasv () {
  DEVICE=`pgrep -x bluealsa >/dev/null && echo -n "bluealsa"`
  if [ -z "$DEVICE" ]; then
    case "$1" in
      "up" | "-i") amixer sset Master 5%+ ;;
      "down" | "-d") amixer sset Master 5%- ;;
      "toggle" | "-t") amixer sset Master toggle ;;
      "mic" | "-m") amixer sset Capture toggle ;;
      "getv" | "-v") amixer sget Master | grep '\[[0-9]*\%\]' | sed "s/ /\n/g" | grep '%' | sed 's/\[//;s/\]//g' ;;
      "getm" | "-g") amixer sget Master | grep '\[o[fn]' | cut -d' ' -f8 | head -1 ;;
      "getvm" | "-vg") printf "%s%s" `amixer sget Master | grep '\[o[fn]' | cut -d' ' -f8 | head -1` `amixer sget Master | grep '\[[0-9]*\%\]' | sed "s/ /\n/g" | grep '%' | sed 's/\[//;s/\]//g'` ;;
      *) printerror "$1" ;;
    esac
  elif [ -z `amixer -D $DEVICE controls` ]; then
    case "$1" in
      "up" | "-i") amixer sset Master 5%+ ;;
      "down" | "-d") amixer sset Master 5%- ;;
      "toggle" | "-t") amixer sset Master toggle ;;
      "mic" | "-m") amixer sset Capture toggle ;;
      "getv" | "-v") amixer sget Master | grep '\[[0-9]*\%\]' | sed "s/ /\n/g" | grep '%' | sed 's/\[//;s/\]//g' ;;
      "getm" | "-g") amixer sget Master | grep '\[o[fn]' | cut -d' ' -f8 | head -1 ;;
      "getvm" | "-vg") printf "%s%s" `amixer sget Master | grep '\[o[fn]' | cut -d' ' -f8 | head -1` `amixer sget Master | grep '\[[0-9]*\%\]' | sed "s/ /\n/g" | grep '%' | sed 's/\[//;s/\]//g'` ;;
      *) printerror "$1" ;;
    esac
  else
    MIXER=`amixer -D $DEVICE | grep 'A2DP' | cut -d"'" -f2`
    case "$1" in
      "up" | "-i") amixer -D "$DEVICE" sset "$MIXER" 5%+ ;;
      "down" | "-d") amixer -D "$DEVICE" sset "$MIXER" 5%- ;;
      "toggle" | "-t") amixer -D "$DEVICE" sset "$MIXER" toggle ;;
      "getv" | "-v") amixer -D "$DEVICE" sget "$MIXER" | grep '\[[0-9]*\%\]' | sed "s/ /\n/g" | grep '%' | sed 's/\[//;s/\]//g' | head -1;;
      "getm" | "-g") amixer -D "$DEVICE" sget "$MIXER" | grep '\[o[fn]' | cut -d' ' -f9 | head -1 ;;
      "getvm" | "-vg") printf "%s%s" `amixer -D "$DEVICE" sget "$MIXER" | grep '\[o[fn]' | cut -d' ' -f9 | head -1` `amixer -D "$DEVICE" sget "$MIXER" | grep '\[[0-9]*\%\]' | sed "s/ /\n/g" | grep '%' | sed 's/\[//;s/\]//g' | head -1` ;;
      *) printerror "$1" ;;
    esac
  fi
}
#Search input for 
echo "$@" | grep -q ' *-h *' && echo \
"Volsv is Free software. You can use it for any purpose, but I make no guerantee about its usability or fitness "\
"for any particular purpose. You are also free to redistribute, modify, and distribute your modifications to "\
"volsv. Volsv is distributed under the BSD 3-Clause license to ensure full license compatibility with GNU, "\
"Linux, and BSD operating systems. A copy of this license is included in the repository.\n\n"\
"Volsv is a script designed to control the volume of a *NIX machine. The commands/flags are as follows:
increase volume: 'up' or '-i'
decrease volume: 'down' or '-d'
toggle volume mute: 'toggle' or '-t'
toggle mic mute: 'mic' or '-m'
get volume level: 'getv' or '-v'
get mute state: 'getm' or '-g'" && exit

for i in $@; do
  if pgrep -x pulseaudio >/dev/null; then
    pulsesv $i
  elif pgrep -x pipewire >/dev/null; then
    pwiresv $i
  elif pgrep -x sndiod >/dev/null; then
    sndiosv $i
  else
    alsasv $i
  fi
  pgrep -x dwmblocks >/dev/null && sigdwmb volume
  #pgrep -x dwmbar >/dev/null && dwmbar-signal volume
done