File: insert-unicode-char

package info (click to toggle)
zsh 5.9-8
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 23,856 kB
  • sloc: ansic: 108,138; sh: 6,976; makefile: 722; perl: 687; awk: 291; sed: 16
file content (22 lines) | stat: -rw-r--r-- 715 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# Make hex integers appear as 0x...
setopt localoptions cbases

integer -g _insert_unicode_ready

if [[ $LASTWIDGET = insert-unicode-char && $_insert_unicode_ready -eq 1 ]]
then
  # Second call; we should have a usable prefix.
  # If we don't, give up.
  (( ${+NUMERIC} )) || return 1
  # Convert it back to hex, padded with zeroes to 8 digits plus the 0x...
  local -i 16 -Z 10 arg=$NUMERIC
  # ...and use print to turn this into a Unicode character.
  LBUFFER+="$(print -n "\U${arg##0x}")"
  integer -g _insert_unicode_ready=0
else
  # Set the base to 16...
  zle argument-base 16
  # ...wait for user to type hex keys then call this widget again.
  zle universal-argument
  integer -g _insert_unicode_ready=1
fi