Created
August 17, 2009 10:29
-
-
Save bigsmoke/169034 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
HAL_FILE=/etc/hal/fdi/policy/99-x11-synaptics.fdi | |
VERBOSITY_LEVEL=2 | |
usage() | |
{ | |
cat <<EOF | |
Usage: $0 options | |
OPTIONS: | |
--verbosity [level] Control the level of output processed by the script. | |
Level 0: No output at all | |
Level 1: Only output changed options | |
Level 2: Only output options set in the configuration file | |
Level 3: Output all options | |
--verbose Shortcut for verbosity level 3 | |
--help Show this help | |
EOF | |
exit 1 | |
} | |
options_from_hal_file() | |
{ | |
HAL_SED_FILTER='s%^\s*<merge\s*key="input\.x11_options\.\(.*\?\)"\s*type="string">\(.*\)</merge>%\1=\2%' | |
cat $HAL_FILE \ | |
| grep '<merge key="input.x11_options.' \ | |
| grep -v 'SHMConfig' \ | |
| sed -e $HAL_SED_FILTER | |
} | |
from() | |
{ | |
synclient -l \ | |
| grep '=' \ | |
| sed -e 's/\s//g' \ | |
| while read option; do | |
key=`echo $option|cut -f 1 -d '='` | |
old_val=`echo $option|cut -f 2 -d '='` | |
new_val=`options_from_hal_file|grep $key|cut -f 2 -d '='` | |
if [ -z $new_val ]; then | |
[ $VERBOSITY_LEVEL == 3 ] && echo -e "\e[1;30m$key = $old_val\e[0m" | |
elif [ $old_val != $new_val ]; then | |
[ $VERBOSITY_LEVEL -ge 1 ] && echo -e "\e[1m$key = \e[1;31m$old_val \e[1;4;32m$new_val\e[0m" | |
synclient "$key=$new_val" | |
else # The HAL file and the life configuration are in sync | |
[ $VERBOSITY_LEVEL -ge 2 ] && echo -e "\e[1m$key = \e[4m$new_val\e[0m" | |
fi | |
done | |
} | |
do_from=0 | |
while [ $# -gt 0 ]; do | |
case "$1" in | |
--from-hal) | |
do_from=1 | |
;; | |
--verbose) | |
VERBOSITY_LEVEL=3 | |
;; | |
--verbosity) | |
VERBOSITY_LEVEL=$2 | |
shift | |
;; | |
--help) | |
usage | |
;; | |
esac | |
shift | |
done | |
if [ $do_from == 1 ]; then | |
from | |
else | |
usage | |
fi | |
# vim: set shiftwidth=4 tabstop=4 expandtab: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment