#! /bin/zsh # # this file: # https://dataswamp.org/~incal/conf/.zsh/caps # # Emacs companion: # # locally: # ~/.emacs.d/emacs-init/caps-back.el # # web: # https://dataswamp.org/~incal/emacs-init/caps-back.el # # See the Emacs Elisp file caps-back.el for how this # works and what advantages it has. # # The below file provides the same behavior in the Linux # console/VTs/ttys as well as an X terminal emulator # (tested on xterm), as long as everywhere runs zsh, of # course :) # # To make it work in the VTs, in # # /etc/console-setup/remap.inc # # do like e.g., # # https://dataswamp.org/~incal/conf/remap.inc # # i.e, # # alt keycode 58 = U+00E2 # M-CAPS (â) # # to make the VT send "â" on M-CAPS (see that file how # to refresh with lkeys) # # # In X, in ~/.xinitrc # # https://dataswamp.org/~incal/conf/.xinitrc # # e.g., do: # # setxkbmap -option caps:none # disable caps lock # xmodmap -e 'keycode 66=a' # rebind CAPS (66) # # # Q: If it all is zsh based, how come it requires # different setup in the VTs and in X? # # A: zsh reacts on a special char, for this to happen # that char must be sent, and that happens # differently in the console and in X, even # (especially) for the same char # create a new keymap: caps-map # (based on the old one: main), bindkey -N caps-map main # in caps-map, remap a-z to A-Z setopt braceccl for c in {a-z}; do bindkey -M caps-map -s "$c" "$c:u" done # create functions to enable/disable the caps-map # by toggling the keymap (from/to caps-map/main); enable-caps-mode () { zle -K caps-map } disable-caps-mode () { zle -K main } # make them available to zle zle -N disable-caps-mode zle -N enable-caps-mode # in main, assign a special key to enable the caps-map; # in caps-map, assign the same key to disable it bindkey -M caps-map â disable-caps-mode bindkey -M main â enable-caps-mode bindkey -M main "\ea" enable-caps-mode # ? # in caps-map, automatically revert to main on certain # chars (e.g., whitespace and punctuation) so you should # seldom have to disable it manually for t in {\(\)\<\>\{\}\[\]\ \.\,\:\;}; do bindkey -M caps-map -s "$t" "â$t" done