From 14b14f24fa65f740e7ef3230399d3745dc2d6d34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9B=B7=E7=94=B5=E8=8A=BD=E8=A1=A3?= Date: Mon, 24 Aug 2026 19:43:35 -0400 Subject: [PATCH] Add IME hotkey command with menu-key migration and conflict detection Co-Authored-By: Claude Fable 5 Claude-Session: https://claude.ai/code/session_01QKxGW1raAWaqeU8WdHsMsp --- bin/omarchy-cn-doctor | 8 ++++- bin/omarchy-cn-ime-hotkey | 61 +++++++++++++++++++++++++++++++++++++++ bin/omarchy-cn-ime-status | 8 +++++ 3 files changed, 76 insertions(+), 1 deletion(-) create mode 100755 bin/omarchy-cn-ime-hotkey diff --git a/bin/omarchy-cn-doctor b/bin/omarchy-cn-doctor index 58cb682f..8580d237 100755 --- a/bin/omarchy-cn-doctor +++ b/bin/omarchy-cn-doctor @@ -11,7 +11,7 @@ module="all" fix="false" for arg in "$@"; do case "$arg" in - all | network | mirror | dev-mirror) module="$arg" ;; + all | network | mirror | dev-mirror | ime) module="$arg" ;; --fix) fix="true" ;; *) echo "Unknown argument: $arg" >&2 @@ -73,14 +73,20 @@ check_dev_mirror() { omarchy-cn-dev-mirror-doctor || failures=$((failures + 1)) } +check_ime() { + omarchy-cn-ime-status || failures=$((failures + 1)) +} + case "$module" in network) check_network ;; mirror) check_mirror ;; dev-mirror) check_dev_mirror ;; +ime) check_ime ;; all) check_network check_mirror check_dev_mirror + check_ime ;; esac diff --git a/bin/omarchy-cn-ime-hotkey b/bin/omarchy-cn-ime-hotkey new file mode 100755 index 00000000..a6873417 --- /dev/null +++ b/bin/omarchy-cn-ime-hotkey @@ -0,0 +1,61 @@ +#!/bin/bash +# omarchy:summary=Set the input method toggle key, migrating the menu key if needed +# omarchy:args= +# omarchy:examples=omarchycn ime hotkey ctrl-space | omarchycn ime hotkey super-space + +set -euo pipefail + +choice="${1:?usage: omarchycn ime hotkey }" +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 diff --git a/bin/omarchy-cn-ime-status b/bin/omarchy-cn-ime-status index 05fc9b59..3cd787f8 100755 --- a/bin/omarchy-cn-ime-status +++ b/bin/omarchy-cn-ime-status @@ -37,6 +37,14 @@ else failures=$((failures + 1)) 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 echo "PASS ime: fcitx5 running" else