├── screenshots ├── en.png ├── rime.png ├── en_uppercase.png └── rime_uppercase.png ├── README.md └── polybar-fcitx5-script.sh /screenshots/en.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bincat233/polybar-fcitx5-script/HEAD/screenshots/en.png -------------------------------------------------------------------------------- /screenshots/rime.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bincat233/polybar-fcitx5-script/HEAD/screenshots/rime.png -------------------------------------------------------------------------------- /screenshots/en_uppercase.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bincat233/polybar-fcitx5-script/HEAD/screenshots/en_uppercase.png -------------------------------------------------------------------------------- /screenshots/rime_uppercase.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bincat233/polybar-fcitx5-script/HEAD/screenshots/rime_uppercase.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # polybar-fcitx5-script.sh 2 | 3 | A script to show Fcitx5 status. Fork from `polybar-fcitx-scripts` on ArchLinux AUR and I can't find it now. I adapt it to fcitx5. 4 | 5 | ![](./screenshots/en.png) 6 | ![](./screenshots/en_uppercase.png) 7 | ![](./screenshots/rime.png) 8 | ![](./screenshots/rime_uppercase.png) 9 | 10 | # Setup 11 | 12 | Copy `polybar-fcitx5-script.sh` to your `~/.config/polybar` folder and add this to your config file: 13 | 14 | ``` ini 15 | [module/fcitx] 16 | type = custom/script 17 | exec = ~/.config/polybar/polybar-fcitx5-script.sh 18 | tail = true 19 | interval = 0 20 | format-prefix = "KBD" 21 | ``` 22 | 23 | You can replace `format-prefix` with the symbol you like. 24 | 25 | If you want to change the up arrow that indicates uppercase into another symbol, modify `CAPS_SYMBOL` in the script. 26 | -------------------------------------------------------------------------------- /polybar-fcitx5-script.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | CAPS_SYMBOL="%{F#c0392b}⇧%{F-}" 4 | IMLIST_FILE="/tmp/fcitx5-imlist" 5 | 6 | capslock() { 7 | xset -q | grep Caps | grep -q on && { 8 | echo on 9 | return 0 10 | } || { 11 | echo off 12 | return 1 13 | } 14 | } 15 | 16 | # Print out identifier of current input method 17 | current() { 18 | dbus-send --session --print-reply \ 19 | --dest=org.fcitx.Fcitx5 \ 20 | /controller \ 21 | org.fcitx.Fcitx.Controller1.CurrentInputMethod \ 22 | | grep -Po '(?<=")[^"]+' 23 | } 24 | 25 | # List all input methods added to Fcitx 26 | imlist() { 27 | if [ ! -f "${IMLIST_FILE}" ]; then 28 | dbus-send --session --print-reply \ 29 | --dest=org.fcitx.Fcitx5 \ 30 | /controller \ 31 | org.fcitx.Fcitx.Controller1.AvailableInputMethods \ 32 | | awk 'BEGIN{i=0}{ 33 | if($0~/struct {/) i=0; 34 | else if(i<6){gsub(/"/,"",$2); printf("%s,",$2); i++} 35 | else if(i==6){printf("%s\n",$2); i++} 36 | }' > ${IMLIST_FILE} 37 | # Output like this: 38 | # pinyin, 拼音, 拼音, fcitx-pinyin, 拼, zh_CN, true 39 | # rime, 中州韻, , fcitx-rime, ㄓ, zh, true 40 | # ...... 41 | fi 42 | 43 | cat ${IMLIST_FILE} 44 | } 45 | 46 | # This script wait for events from `watch` and 47 | # update the text by printing a new line. 48 | # 49 | # Strip `Keyboard - ` part from IM name then print 50 | print_pretty_name() { 51 | name=$(imlist | grep "^$(current)," | cut -d',' -f5) 52 | if [[ -z "$name" ]]; then 53 | return 54 | fi 55 | if capslock > /dev/null; then 56 | # ${var^^} means uppercase, when CapsLock is on, let the name uppercase 57 | name="${name^^}${CAPS_SYMBOL}" 58 | fi 59 | echo "${name}" 60 | } 61 | 62 | react() { 63 | # Without this, Polybar will display empty 64 | # string until you switch input method. 65 | print_pretty_name 66 | 67 | # Track input method changes. Each new line read is an event fired from IM switch 68 | while true; do 69 | # When read someting from dbus-monitor 70 | read -r unused 71 | print_pretty_name 72 | done 73 | } 74 | 75 | ## 76 | # Watch for events from Fcitx. 77 | # 78 | # Because this script won't stop, I have to put the event handling part 79 | # in another file named `react`. 80 | ## 81 | 82 | # Need --line-buffered to avoid messages being hold in buffer 83 | dbus-monitor --session destination=org.freedesktop.IBus | grep --line-buffered '65505\|65509' | react 84 | --------------------------------------------------------------------------------