summaryrefslogtreecommitdiff
path: root/.local/bin/uni
blob: d0dbc36dd21d0979ea77580530e1e362f388b65e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/bin/sh

set -e

export NOTIFY_LONG=unicode
export NOTIFY_SHORT="${0##*/}"

setup()
{
	curl 'https://www.unicode.org/Public/UNIDATA/UnicodeData.txt' \
	| sed -E '
		s/;[^;]*//2g
		s/\<(.)([A-Z]*)/\1\L\2/2g
		/^[^;]*;</d
		/Compatibility/d
		/Variation Selector/d
		s/[^;]*/\\\\u&/
	' >"$DATA"
}

readonly DATA="${XDG_DATA_HOME:-$HOME/.local/share}/unicode-data"
[ -f "$DATA" ] || setup

opt="$(cut -d';' -f2 "$DATA" | osel)"
rune="$(awk -vopt="$opt" -F';' '$2 == opt { print $1 }' "$DATA" | xargs printf)"

if [ -t 2 ]
then
	wl-copy -n "$rune" \
	&& notify 'Rune Copied' "The rune ‘$rune’ was copied to the clipboard"
else
	wtype -- "$rune"
fi