Add IME hotkey command with menu-key migration and conflict detection
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QKxGW1raAWaqeU8WdHsMsp
This commit is contained in:
@@ -11,7 +11,7 @@ module="all"
|
|||||||
fix="false"
|
fix="false"
|
||||||
for arg in "$@"; do
|
for arg in "$@"; do
|
||||||
case "$arg" in
|
case "$arg" in
|
||||||
all | network | mirror | dev-mirror) module="$arg" ;;
|
all | network | mirror | dev-mirror | ime) module="$arg" ;;
|
||||||
--fix) fix="true" ;;
|
--fix) fix="true" ;;
|
||||||
*)
|
*)
|
||||||
echo "Unknown argument: $arg" >&2
|
echo "Unknown argument: $arg" >&2
|
||||||
@@ -73,14 +73,20 @@ check_dev_mirror() {
|
|||||||
omarchy-cn-dev-mirror-doctor || failures=$((failures + 1))
|
omarchy-cn-dev-mirror-doctor || failures=$((failures + 1))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
check_ime() {
|
||||||
|
omarchy-cn-ime-status || failures=$((failures + 1))
|
||||||
|
}
|
||||||
|
|
||||||
case "$module" in
|
case "$module" in
|
||||||
network) check_network ;;
|
network) check_network ;;
|
||||||
mirror) check_mirror ;;
|
mirror) check_mirror ;;
|
||||||
dev-mirror) check_dev_mirror ;;
|
dev-mirror) check_dev_mirror ;;
|
||||||
|
ime) check_ime ;;
|
||||||
all)
|
all)
|
||||||
check_network
|
check_network
|
||||||
check_mirror
|
check_mirror
|
||||||
check_dev_mirror
|
check_dev_mirror
|
||||||
|
check_ime
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
|||||||
Executable
+61
@@ -0,0 +1,61 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# omarchy:summary=Set the input method toggle key, migrating the menu key if needed
|
||||||
|
# omarchy:args=<ctrl-space|super-space>
|
||||||
|
# omarchy:examples=omarchycn ime hotkey ctrl-space | omarchycn ime hotkey super-space
|
||||||
|
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
choice="${1:?usage: omarchycn ime hotkey <ctrl-space|super-space>}"
|
||||||
|
fcitx_config="$HOME/.config/fcitx5/config"
|
||||||
|
bindings="$HOME/.config/hypr/bindings.lua"
|
||||||
|
|
||||||
|
# Replace or append the [Hotkey/TriggerKeys] section in fcitx5 global config
|
||||||
|
set_trigger() {
|
||||||
|
local key="$1"
|
||||||
|
|
||||||
|
mkdir -p "${fcitx_config%/*}"
|
||||||
|
touch "$fcitx_config"
|
||||||
|
awk '
|
||||||
|
/^\[Hotkey\/TriggerKeys\]$/ { skip = 1; next }
|
||||||
|
/^\[/ { skip = 0 }
|
||||||
|
!skip { print }
|
||||||
|
' "$fcitx_config" > "$fcitx_config.omarchycn-tmp"
|
||||||
|
printf '[Hotkey/TriggerKeys]\n0=%s\n' "$key" >> "$fcitx_config.omarchycn-tmp"
|
||||||
|
mv "$fcitx_config.omarchycn-tmp" "$fcitx_config"
|
||||||
|
}
|
||||||
|
|
||||||
|
remove_menu_migration() {
|
||||||
|
if [[ -f $bindings ]]; then
|
||||||
|
sed -i '/^-- OmarchyCN ime hotkey begin$/,/^-- OmarchyCN ime hotkey end$/d' "$bindings"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
case "$choice" in
|
||||||
|
ctrl-space)
|
||||||
|
set_trigger "Control+space"
|
||||||
|
remove_menu_migration
|
||||||
|
echo "输入法切换键: Ctrl+Space(Omarchy 菜单保持 Super+Space)"
|
||||||
|
;;
|
||||||
|
super-space)
|
||||||
|
set_trigger "Super+space"
|
||||||
|
mkdir -p "${bindings%/*}"
|
||||||
|
touch "$bindings"
|
||||||
|
remove_menu_migration
|
||||||
|
cat >> "$bindings" <<'EOF'
|
||||||
|
-- OmarchyCN ime hotkey begin
|
||||||
|
hl.unbind("SUPER + SPACE")
|
||||||
|
o.bind("SUPER + ALT + SPACE", "Omarchy menu", "omarchy-menu toggle")
|
||||||
|
-- OmarchyCN ime hotkey end
|
||||||
|
EOF
|
||||||
|
echo "输入法切换键: Super+Space"
|
||||||
|
echo "Omarchy 菜单已迁移至 Super+Alt+Space(写入 $bindings)"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "Unknown hotkey choice: $choice (expected ctrl-space or super-space)" >&2
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
if systemctl --user is-active omarchy-fcitx5.service > /dev/null 2>&1; then
|
||||||
|
systemctl --user restart omarchy-fcitx5.service
|
||||||
|
fi
|
||||||
@@ -37,6 +37,14 @@ else
|
|||||||
failures=$((failures + 1))
|
failures=$((failures + 1))
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
trigger=$(grep -sA2 '^\[Hotkey/TriggerKeys\]' "$HOME/.config/fcitx5/config" | grep -sE '^0=' | cut -d= -f2- || true)
|
||||||
|
if [[ $trigger == "Super+space" ]] && ! grep -sq 'OmarchyCN ime hotkey begin' "$HOME/.config/hypr/bindings.lua"; then
|
||||||
|
echo "FAIL ime: Super+space 与 Omarchy 菜单冲突 (run: omarchycn ime hotkey super-space)"
|
||||||
|
failures=$((failures + 1))
|
||||||
|
else
|
||||||
|
echo "PASS ime: trigger key ${trigger:-Control+space (fcitx5 default)}"
|
||||||
|
fi
|
||||||
|
|
||||||
if pgrep -x fcitx5 > /dev/null 2>&1; then
|
if pgrep -x fcitx5 > /dev/null 2>&1; then
|
||||||
echo "PASS ime: fcitx5 running"
|
echo "PASS ime: fcitx5 running"
|
||||||
else
|
else
|
||||||
|
|||||||
Reference in New Issue
Block a user