fix nerdfont rofi finder

This commit is contained in:
azpsen 2024-01-29 13:44:31 -06:00
parent c657bf51f7
commit 150e55fb99
2 changed files with 77 additions and 0 deletions

View File

@ -0,0 +1,8 @@
#!/bin/bash
# Run Rofi with the nerd-font-cheat script as the source for the modi
rofi -modi "nerdfont:~/.config/rofi/scripts/nerd-fonts.sh,emoji" -show nerdfont -emoji-mode copy -monitor -1
# Copy the selected icon to the clipboard
# echo "$selected_icon" | xclip -selection clipboard

View File

@ -0,0 +1,69 @@
#!/bin/bash
# icons cache file
ICONS_FILE="$HOME/.cache/nf-cheat.txt"
# url of icon sheet
URL="https://raw.githubusercontent.com/groovykiwi/rofi-nerdfont/master/nerd-font-cheatsheet.txt"
# get current time
CURRENT_TIME=$(date +%s)
# send notifications
function notify() {
if [ "$(command -v notify-send)" ]; then
notify-send "$1" "$2"
fi
}
# download icons
function download() {
notify `basename "$0"` 'downloading nerd-font icons list'
echo "" > "$ICONS_FILE"
# echo url to terminal and download the cheat sheet
echo "Downloading: $URL"
icons=$(curl -s "$URL")
echo "$icons" >> "$ICONS_FILE"
notify `basename "$0"` "icons downloaded"
}
# download icons file if it doesn't exist or is older than 5 days
if [ ! -f "$ICONS_FILE" ] || [ $((CURRENT_TIME - `stat -c %Y $ICONS_FILE`)) -gt 432000 ]; then
download
fi
function rofinf() {
icons=$(cat "$ICONS_FILE")
line=$(echo "$icons" | rofi -monitor -1 -dmenu -p " 󰞅 nerd-font " -i -font "JetBrainsMonoNL Nerd Font Mono" -width 100 -location 0 -lines 15 -kb-accept-entry Return | cut -d" " -f2 | tr '\n' ' ' | sed 's///g; s/\s//g' | xclip -selection clipboard)
exit_code=$?
line=($line)
}
selection="$@"
if [ -z "$selection" ]
then
readarray -t icons < "$ICONS_FILE"
for icon in "${icons[@]}"; do
echo "$icon"
done
else
coproc $(echo "$selection" | cut -d" " -f2 | tr '\n' ' ' | sed 's///g; s/\s//g' | xclip -selection clipboard)
exit 0
fi
case $1 in
--download)
download
;;
--rofi)
rofinf
;;
esac