4 # Thorsten Glaser <tg@mirbsd.org>
5 # Dominik George <nik@naturalnet.de>
7 # Provided that these terms and disclaimer and all copyright notices
8 # are retained or reproduced in an accompanying document, permission
9 # is granted to deal in this work without restriction, including un‐
10 # limited rights to use, publicly perform, distribute, sell, modify,
11 # merge, give away, or sublicence.
13 # This work is provided “AS IS” and WITHOUT WARRANTY of any kind, to
14 # the utmost extent permitted by applicable law, neither express nor
15 # implied; without malicious intent or gross negligence. In no event
16 # may a licensor, author or contributor be held liable for indirect,
17 # direct, other damage, loss, or other issues arising in any way out
18 # of dealing in the work, even if advised of the possibility of such
19 # damage or existence of a defect, except proven that it results out
20 # of said person’s immediate fault when using the work as intended.
22 : ${XDG_DATA_HOME:=~/.local/share}
24 if [[ $1 = install ]]; then
25 script=$(readlink -f $0)
27 [[ -d $XDG_DATA_HOME ]] || mkdir -p $XDG_DATA_HOME
28 [[ -f $XDG_DATA_HOME/unidata.txt ]] || wget -O $XDG_DATA_HOME/unidata.txt "https://www.mirbsd.org/cvs.cgi/~checkout~/contrib/samples/unidata.txt?content-type=text%2Fplain"
29 [[ -x "$script" ]] || chmod +x "$script"
31 grep "bind ^U exec mksh $script" ~/.screenrc || print -r -- "bind ^U exec mksh $script" >>~/.screenrc
34 elif [[ $1 = update ]]; then
35 [[ -f $XDG_DATA_HOME/unidata.txt ]] && wget -O $XDG_DATA_HOME/unidata.txt "https://www.mirbsd.org/cvs.cgi/~checkout~/contrib/samples/unidata.txt?content-type=text%2Fplain"
40 if [[ $1 != do ]]; then
41 screen -X eval 'split' 'focus down'
42 screen -X screen mksh "$0" do
47 UNIDATA=$XDG_DATA_HOME/unidata.txt
49 if ! T=$(mktemp -d /tmp/utf8-select.XXXXXXXXX); then
50 print -u2 Error creating temporary directory
56 sed -n '/^.*U+\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\) *[^ ]* *\([^;]*\);.*$/s//\1 \2/p' \
57 <"$UNIDATA" | grep -v -e '^00[0189]' -e '^007F' -e '^D[89ABCDEF]' >U
63 --cancel-label "No, thanks" \
66 --title 'UTF-8 selector' \
67 --inputbox "${res:+$res }Look up character?" 8 $((COLUMNS - 4)) \
72 fgrep -i -e "$(<o)" U >r
79 while IFS= read -r l; do
80 typeset -i1 x=16#${l::4}
87 --cancel-label "No, thanks" \
89 --extra-label "Back" \
92 --title 'UTF-8 selector' \
93 --menu 'Select Unicode character to insert' \
94 $((LINES-4)) $((COLUMNS-4)) $((LINES-10)) \
99 (( v == 3 )) && continue
101 res="Nothing selected?"
102 [[ -s q ]] || continue
103 typeset -i1 ch=16#$(<q)
104 print -nr -- "${ch#1#}" >ch
105 screen -X readreg p "$T/ch"
106 screen -X eval 'focus up' 'paste p' 'focus down'