Update setkb.sh

* BUG: Shell variables can't contain hyphens, sorry... So $DH-mod -> $DH_Mod
* BUG: #{} -> ${}
* Made setkb.sh robust towards more combinations and conditions.
This commit is contained in:
DreymaR 2023-06-19 23:18:25 +02:00
parent 37cba71426
commit adcbc4986a
3 changed files with 67 additions and 37 deletions

View File

@ -61,7 +61,7 @@ localectl
---------
* You can use the `localectl set-x11-keymap` command to make changes persistent; you may have to run it with `sudo` privileges
* Syntax: `[sudo] localectl [--no-convert] set-x11-keymap layout [model [variant [options]]]`
* Example: `sudo localectl set-x11-keymap us pc105aw-sl cmk_ed_us "lv5:caps_switch_lock,misc:extend"`
* Example: `sudo localectl set-x11-keymap us pc105awide cmk_ed_us "lv5:caps_switch_lock,misc:extend"`
* For `layout` and `[variant]`, you can use for instance `"us,us"` and `"cmk_ed_us,"` to switch between Cmk-eD and the default us layout
* Unfortunately, you can't switch between multiple models nor options this way so your QWERTY may have the Angle (and Curl!) mods...
* Add `--no-convert` to not convert between closest matching console and X11 keyboard mappings; this precludes applying as system console mapping
@ -89,15 +89,14 @@ input * {
}
```
And, here's one for Hyprland:
And here's one for Hyprland's `~/.config/hypr/hyprland` file:
```
input {
kb_rules=evdev
kb_model=pc105aw-sl
kb_model=pc105awide
kb_layout=us
kb_variant=cmk_ed_us
kb_options=misc:extend,lv5:caps_switch_lock,grp:shifts_toggle,compose:menu,misc:cmk_curl_dh
repeat_rate=40
repeat_delay=200
}

View File

