-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.zshrc.laptop
104 lines (94 loc) · 2.28 KB
/
.zshrc.laptop
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# smon: sway monitor
# Usage: smon - auto switch
# smon m - use both monitors
smon(){
local arr=(`swaymsg -pt get_outputs | grep '^Output' | cut -d ' ' -f 2`)
if (( $#arr < 1 )) ; then
echo "0 monitor detected!" >&2
return 1
elif (( $#arr == 1 )) ; then
swaymsg "output $arr[1] enable"
swaymsg "output $arr[1] pos 0 0 res 1920x1080"
return 0
fi
arr=('DP-1' 'eDP-1')
if (( $# < 1 )) ; then
for i in $arr ; do
swaymsg "output $i disable"
done
swaymsg "output $arr[1] enable"
swaymsg "output $arr[1] pos 0 0 res 1920x1080"
elif [ "x$#" = "x1" ] && [ "$1" = "m" ] ; then
for i in $arr ; do
swaymsg "output $i disable"
done
swaymsg "output $arr[1] enable"
swaymsg "output $arr[2] enable"
swaymsg "output $arr[2] pos 0 1080 res 1920x1080"
swaymsg "output $arr[1] pos 0 0 res 1920x1080"
else
echo "invalid argument!" >&2
return 1
fi
}
# xas - xrandr auto switch
# Used to switch between monitors
# Usage:
# xas 0 - switch to main monitor (laptop's screen)
# xas 1 - switch to extra monitor
# xas 01 - switch to both monitor, 'xas 10' is the same
xas(){
local arr=(`xrandr | grep -P '(?<!dis)connected' | awk '{print $1}'`)
if (( $#arr < 1 )) ; then
echo "0 monitor detected!" >&2
return 1
fi
local switch_to_main(){
xrandr --output $arr[1] --auto
for i in ${arr[*]:1} ; do
xrandr --output $i --off
done
}
local switch_to_extra(){
if (( $#arr < 2 )) ; then
echo "Less than 2 monitors!" >&2
return 1
fi
xrandr --output $arr[1] --off
xrandr --output $arr[2] --auto
for i in ${arr[*]:2} ; do
xrandr --output $i --off
done
}
local switch_to_both(){
if (( $#arr < 2 )) ; then
echo "Less than 2 monitors!" >&2
return 1
fi
#xrandr --output $arr[1] --off
#xrandr --output $arr[2] --off
xrandr --output $arr[2] --auto --pos 0x0
xrandr --output $arr[1] --auto --pos 0x1080
for i in ${arr[*]:2} ; do
xrandr --output $i --off
done
}
case "x$1" in
x0)
switch_to_main ;;
x1)
switch_to_extra ;;
x01) ;&
x10)
switch_to_both ;;
x)
if (( $#arr == 1 )) ; then
switch_to_main
elif (( $#arr > 1 )) ; then
switch_to_extra
fi
;;
*)
echo 'Invalid input!' >&2
esac
}