Advertisement
Y99drasil

dvol

Mar 1st, 2013
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VIM 2.37 KB | None | 0 0
  1. lbar - OSD Volume utility
  2. #
  3.  
  4. #Customize this stuff
  5. IF="Master"         # audio channel: Master|PCM
  6. SECS="1"            # sleep $SECS
  7. BG="#111111"        # background colour of window
  8. FG="#eeeeee"        # foreground colour of text/icon
  9. BAR_FG="#ffffff"    # foreground colour of volume bar
  10. BAR_BG="#777777"    # background colour of volume bar
  11. XPOS="595"          # horizontal positioning
  12. YPOS="435"          # vertical positioning
  13. HEIGHT="30"         # window height
  14. WIDTH="250"         # window width
  15. BAR_WIDTH="165"     # width of volume bar
  16. ICON=~/.dzen2/thayer/vol-hi.xbm
  17. FONT="-*-terminus-medium-r-*-*-14-*-*-*-*-*-*-*"
  18. ICON_VOL=~/.dzen2/thayer/vol-hi.xbm
  19. ICON_VOL_MUTE=~/vol-mute.xbm
  20. ICON=$ICON_VOL
  21.  
  22. #Probably do not customize
  23. PIPE="/tmp/dvolpipe"
  24.  
  25. err() {
  26.   echo "$1"
  27.   exit 1
  28. }
  29.  
  30. usage() {
  31.   echo "usage: dvol [option] [argument]"
  32.   echo
  33.   echo "Options:"
  34.   echo "     -i, --increase - increase volume by \`argument'"
  35.   echo "     -d, --decrease - decrease volume by \`argument'"
  36.   echo "     -t, --toggle   - toggle mute on and off"
  37.   echo "     -h, --help     - display this"
  38.   exit
  39. }  
  40.    
  41. #Argument Parsing
  42. case "$1" in
  43.   '-i'|'--increase')
  44.     [ -z "$2" ] && err "No argument specified for increase."
  45.     [ -n "$(tr -d [0-9] <<<$2)" ] && err "The argument needs to be an integer."
  46.     AMIXARG="${2}%+"
  47.     ;;
  48.   '-d'|'--decrease')
  49.     [ -z "$2" ] && err "No argument specified for decrease."
  50.     [ -n "$(tr -d [0-9] <<<$2)" ] && err "The argument needs to be an integer."
  51.     AMIXARG="${2}%-"
  52.     ;;
  53.   '-t'|'--toggle')
  54.     AMIXARG="toggle"
  55.     ;;
  56.   ''|'-h'|'--help')
  57.     usage
  58.     ;;
  59.   *)
  60.     err "Unrecognized option \`$1', see dvol --help"
  61.     ;;
  62. esac
  63.  
  64. #Actual volume changing (readability low)
  65. AMIXOUT="$(amixer set "$IF" "$AMIXARG" | tail -n 1)"
  66. MUTE="$(cut -d '[' -f 4 <<<"$AMIXOUT")"
  67. VOL="$(cut -d '[' -f 2 <<<"$AMIXOUT" | sed 's/%.*//g')"
  68. if [ "$MUTE" = "off]" ]; then
  69.   ICON=$ICON_VOL_MUTE
  70. else
  71.   ICON=$ICON_VOL
  72. fi
  73.  
  74. #Using named pipe to determine whether previous call still exists
  75. #Also prevents multiple volume bar instances
  76. if [ ! -e "$PIPE" ]; then
  77.   mkfifo "$PIPE"
  78.   (dzen2 -tw "$WIDTH" -h "$HEIGHT" -x "$XPOS" -y "$YPOS" -fn "$FONT" -bg "$BG" -fg "$FG" < "$PIPE"
  79.    rm -f "$PIPE") &
  80. fi
  81.  
  82. #Feed the pipe!
  83. (echo "$VOL" | gdbar -l "^i(${ICON}) " -fg "$BAR_FG" -bg "$BAR_BG" -w "$BAR_WIDTH" ; sleep "$SECS") > "$PIPE"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement