答案1
下面是我编写的用于动态设置值的 bash 脚本。要使用,请将脚本放入〜/ bin / trackpoint(用户箱)或/usr/bin/指点杆(全局 bin)并使其可执行。
trackpoint <option>
获取价值trackpoint <option> <value>
设置值trackpoint --values
获取所有选项值的列表trackpoint --help
获取选项列表(仅是 $tp_root 中的文件列表)。
在 Ubuntu 14.04 上测试。调用sudo
将值写入文件。
#!/bin/bash
# trackpoint
# Gets or sets a trackpoint configuration option
# Example - get sensitivity:
# trackpoint sensitivity
# Example - set sensitivity to 160:
# trackpoint sensitivity 160
# tp_root locator command from http://askubuntu.com/a/144185/151944
tp_root=`find /sys/devices/platform/i8042 -name name | xargs grep -Fl TrackPoint | sed 's/\/input\/input[0-9]*\/name$//'`
option=$1
value=$2
me=`basename $0`
fail() { echo "Error: $@" 1>&2; exit 1; }
[ -d ${tp_root} ] || fail "Invalid tp_root: ${tp_root}"
option_list=`find ${tp_root} -maxdepth 1 -type f -printf '%f '`;
[ ${option} ] || fail "please provide an option to set or get. Option must be one of: ${option_list}"
[[ ${option} == *--help* ]] && { echo -e "Usage: ${me} option_name [value_to_set]\n\nGets or sets a trackpoint option.\n\nTo get a list of all values use:\n ${me} --values\n\nAvailable options:\n ${option_list}"; exit 0; }
[[ ${option} == *--values* ]] && { for f in `find ${tp_root} -maxdepth 1 -type f -printf '%f '`; do { echo $f; echo " $(cat ${tp_root}/${f})"; } done; exit 0; }
file="${tp_root}/${option}"
[ -f ${file} ] || fail "option must be one of: ${option_list}"
[ -z ${value} ] && { cat ${file}; exit 0; }
[ ${value} -gt 255 ] && fail "$option cannot be greater than 255"
echo -n ${value}| sudo tee ${file}
echo ""