-
Notifications
You must be signed in to change notification settings - Fork 4
/
xrasengan_complete
executable file
·125 lines (104 loc) · 2.87 KB
/
xrasengan_complete
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# -*- mode: sh -*-
#
# Copyright 2015 Geyslan G. Bem
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#
# xrasengan bash completion
#
#!/bin/bash
list_contains() {
local list=$1
local value=$2
for word in $list; do
[[ $word == "$value" ]] && return 0
done
return 1
}
update_outputs_connected() {
if ! [[ $force ]]; then
OPTS="$(xrandr | awk '/ connected/ {print $1}')"
return
fi
# Workaround to turn on connected outputs that may be in suspend mode
# and hence shown as disconnected
local times=2
local seconds=1
while [ $times -gt 0 ]; do
xrandr 1> /dev/null
sleep $seconds
let times-=1
done
OPTS="$(xrandr | awk '/ connected/ {print $1}')"
}
update_outputs_connected_inactive() {
OPTS="$(xrandr | awk '/ connected/ && /\)$/ {print $1}')"
}
update_outputs_active() {
OPTS="$(xrandr | awk '/mm$/ {print $1}')"
}
update_output_modes() {
local output="$1"
OPTS="$(xrandr | awk '/'$output'/ {f=1;next} !/^ /{f=0} f {print $1}')"
}
_xrasengan()
{
local cur prev prev_prev OPTS
COMREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
prev_prev="${COMP_WORDS[COMP_CWORD-2]}"
if list_contains "${COMP_WORDS[*]}" "--force" || list_contains "${COMP_WORDS[*]}" "-f"; then
force="force"
else
force=""
fi
case $cur in
--*)
OPTS=$(echo "--force --force-only --try-reload-active-layout --help --list-all --list-connected --list-active --list-disconnected --clone --turn-on --turn-off --left --right --above --below --primary" | sort)
COMPREPLY=( $(compgen -W "${OPTS[*]}" -- "$cur") )
return 0
;;
-*)
OPTS=$(echo "-f -fo -tral -h -la -lc -lac -ld -c -on -off -l -r -a -b -p" | sort)
COMPREPLY=( $(compgen -W "${OPTS[*]}" -- "$cur") )
return 0
;;
esac
update_outputs_connected
case $prev in
--clone | -c | --turn-off | -off | --left | -l | --right | -r | --above | -a | --below | -b | --primary | -p)
update_outputs_active
COMPREPLY=( $(compgen -W "${OPTS[*]}" -- "$cur") )
return 0
;;
--turn-on | -on)
update_outputs_connected_inactive
COMPREPLY=( $(compgen -W "${OPTS[*]}" -- "$cur") )
return 0
;;
esac
case $prev_prev in
--clone | -c | --left | -l | --right | -r | --above | -a | --below | -b)
COMPREPLY=( $(compgen -W "${OPTS[*]}" -- "$cur") )
return 0
;;
--turn-on | -on)
update_output_modes "$prev"
COMPREPLY=( $(compgen -W "${OPTS[*]}" -- "$cur") )
return 0
;;
esac
}
complete -F _xrasengan xrasengan