2022-09-06 23:34:19 -06:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
# Usage: ./switch_keyboards.sh [args]
|
|
|
|
#
|
|
|
|
# Args:
|
|
|
|
# console Loads the console version
|
|
|
|
# mac Loads the Mac keyboard version
|
|
|
|
# pc Loads the standard keyboard version
|
2023-01-01 13:26:25 -07:00
|
|
|
# fn Loads the version for a standard keyboard without an fn row
|
2022-09-06 23:34:19 -06:00
|
|
|
#
|
|
|
|
# Explanation =========
|
|
|
|
# Mac keyboards place their super key adjacent to the spacebar, while standard
|
|
|
|
# keyboards put alt in that spot:
|
|
|
|
#
|
|
|
|
# Macbook: Shift | z
|
|
|
|
# Fn | Ctrl | Alt | Super | Space
|
|
|
|
#
|
|
|
|
# Standard: Shift | z
|
|
|
|
# Fn | Ctrl | Super | Alt | Space
|
|
|
|
#
|
|
|
|
# To preserve consistency when switching keyboards, two versions of the same
|
|
|
|
# xremap config.yml are available. This script toggles between the two
|
|
|
|
#
|
|
|
|
# Xremap can also run in a non-graphical console. For this we don't need to
|
|
|
|
# remap Super and Alt, though we still need other keys, like capslock. An
|
|
|
|
# optional "console" argument can be passed to this script to load
|
|
|
|
# config_console.yml
|
|
|
|
print_help() {
|
|
|
|
cat <<HELP
|
|
|
|
Switches keyboard modifer keys between Mac and PC layouts
|
|
|
|
|
|
|
|
USAGE: $(basename "$0") <ARG>
|
|
|
|
|
|
|
|
ARGS:
|
|
|
|
mac Remaps assuming super is adjacent to the spacebar
|
|
|
|
pc Remaps assuming alt is adjacent to the spacebar
|
2023-01-01 13:26:25 -07:00
|
|
|
fn Remaps assuming pc + no fn row
|
2022-09-06 23:34:19 -06:00
|
|
|
console Only remaps capslock to ctrl
|
|
|
|
help Print this message and exit
|
|
|
|
HELP
|
|
|
|
}
|
|
|
|
|
|
|
|
if ! command -v xremap &>/dev/null; then
|
|
|
|
printf "xRemap not found\nLayouts were not switched\n"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2023-01-08 15:57:38 -07:00
|
|
|
declare path sw_type="$1"
|
|
|
|
|
|
|
|
case "$(echo "$sw_type" | awk '{print tolower($0)}')" in
|
2022-09-06 23:34:19 -06:00
|
|
|
console)
|
|
|
|
ln -sf ~/.config/xremap/config_console.yml ~/.config/xremap/config.yml
|
|
|
|
;;
|
|
|
|
mac)
|
|
|
|
ln -sf ~/.config/xremap/config_mac.yml ~/.config/xremap/config.yml
|
|
|
|
;;
|
2023-01-01 13:26:25 -07:00
|
|
|
pc | standard)
|
2022-09-06 23:34:19 -06:00
|
|
|
ln -sf ~/.config/xremap/config_standard.yml ~/.config/xremap/config.yml
|
|
|
|
;;
|
2023-01-01 13:26:25 -07:00
|
|
|
fn | small | mini)
|
|
|
|
ln -sf ~/.config/xremap/config_no_fn.yml ~/.config/xremap/config.yml
|
|
|
|
;;
|
2022-09-06 23:34:19 -06:00
|
|
|
*)
|
2022-11-10 00:01:06 -07:00
|
|
|
if [[ -n "$1" ]]; then
|
|
|
|
print_help
|
|
|
|
exit 0
|
|
|
|
fi
|
2022-09-06 23:34:19 -06:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2023-01-08 15:57:38 -07:00
|
|
|
if path="$(basename "$(realpath ~/.config/xremap/config.yml)")"; then
|
|
|
|
case "$path" in
|
|
|
|
config_console.yml)
|
|
|
|
echo "Using minimal console remapping";;
|
|
|
|
config_mac.yml)
|
|
|
|
echo "Using mac layout :: ALT | SUPER | SPACE";;
|
|
|
|
config_standard.yml)
|
|
|
|
echo "Using standard layout :: ALT | SUPER | SPACE";;
|
|
|
|
config_no_fn.yml)
|
|
|
|
echo "Using standard no-fn row layout :: ALT | SUPER | SPACE";;
|
|
|
|
*)
|
|
|
|
echo "Using unidentified layout";;
|
|
|
|
esac
|
|
|
|
else
|
|
|
|
echo "xremap config path not found"
|
|
|
|
fi
|
|
|
|
|
2023-01-08 15:40:57 -07:00
|
|
|
sudo /usr/bin/systemctl restart xremap.service
|
2022-09-06 23:34:19 -06:00
|
|
|
sleep 2
|