[ create a new paste ] login | about

Link: http://codepad.org/VZ4HLaPY    [ raw code | fork ]

Plain Text, pasted on Jul 8:
#!/bin/bash
# Glaucous asoundrc script 2011
# Usage: glakke-asound NUMBER
#
# asoundrc file must contain this (Minus one comment (#)):
## glakke-asound-begin
## Set output names here
## glakke-asound-tv "hw:0,2"
## Don't touch line below
#slave.pcm "live_analog"
## glakke-asound-end
# 
# Using 'glakke-asound tv' would then change the 
# the slave.pcm to "hw:0,2"

if [[ "${1}" = "" ]]; then
	echo "Specify number."	
	exit 0
fi

echo "Input ${1}"

ASOUNDRC="${HOME}/.asoundrc"
TMP_FILE="$(mktemp)"
VAR_PATTERN='glakke-asound-'
OUTPUT_PATTERN='slave.pcm'
END_PATTERN='glakke-asound-end'

# Get line number of output line
OUTPUT_LINE="$(grep -n ${END_PATTERN} .asoundrc | cut -f1 -d:)"
let "OUTPUT_LINE--"
# Get the ALSA device name
OUTPUT_VAR="$(cat ${ASOUNDRC} | grep ${VAR_PATTERN}${1} | awk '{ print $3 }')"

echo "TMP: ${TMP_FILE}"

if [[ "$OUTPUT_VAR" = "" ]]; then
	echo "Variable $1 doesn't exist."
	rm ${TMP_FILE}
	exit 0
fi

echo "Chosen: ${OUTPUT_VAR}"

# Output to TMP
sed "${OUTPUT_LINE} c ${OUTPUT_PATTERN} ${OUTPUT_VAR}" "${ASOUNDRC}" > "${TMP_FILE}"

echo "Moving tmp file.."

# Move TMP to .asoundrc
mv ${TMP_FILE} ${ASOUNDRC}

echo "done"


Create a new paste based on this one


Comments: