Last active
January 1, 2025 09:25
-
-
Save kawsaramin101/aa3ae00656a09df56bd7df204ea3f992 to your computer and use it in GitHub Desktop.
Bash script to toggle between Ibus input methods. Useful in Wayland because wayland doesn't support global shortcuts for apps. Set a keyboard shortcut (eg: meta+space) to run this script. Don't forget to run "chmod +x ibus-toggle.sh" before running the script.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Get the installed engines from ibus config | |
engines_raw=$(ibus read-config | grep "preload-engines") | |
engines=$(echo "$engines_raw" | sed -E "s/preload-engines: \['(.*)'\]/\1/" | tr "," "\n" | tr -d "' ") | |
# Convert installed engines into an array | |
methods=() | |
while IFS= read -r line; do | |
methods+=("$line") | |
done <<< "$engines" | |
# Get current input method | |
current=$(ibus engine) | |
# Find the current index in the methods array | |
for i in "${!methods[@]}"; do | |
if [[ "${methods[$i]}" == "$current" ]]; then | |
current_index=$i | |
break | |
fi | |
done | |
# Calculate the next index | |
next_index=$(( (current_index + 1) % ${#methods[@]} )) | |
# Switch to the next input method | |
ibus engine "${methods[$next_index]}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment