summaryrefslogtreecommitdiff
path: root/.local/bin
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com> 2023-11-07 03:45:18 +0100
committerThomas Voss <mail@thomasvoss.com> 2023-11-07 03:45:18 +0100
commite245030c07d68ae4f1b05b8c9dc10443bdc5bcdd (patch)
treec043dde567edcbbe83cf0b94889a580d22e1d7cd /.local/bin
parent8834f8cb341beb8212196a53cdf8de09a7d6d5d3 (diff)
uni: Add the uni script for unicode input
Diffstat (limited to '.local/bin')
-rwxr-xr-x.local/bin/uni27
1 files changed, 27 insertions, 0 deletions
diff --git a/.local/bin/uni b/.local/bin/uni
new file mode 100755
index 0000000..4be2d86
--- /dev/null
+++ b/.local/bin/uni
@@ -0,0 +1,27 @@
+#!/bin/sh
+
+set -e
+
+setup()
+{
+ curl 'https://www.unicode.org/Public/UNIDATA/UnicodeData.txt' \
+ | >"$DATA" sed -E \
+ -e 's/;[^;]*//2g' \
+ -e 's/\<(.)([A-Z]*)/\1\L\2/2g' \
+ -e '/^[^;]*;</d' \
+ -e '/Compatibility/d' \
+ -e '/Variation Selector/d'
+}
+
+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 { printf "\\\\u%s\\\\n", $1; exit }' "$DATA" \
+ | xargs printf
+)"
+
+wl-copy -n "$rune" && notify uni unicode 'Rune Copied' \
+ "The rune ‘$rune’ was copied to the clipboard"