From e879719e6644cdace1e794e5471eedfb3b882310 Mon Sep 17 00:00:00 2001 From: Aaron LI Date: Fri, 8 Jan 2016 21:11:52 +0800 Subject: 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 --- _bin/volume.sh | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100755 _bin/volume.sh (limited to '_bin/volume.sh') 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 + -- cgit v1.2.2