multilib is correct now
[dcc-suckless-config] / bashs / shell scrips / keyboardlayoutswitcher.sh
1 #!/bin/bash
2
3 numberofparameter=$#                                                # Gets the number of parameter passed
4 currentlayout=$(setxkbmap -query | grep layout | awk '{print $2}')  # Gets the current layout
5 langLayout=($*)                                                     # Passes the parameters into an array
6
7 i=0
8
9 while [[ "$i" -lt "$numberofparameter" ]]; do
10   if [[ "${langLayout[$i]}" == "${currentlayout}" ]]; then
11     break
12   fi
13   i=$(($i+1))
14 done
15
16 # checks if i has not reached to the last parameter (last language)
17 if [[ "$i" -lt "(($numberofparameter-1))" ]]; then
18   # Sets to next parameter (next language)
19   setxkbmap -layout ${langLayout[$(($i+1))]} && notify-send --icon /usr/share/icons/Dracula/apps/scalable/key_bindings.svg "Keyboard Layout" "Keyboard set to ${langLayout[$(($i+1))]}" || notify-send --icon /usr/share/icons/Dracula/apps/scalable/key_bindings.svg "Keyboard Layout" "Something went wrong :/"
20 else
21   # Has reached the end, so looping back to the first parameter (first language)
22   setxkbmap -layout $1 && notify-send --icon /usr/share/icons/Dracula/apps/scalable/key_bindings.svg "Keyboard Layout" "Keyboard set to $1" || notify-send --icon /usr/share/icons/Dracula/apps/scalable/key_bindings.svg "Keyboard Layout" "Something went wrong :/"
23 fi