-
#!/bin/bash
-
-
function usage() {
-
pro=$(basename $0)
-
echo "Welcome to $pro, version 0.1"
-
echo "code by slucx(slucx@sina.com)"
-
echo "$pro [inside/outside/all/toggle/help]"
-
echo "arguments:"
-
echo -e "\t inside - use inside monitor"
-
echo -e "\t outside - use outside monitor"
-
echo -e "\t all - use both inside and outside monitors"
-
echo -e "\t toggle - toggle the monitor"
-
echo -e "\t help - print this document"
-
}
-
-
# set backgroud
-
eval $(cat ~/.fehbg)
-
-
# vars
-
inside=0
-
outside=1
-
all=2
-
mm="/tmp/monitor.chg"
-
-
# devices
-
dev_inside="LVDS1"
-
if [[ $(xrandr | grep "HDMI1 connected") ]]; then
-
dev_outside="HDMI1"
-
elif [[ $(xrandr | grep "VGA1 connected") ]]; then
-
dev_outside="VGA1"
-
else
-
dev_outside=$dev_inside
-
fi
-
-
# if not exist, create it
-
[[ -f $mm ]] || echo $inside > $mm
-
-
# set value
-
v=$(cat $mm)
-
if [ $# == 1 ]; then
-
case $1 in
-
"inside")
-
[ $v == $inside ] && exit
-
v=$inside
-
echo $inside > $mm
-
;;
-
"outside")
-
[ $v == $outside ] && exit
-
v=$outside
-
echo $outside > $mm
-
;;
-
"all")
-
[ $v == $all ] && exit
-
v=$all
-
echo $all > $mm
-
;;
-
"toggle")
-
v=$(($v + 1))
-
[[ $v -le $outside ]] || v=$inside
-
echo $v > $mm
-
;;
-
"help")
-
usage
-
exit
-
;;
-
*)
-
echo "Unknown command '$1'..."
-
usage
-
exit
-
;;
-
esac
-
elif [ $# == 0 ]; then # use outside monitor first
-
v=$outside
-
echo $outside > $mm
-
fi
-
-
# change monitor
-
case $v in
-
$all)
-
if [ "$dev_outside"x != "$dev_inside"x ]; then
-
echo "using all"
-
xrandr --output $dev_outside --left-of $dev_inside --auto --output $dev_inside --auto
-
fi
-
;;
-
$outside)
-
if [ "$dev_outside"x != "$dev_inside"x ]; then
-
echo "using outside monitor"
-
xrandr --output $dev_outside --auto --output $dev_inside --off
-
fi
-
;;
-
$inside)
-
echo "using inside monitor"
-
xrandr --output $dev_inside --auto
-
if [ "$dev_outside"x != "$dev_inside"x ]; then
-
xrandr --output $dev_outside --off
-
fi
-
;;
-
*)
-
;;
-
esac
用法: 假设脚本名称为monitor.sh
monitor.sh inside 使用内部显示器
monitor.sh outside 使用外部显示器
monitor.sh all 同时使用,外部显示器在左
monitor.sh 尝试优先使用外部显示器
monitor.sh toggle 切换内部和外部显示器
注:显示器设备名称可能不一致,具体的可以通过xrandr查询
阅读(1199) | 评论(0) | 转发(0) |