scripts

random scripts
git clone https://git.parazyd.org/scripts
Log | Files | Refs

volume (901B)


      1 #!/bin/sh
      2 #
      3 # z3bra - (c) wtfpl 2014
      4 
      5 CHANNEL=$(amixer | sed "1s/^.*'\(.*\)'.*$/\1/p;d")
      6 
      7 usage () {
      8 	cat <<EOF
      9 usage: $(basename $0) [-hsla] [-+!]
     10 	-h : print help
     11 	-s : print on/off
     12 	-l : print the current volume percentage (default)
     13 	-a : print both level and state
     14 	+  : volume +5%
     15 	-  : volume -5%
     16 	!  : toggle mute
     17 EOF
     18 }
     19 
     20 level() {
     21 	amixer get $CHANNEL | sed -n 's/^.*\[\([0-9]\+\)%.*$/\1/p' | uniq
     22 }
     23 
     24 state() {
     25 	amixer get $CHANNEL | sed -n 's/^.*\[\(o[nf]\+\)]$/\1/p' | uniq
     26 }
     27 
     28 # print out level and state if no argument is given
     29 test $# -eq 0 && echo "`level`" && exit 0
     30 
     31 case $1 in
     32 	-h)       usage ;;
     33 	-s)       state ;;
     34 	-l)       level ;;
     35 	up|+)     amixer set $CHANNEL 5%+ >/dev/null;;
     36 	down|-)   amixer set $CHANNEL 5%- >/dev/null;;
     37 	toggle|!) amixer set $CHANNEL toggle >/dev/null;;
     38 	X)        amixer set Capture toggle >/dev/null;;
     39 	*)        amixer set $CHANNEL $1 >/dev/null;;
     40 esac