@ -49,6 +49,7 @@ XRunDir=${XKBDIR} # (-d) The xkb-type dir to run setxkbmap from
AddCmdYN='no' # (-a) Add setxkbmap cmd to file?
AddDefault="${HOME}/.bashrc"
AddCmdTo=${AddDefault} # (-f) File (such as '~/.bashrc') to add setxkbmap cmd to
PrntCmd='no' # (-p) Print the setxkbmap command instead of running it?
ArgStr='' #'5caws us us' # (--) Shortcut string for setkb (model locale eD-variant)
## NOTE: '# (-a)' means that the value can be set by option argument '-a <value>'
@ -65,6 +66,7 @@ HelpStr="\e[1mUsage: bash ${MyNAME} [optional args] [<kbd> [<loc> <sym>]]\e[0m\n
"[-k] Keep old XKB server(s) - '${KeepXKM}' [toggle, no arg.]\n"\
"[-a] Add cmd line to file? - '${AddCmdYN}' [toggle, no arg.]\n"\
"[-f] <file> to add cmd to - '${AddCmdTo}'\n"\
"[-p] Print cmd; don't run it - '${PrntCmd}'\n"\
"[--] <ShortStr> - '${ArgStr}'\n"\
"\nSpecify '-d-' to run from the local repo directory w/o installing.\n"\
"\n\e[1mShortStr syntax, defining eD model+layout as a short split string:\e[0m\n"\
@ -127,11 +129,11 @@ MyCD()
OldDir=`pwd`
NewDir=${1:-`pwd`}
cd ${NewDir} \
&& MyPoint "Changed dir to '${NewDir}'" || MyError "Change to '${NewDir}' failed"
&& MyPoint "Changing dir to '${NewDir}'" || MyError "Change to '${NewDir}' failed"
}
#~ if [ "$#" == 0 ]; then PrintHelpAndExit 2; fi # No args
while getopts "m:l:o:v:d:f:akh?" cmdarg; do
while getopts "m:l:o:v:d:f:pakh?" cmdarg; do
case $cmdarg in
m) XKBmodel="$OPTARG" ;;
l) XKBlayout="$OPTARG" ;;
@ -139,6 +141,7 @@ while getopts "m:l:o:v:d:f:akh?" cmdarg; do
v) Verbosity="$OPTARG" ;;
d) XRunDir="$OPTARG" ;;
f) AddCmdTo="$OPTARG" ;;
p) PrntCmd='yes' ;;
a) AddCmdYN='yes' ;;
k) KeepXKM='yes' ;;
h) PrintHelpAndExit 0 ;;
@ -150,20 +153,20 @@ done
shift $(( $OPTIND - 1 )) # Remove already processed args
[[ "${XRunDir}" == '-' ]] && XRunDir="${XKBLOC}" # Use the default local dir
[[ "$@" == "" ]] || ArgStr=($@) # Split the ShortString, if present
[[ "$@" == "" ]] || ArgStr=($@) # Split the ShortString, if present
if [ -n "${ArgStr}" ]; then # Use ShortString notation
ModStr="${ArgStr[0]}"
KbdStr="${ModStr:0:1}" ; ModStr="${ModStr:1}" # 1st chr = Kbd type: 4/5 for ANSI/ISO
[[ "${ModStr:0:1}" == 'c' ]] && DH-Mod='y' || DH-Mod='n' # 2nd chr may be 'c' for the Curl mod
[[ ${DH-Mod} == 'y' ]] && ModStr="${ModStr:1}" # (remove the found character)
[[ "${KbdStr}" =~ [45] ]] || MyError "Kbd model 'pc10${KbdStr}' unknown!"
[[ "${ModStr:0:1}" == 'c' ]] && DH_Mod='y' || DH_Mod='n' # 2nd chr may be 'c' for the Curl mod
[[ ${DH_Mod} == 'y' ]] && ModStr="${ModStr:1}" # (remove the found character)
[[ "${ModStr: -1}" == 's' ]] && SymMod='y' || SymMod='n' # Last chr may be 's' for the Sym mod
if [[ ${SymMod} == 'y' ]]; then
ModStr="${ModStr:: -1}"
if [[ "${ModStr}" =~ 'w' ]]; then # Sort out Sym variants
case "#{KbdStr}" in
if [[ "${ModStr}" =~ [w] ]]; then # Sort out Sym variants
case "${KbdStr}" in
4) SymStr='wide-104' ;; # symkeys(sym_w-104)
5) SymStr='wide-105' ;; # symkeys(sym_w-105)
*) MyError "Kbd model 'pc10${KbdStr}' unknown!" ;;
esac
else
SymStr='non-wide' # symkeys(sym_non-w)
@ -171,7 +174,7 @@ if [ -n "${ArgStr}" ]; then # Use ShortString notation
SymStr="sym_${SymStr}"
fi
case "${ModStr}" in
n) ModStr='' ;; # Generic pc104(ANSI)/pc105(ISO) kbd
n|'') ModStr='' ;; # Generic pc104(ANSI)/pc105(ISO) kbd
a) ModStr='angle' ;; # w/ Angle ergo mod
w) ModStr='-wide' ;; # w/ Wide ergo mod
aw) ModStr='awide' ;; # w/ AngleWide ergo mod
@ -179,7 +182,7 @@ if [ -n "${ArgStr}" ]; then # Use ShortString notation
*) MyError "ShortStr model '${ArgStr[0]}' unknown!" ;;
esac
XKBmodel="pc10${KbdStr}${ModStr}" # Kbd type and Angle/Wide define xkb model
[[ ${DH-Mod} == 'y' ]] && XKBoption+=',misc:cmk_curl_dh' # Curl-DH is an XKB option
[[ ${DH_Mod} == 'y' ]] && XKBoption+=',misc:cmk_curl_dh' # Curl-DH is an XKB option
[[ ${SymMod} == 'y' ]] && XKBoption+=",misc:${SymStr}" # Sym mod is an XKB option
if [ -n "${ArgStr[2]}" ]; then # If there are three parts, ...
@ -194,7 +197,8 @@ if [ -n "${ArgStr}" ]; then # Use ShortString notation
if [ -n "${ArgStr[1]}" ]; then # If there are two or more parts, ...
XKBlayout="${ArgStr[1]}($XKBvar)" # ...use the lay(var) string.
else # Otherwise, use existing layout.
XKBlayout=`setxkbmap -query | grep layout | awk '{print $2}'`
[[ XKBlayout=`setxkbmap -query | grep layout | awk '{print $2}'` ]] \
|| XKBlayout='us' # If not found, default to the US locale
fi
fi
## TODO: Also set the right Extend variant option for Curl, when it gets implemented.
@ -204,7 +208,9 @@ fi
MyMsg "$HeadStr"
#~ MyCD "${XKBpath%/}/${XRunDir%/}"
if [ -n "${ArgStr}" ]; then
MyPoint "Using model/layout '$XKBmodel'/'$XKBlayout' from ShortStr"
MyPoint "ShortStr model/layout: ${XKBmodel} / ${XKBlayout}"
MyPoint "ShortStr lay. options: Curl(DH) - '${DH_Mod}'; Sym - '${SymMod}'."
MyEcho
fi
MyCD "${XRunDir%/}" # Change to the xkb dir first
@ -225,16 +231,21 @@ fi
## Clear the xkb options (to avoid duplicates)
setxkbmap -option ''
## Run the actual setxkbmap command
## Run or print out the actual setxkbmap command
[[ ${PrntCmd} == 'yes' ]] && RunPrt='Printing' || RunPrt='Running'
SetXKB="-model ${XKBmodel} -layout ${XKBlayout} -option ${XKBoption}"
if [ ${XRunDir} == ${XKBDIR} ]; then
MyPoint "Running setxkbmap with the system XKB dir:\n"
MyPoint "${RunPrt} setxkbmap command with the system XKB dir:\n"
OptXKB="-v ${Verbosity}" # Note: Verbosity doesn't work well with -print
else
MyPoint "Running setxkbmap with a local XKB dir:\n" # . is the local dir
MyPoint "${RunPrt} setxkbmap command with a local XKB dir:\n" # . is the local dir
OptXKB="-print | xkbcomp -I -I. -I${XKBDIR} $DISPLAY 2>/dev/null" # Wasn't there a hyphen before $DISPLAY?
fi
setxkbmap $SetXKB $OptXKB
if [ ${PrntCmd} == 'yes' ]; then
MyEcho "setxkbmap ${SetXKB} ${OptXKB}"
else
setxkbmap ${SetXKB} ${OptXKB}
fi
MyEcho ""
## Add the setxkbmap command to a file, if specified. Note the quotes necessary for FileXKB.

