From 873165b6d8cf817e6f581be489c4aa7deea9b421 Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Wed, 6 Dec 2023 01:31:57 +0100 Subject: uni: Switch from sh to andy --- .local/bin/uni | 47 +++++++++++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 22 deletions(-) (limited to '.local/bin/uni') diff --git a/.local/bin/uni b/.local/bin/uni index 778d2eb..a829fd0 100755 --- a/.local/bin/uni +++ b/.local/bin/uni @@ -1,34 +1,37 @@ -#!/bin/sh +#!/usr/local/bin/andy -set -e +set -e NOTIFY_LONG unicode +set -e NOTIFY_SHORT uni -export NOTIFY_LONG=unicode -export NOTIFY_SHORT="${0##*/}" - -setup() -{ - curl 'https://www.unicode.org/Public/UNIDATA/UnicodeData.txt' \ - | sed -E ' +func setup { + curl 'https://www.unicode.org/Public/UNIDATA/UnicodeData.txt' + | sed -E r#' s/;[^;]*//2g s/\<(.)([A-Z]*)/\1\L\2/2g /^[^;]*;"$DATA" + s/^\\u([^;]{5})/\\U000\1/ + '# >$DATA } -readonly DATA="${XDG_DATA_HOME:-$HOME/.local/share}/unicode-data" -[ -f "$DATA" ] || setup +test $#XDG_DATA_HOME -eq 0 && set XDG_DATA_HOME $HOME/.local/share +set DATA $XDG_DATA_HOME/unicode-data +test -f $DATA || setup + +set idx `{ + tee >{cut -d';' -f1 | read -d\n runes} <$DATA + | cut -d';' -f2 $DATA + | osel -i +} +set rune `printf $runes[$idx] -idx="$(cut -d';' -f2 "$DATA" | osel -i)" -code="$(head -n "$idx" "$DATA" | tail -n1 | cut -d';' -f1)" -rune="$(printf $code)" +if test -t 2 { + wl-copy -n "$rune" + | notify 'Rune Copied' "The rune ‘$rune’ was copied to the clipboard" +} else { + wtype -- $rune +} -if [ -t 2 ] -then - wl-copy -n "$rune" \ - && notify 'Rune Copied' "The rune ‘$rune’ was copied to the clipboard" -else - wtype -- "$rune" -fi +# vi: ft=sh -- cgit v1.2.3