-
Notifications
You must be signed in to change notification settings - Fork 0
/
toogle-xinput.sh
executable file
·53 lines (40 loc) · 1.11 KB
/
toogle-xinput.sh
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
#!/bin/bash
notify_timeout=5
# $1=title, $2=message, $3=exit_code
function notify {
de=$DESKTOP_SESSION
if [[ $de = "plasma" ]]
then
kdialog --title "$1" --passivepopup "$2" $notify_timeout &
elif [[ $de = "ubuntu" ]]
then
notify-send -u critical "$1" "$2" -t $(($notify_timeout*1000))
fi
echo -e "$2"
exit $3
}
# if no argument is passed
if [ -z "$1" ]
then
notify "toogle-xinput.sh" " Invalid command.\n Usage: ./toogle-xinput.sh [id]" 1
fi
check_id="$(xinput list | grep "id=$1")"
# if there does not exist any input device corresponding to the given id
if [ -z "$check_id" ]
then
notify "toogle-xinput.sh" " Invalid id.\n Use \"xinput list\" to see available ids." 1
fi
# get enabled status
status="$(xinput list-props $1 | grep "Device Enabled")"
status="${status: -1}"
# regex matching to get the name of input device
pattern='((\w+\s+)+)\s+id=10'
[[ "$(xinput list)" =~ $pattern ]]
if [ $status -eq 0 ]
then
xinput enable $1
notify "toogle-xinput.sh" " Enabled Input: ${BASH_REMATCH[1]}" 0
else
xinput disable $1
notify "toogle-xinput.sh" " Disalbed Input: ${BASH_REMATCH[1]}" 0
fi