From 939c97ad9b0d1f3aa0005ed7a8cfa1073a7e3819 Mon Sep 17 00:00:00 2001 From: sinanmohd Date: Sat, 18 Mar 2023 20:56:43 +0530 Subject: dunicode: initial commit: script to copya and type unicode --- README.md | 3 ++ dunicode | 101 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 104 insertions(+) create mode 100755 dunicode diff --git a/README.md b/README.md index 78c4d9c..05f54cd 100644 --- a/README.md +++ b/README.md @@ -66,3 +66,6 @@ the geoip database ## daskpass this can be used as a password prompt. to use it with sudo set SUDO_ASKPASS + +## dunicode +script to copy and type unicode characters diff --git a/dunicode b/dunicode new file mode 100755 index 0000000..6600d61 --- /dev/null +++ b/dunicode @@ -0,0 +1,101 @@ +#!/bin/sh +set -e + +data_dir="${XDG_DATA_HOME:-$HOME/.local/share}/unicode" +menu="wmenu" + +note() +{ + : "${1:?}" + + command -v notify-send > /dev/null && + notify-send " dunicode" "$1" +} + +die() +{ + : "${1:?}" + + note "$1" + printf "\033[31;1merr: %b\033[0m\n" "$1" 1>&2 + exit "${2:-1}" +} + +dep_check() +{ + : "${1:?}" + + for dep; do + command -v "$dep" 1>/dev/null || + die "$dep not found, please install it" 127 + done + + unset dep +} + +get_glyph() +{ + + str= + + for glyph in "$data_dir"/* + do + [ -s "$glyph" ] && + str="${str}${glyph##*/}\n" + done + + [ -z "$str" ] && + die "no glyphs available, put them in $data_dir" + + # shellcheck disable=SC2059 + [ -n "${str#*\n}" ] && + str="$(printf "$str" | "$menu" -p " ")" + + str="$("$menu" -l 25 -p " " < "${data_dir}/${str}")" + echo "${str%%[[:space:]]*}" + + unset str +} + +main() +{ + + [ -z "$WAYLAND_DISPLAY" ] && + menu="dmenu" + + case "$1" in + -h) + printf "usage: %s %s" "${0##*/}" "[-ct]" + ;; + -c) + glyph="$(get_glyph)" + + if [ -z "$WAYLAND_DISPLAY" ] + then + dep_check "xclip" + printf "%s" "$glyph" | xclip -selection clipboard + else + dep_check "wl-copy" + printf "%s" "$glyph" | wl-copy + fi && + note "$glyph coppied to clipboard" + ;; + -t|"") + glyph="$(get_glyph)" + + if [ -z "$WAYLAND_DISPLAY" ] + then + dep_check "xdotool" + xdotool type --delay 20 "$glyph" + else + dep_check "wtype" + wtype -d 20 "$glyph" + fi + ;; + *) + die "invalid usage: ${0##*/} $*" + ;; + esac +} + +main "$@" -- cgit v1.2.3