diff options
| -rwxr-xr-x | .local/bin/emoji | 62 |
1 files changed, 56 insertions, 6 deletions
diff --git a/.local/bin/emoji b/.local/bin/emoji index cb50f7d..2830aad 100755 --- a/.local/bin/emoji +++ b/.local/bin/emoji @@ -1,19 +1,69 @@ #!/bin/sh -# The famous "get a menu of emojis to copy" script. +MENU_CMD="dmenu -fn \"monospace\" -p \"🤣\" -l 24" -# Get user selection via dmenu from emoji file. -chosen=$(cut -d ';' -f1 ~/.local/share/larbs/emoji | dmenu -fn DejaVuSansMono\ Nerd\ Font -i -l 30 | sed "s/ .*//") -#chosen=$(cut -d ';' -f1 ~/.local/share/larbs/emoji | dmenu -fn JoyPixels -i -l 30 | sed "s/ .*//") +[ "$XDG_SESSION_TYPE" = "wayland" ] && MENU_CMD="bemenu --fn \"monospace\" -p 🤣 -l 24" + +cachedir=${XDG_CACHE_HOME:-"$HOME/.cache"} +if [ -d "$cachedir" ]; then + cache=$cachedir/dmenu_emoji + historyfile=$cachedir/dmenu_emoji_history +else # if no xdg dir, fall back to dotfiles in ~ + cache=$HOME/.dmenu_emoji_cache + historyfile=$HOME/.dmenu_emoji_history +fi + +if ! [ -e "$cache" ] ; then + #| cut -d ';' -f1 ~/.local/share/larbs/emoji \ + cat ~/.local/share/larbs/emoji > "$cache" +fi + +chosen=$(awk -v histfile=$historyfile ' + BEGIN { + while( (getline < histfile) > 0 ) { + sub("^[0-9]+\t","") + print + x[$0]=1 + } + } !x[$0]++ ' "$cache" \ + | $MENU_CMD \ + | awk -v histfile=$historyfile ' + BEGIN { + FS=OFS="\t" + while ( (getline < histfile) > 0 ) { + count=$1 + sub("^[0-9]+\t","") + fname=$0 + history[fname]=count + } + close(histfile) + } + + { + history[$0]++ + print + } + + END { + if(!NR) exit + for (f in history) + print history[f],f | "sort -t '\t' -k1rn >" histfile + } + ') # Exit if none chosen. [ -z "$chosen" ] && exit # If you run this command with an argument, it will automatically insert the # character. Otherwise, show a message that the emoji has been copied. +chosen="$(echo "$chosen" | sed "s/ .*//")" if [ -n "$1" ]; then - xdotool type "$chosen" + xdotool type "$(echo "$chosen" | sed "s/ .*//")" else - echo "$chosen" | tr -d '\n' | xclip -selection clipboard + if [ "$XDG_SESSION_TYPE" = "wayland" ]; then + echo "$chosen" | tr -d '\n' | wl-copy + else + echo "$chosen" | tr -d '\n' | xclip -selection clipboard + fi notify-send "'$chosen' copied to clipboard." & fi |
