Commit 54179ca3 authored by Glen Mével's avatar Glen Mével

`bell` can now take arguments

parent 0b14fd8a
#!/bin/sh
# Usage:
# bell [percent [pitch [duration]]]
# Rings the bell.
# Volume (in percents) to use when none is given and the bell is muted:
DEFAULT_VOLUME=50
# This script depends on the program “xset”.
command -V xset >/dev/null || return 1
function is_integer() {
case "$1" in
*[!0-9]*) return 1 ;;
*) return 0 ;;
esac
}
is_integer "$1" && is_integer "$2" && is_integer "$3" && [ "$#" -le 3 ] || {
echo>&2 'Bad argument'
exit 1
}
percent="$1"
pitch="$2"
duration="$3"
# Save the bell settings.
settings=( $(xset -q | grep bell | grep -o '[0-9]*') )
# Activate the bell if needed.
xset b "${settings[0]/#0/50}"
# Set up the bell.
: "${percent:="${settings[0]/#0/"$DEFAULT_VOLUME"}"}"
: "${pitch:="${settings[1]}"}"
: "${duration:="${settings[2]}"}"
xset b "$percent" "$pitch" "$duration"
# Ring the bell.
echo -ne '\a'
# Restore the bell settings.
xset b "${settings[@]}"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment