aboutsummaryrefslogtreecommitdiffstats
path: root/_bin/volume.sh
diff options
context:
space:
mode:
authorAaron LI <aaronly.me@gmail.com>2016-01-08 21:11:52 +0800
committerAaron LI <aaronly.me@gmail.com>2016-01-08 21:11:52 +0800
commite879719e6644cdace1e794e5471eedfb3b882310 (patch)
tree3793565d8f55fd96ddf0c2e143c1961424eb6cc4 /_bin/volume.sh
parent809155c33e7986cc1ff87781cc5892e7d534a589 (diff)
downloaddotfiles-e879719e6644cdace1e794e5471eedfb3b882310.tar.bz2
Add scripts `volume.sh` and `music-player.sh`
* `volume.sh`: support Linux (amixer/ALSA) and FreeBSD/DragonFly (mixer) * `music-player.sh`: support mpd and mocp
Diffstat (limited to '_bin/volume.sh')
-rwxr-xr-x_bin/volume.sh78
1 files changed, 78 insertions, 0 deletions
diff --git a/_bin/volume.sh b/_bin/volume.sh
new file mode 100755
index 0000000..f8558d9
--- /dev/null
+++ b/_bin/volume.sh
@@ -0,0 +1,78 @@
+#!/bin/sh
+#
+# Volume control wrapper to support different systems.
+#
+# Aaron LI
+# Created: 2016-01-07
+# Updated: 2016-01-07
+#
+
+# ALSA device/driver (Linux)
+ALSA_DEV="Master"
+# OSS device (FreeBSD/DragonFly)
+OSS_DEV="vol"
+
+
+if [ $# -ne 1 ]; then
+ echo "Usage:"
+ echo " `basename $0` < +% | -% | toggle | mute | unmute >"
+ exit 1
+fi
+
+
+# amixer: Linux ALSA
+vol_amixer() {
+ case "$1" in
+ toggle)
+ amixer set ${ALSA_DEV} toggle
+ ;;
+ mute)
+ amixer set ${ALSA_DEV} mute
+ ;;
+ unmute)
+ amixer set ${ALSA_DEV} unmute
+ ;;
+ +[1-9]*|-[1-9]*)
+ sign=`echo "$1" | cut -c1`
+ value="${1#?}"
+ amixer set ${ALSA_DEV} "${value}%${sign}" unmute
+ ;;
+ *)
+ echo "ERROR: amixer: unknown control command"
+ exit 11
+ ;;
+ esac
+}
+
+
+# mixer: FreeBSD/DragonFly OSS
+vol_mixer() {
+ # FIXME: how to toggle/mute/unmute ???
+ case "$1" in
+ +[1-9]*|-[1-9]*)
+ sign=`echo "$1" | cut -c1`
+ value="${1#?}"
+ mixer ${OSS_DEV} "${sign}${value}:${sign}${value}"
+ ;;
+ *)
+ echo "ERROR: mixer: unknown control command"
+ exit 21
+ ;;
+ esac
+}
+
+
+OS=`uname -s`
+case "${OS}" in
+ Linux)
+ vol_amixer "$1"
+ ;;
+ FreeBSD|DragonFly)
+ vol_mixer "$1"
+ ;;
+ *)
+ echo "ERROR: currently unsupport operating system"
+ exit 2
+ ;;
+esac
+