From fbccd6f7b15563abb982589d8e0e1acce3bd5427 Mon Sep 17 00:00:00 2001 From: ktyl Date: Tue, 13 Dec 2022 23:28:59 +0000 Subject: [PATCH] cycle keyboard language with mod shift l --- .config/sxhkd/sxhkdrc | 6 ++---- .scripts/lang/kbnext | 30 ++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 4 deletions(-) create mode 100755 .scripts/lang/kbnext diff --git a/.config/sxhkd/sxhkdrc b/.config/sxhkd/sxhkdrc index 49a4924..aea960e 100644 --- a/.config/sxhkd/sxhkdrc +++ b/.config/sxhkd/sxhkdrc @@ -10,10 +10,8 @@ super + shift + s $SCRIPTS/ss -Dosu # languages -super + shift + e - $SCRIPTS/lang/kben -super + shift + f - $SCRIPTS/lang/kbfr +super + shift + l + $SCRIPTS/lang/kbnext # # screen backlight diff --git a/.scripts/lang/kbnext b/.scripts/lang/kbnext new file mode 100755 index 0000000..2cc9d4d --- /dev/null +++ b/.scripts/lang/kbnext @@ -0,0 +1,30 @@ +#!/bin/bash + +# First, we check if the file that keeps track of the number of times the script +# has been run exists. If not, we create it and initialize it to 0. +state_file="$HOME/.cache/.kbnext_idx" + +if [ ! -f $state_file ]; then + touch $state_file + echo 0 > $state_file +fi + +# Next, we read the current value in the file and store it in a variable. +num_runs=$(<$state_file) + +# Then, we check if the number of times the script has been run is even or odd. +# If it is even, we run the first command. If it is odd, we run the second command. +if (( num_runs % 2 == 0 )); then + # Run the first command here. + # For example: + kben +else + # Run the second command here. + # For example: + kbfr +fi + +# Finally, we increment the value in the file by 1 to keep track of the number of +# times the script has been run. +((num_runs++)) +echo $num_runs > $state_file