dotfiles/.local/bin/dmenunerdsymbols

29 lines
1013 B
Plaintext
Raw Normal View History

#!/bin/sh
2024-04-23 04:34:15 +02:00
json_url="https://raw.githubusercontent.com/ryanoasis/nerd-fonts/master/glyphnames.json"
local_file="$HOME/.local/share/script-data/chars/nerd-glyphs.json"
needs_update() {
2024-05-16 18:31:37 +02:00
local_date=$(stat -c %Y "$local_file" 2>/dev/null || echo 0)
current_date=$(date +%s)
[ "$((current_date - local_date))" -ge "$((14 * 24 * 3600))" ]
2024-04-23 04:34:15 +02:00
}
2024-05-16 18:31:37 +02:00
if [ ! -f "$local_file" ]; then
curl -s "$json_url" -o "$local_file"
elif needs_update; then
remote_date=$(curl -sI "$json_url" | grep -i '^Last-Modified:' | sed 's/Last-Modified: //')
if [ "$remote_date" != "$(stat -c %y "$local_file" 2>/dev/null)" ]; then
curl -s "$json_url" -o "$local_file"
fi
2024-04-23 04:34:15 +02:00
fi
selected=$(jq -r '. as $input | to_entries[] | select(.key != "METADATA") | "\(.value.char) \(.key)"' "$local_file" | dmenu -bw 2 -i -W 290 -X 1061 -Y 15 -l 30 | sed "s/ .*//")
[ -z "$selected" ] && exit
if [ -n "$1" ]; then
2024-05-16 18:31:37 +02:00
xdotool type "$selected"
2024-04-23 04:34:15 +02:00
else
2024-05-16 18:31:37 +02:00
printf "%s" "$selected" | xclip -selection clipboard
notify-send "$selected - copied to clipboard." &
2024-04-23 04:34:15 +02:00
fi