View File

@ -25,23 +25,32 @@ They work just fine with nearly all other versions and distros, though.
Note that the `base` and `evdev` rules are compiled slightly differently, so I provide both. Their `.lst` and `.xml` counterparts are identical/aliases.
<br>
FIXD:
-----
* The setkb.sh script wasn't working as it should. It got an error saying, e.g., "model pc104 doesn't exist".
- Shortstrs like `4ns` and `5cas` worked, as did `4aw` or `5w`. `4ws` didn't; gave "pc104/pc105 doesn't exist" errors.
- Identified these bugs: `DH-Mod` -> `DH_Mod` && "#{ModStr}" -> "${ModStr}".
- Furthermore, the layout was empty if setkb.sh can't run the setxkbmap cmd to determine layout.
- Added a conditional to see if the command was run successfully or default to 'us'
- Furthermore, the variant defaults to 'cmk_ed_us' instead of 'basic'? Because of a default setting, or what? It's OK though.
- Models `5s`, `5c` or `5cs` still not working, giving errors like `5s doesn't exist`. `5ns` worked.
- The error was not having a case model for the empty string ''.
- Giving a weird KbdStr could lead to weirdness. Now it gives an error message.
<br>
2FIX:
-----
* WSL1 uses xorg rules. I've only prepared for evdev and base. How to solve that? But xorg -> base by link!
- Is there another reason, then, that setxkbmap can't see my changes? The files are installed.
* Local dir by setkb.sh isn't working?
<br>
TODO:
-----
* Rework ergo model names.
- I'd like to use a model string `pc104`/`pc105` in setkb, which would simplify the case search in `SetXStr`.
- Then, the mods should have the same names, e.g., `pc104awide`/`pc105awide` instead of `pc104aw-zqu`/`pc105aw-sl`.
- Use `#angle`, `#wide`, `#awide` (and pc104awing).
- Is there currently no ISO-Wide option? No. That's because the Angle mod is "mandatory". But still, for consistency.
- Hide the AWing option from menus? It's pretty arcane and not really recommended.
- The `pc105curl` model is actually a CurlAngle model, and thus badly named. Fix. All the Curl models seem messy?
* Sym mod implementation
- The Sym mod should not be implemented as hard/model; it must not rearrange Extend.
- Better to make a new symbols/symbolkeys file, and put all symbol key definitions in there.
- That'd be nice for any other (not too radical) alt-layouts as well, I should think?
- Then select sym mod according to wide status, as an option.
- Update setkb.sh to handle all that.
* The `pc105curl` model is actually a CurlAngle model, and thus badly named. Fix?!
- All the Curl models seem messy? What was I thinking? But maybe to avoid the option thing, they could still be useful?
* Better instructions for Wayland?
- Depends on your Wayland Compositor (Sway is common?)
@ -81,8 +90,6 @@ TODO:
* Check out the compose:102 option. This would be similar to what I've used in EPKL for Windows! It's also present in some other layouts.
- Add compose:102 in the default setkb options? Inconsistent between ISO and ANSI, just add a pro-tip?
* Echo the setxkbmap command when using setkb.sh, for ease of troubleshooting! Also make the script able to output the command for piping.
* Add a localectl option to setkb.sh? So people can choose that or setxkbmap. Eventually, even more variants such as Sway?
* Problems with Super+<letter> shortcuts: https://github.com/DreymaR/BigBagKbdTrixXKB/issues/23#issuecomment-1027839924
@ -176,7 +183,20 @@ HOLD:
DONE:
-----
* Update xkb-data to 2.35.1.1 as of 2023-05-31 (package updated 2022-04-05)
* Echo the setxkbmap command when using setkb.sh, for ease of troubleshooting! Also make the script able to output the command for piping?
* Reworked ergo model names.
- Mods should have modularly related names, e.g., `pc104awide`/`pc105awide` instead of `pc104aw-zqu`/`pc105aw-sl`.
- Converted, therefore, to `#angle`, `#wide`, `#awide` (and the "arcane" `pc104awing`, now hidden from menus).
* Sym mod implementation.
- The Sym mod can not be implemented as hard/model, as it must not rearrange Extend. Like Curl, it is an `option` mod.
- Made a symbols/symkeys file, and put all symbol key definitions in there.
- There are `non-wide`, `wide-104` and `wide-105` variants. The latter two build on the Colemak-Wide ergo mods.
- The `setkb.sh` script is updated to handle these with an `s` shortstr syntax, so it respects `caws` nomenclature.
- This should be nice for use with any other layouts that don't touch symbol keys as well! Even QWERTY.
* Update xkb-data to 2.35.1.1 as of 2023-05-31 (package updated 2022-04-05).
- The [freedesktop.org GitLab repo][XKBgitLb] is the freshest there is? But it has the rules in raw/uncompiled format.
- So, instead use the [Debian Sid xkb-data package][XKB-DebS] which is the most updated one in actual use.
- Add the patch that fixes the hobbled Colemak (LatAm, Colemak for Gaming) variant