chore: update rofi-emoji to paste the emoji rather than copy
4963a48d
1 file(s) · +21 −5
| 1 | 1 | #!/bin/sh |
|
| 2 | - | # Requires: rofi, xclip, a color emoji font (Noto Color Emoji) |
|
| 2 | + | # Requires: rofi, xclip, xdotool, a color emoji font (Noto Color Emoji) |
|
| 3 | 3 | # Emoji and kaomoji picker: search by name, Enter copies the character to the |
|
| 4 | - | # clipboard. There is no paste-into-the-window step because that needs xdotool |
|
| 5 | - | # to fake a keystroke, which is not installed — copy and paste normally. |
|
| 4 | + | # clipboard and pastes it into whatever window was focused before rofi opened. |
|
| 5 | + | # Terminals don't bind plain ctrl+v to paste, so terminal window classes get |
|
| 6 | + | # ctrl+shift+v instead; override the whole thing with ROFI_EMOJI_PASTE_KEYS. |
|
| 6 | 7 | # Picks are remembered and float to the top, so the handful anyone actually |
|
| 7 | 8 | # uses stop needing to be searched for. |
|
| 8 | 9 | set -u |
|
| 21 | 22 | cat "$RECENT" "$DATA" | awk -F'\t' '!seen[$1]++ { printf "%s %s\n", $1, $2 }' |
|
| 22 | 23 | } |
|
| 23 | 24 | ||
| 25 | + | TARGET_WIN=$(xdotool getactivewindow 2>/dev/null) || TARGET_WIN= |
|
| 26 | + | ||
| 24 | 27 | CHOICE=$(rows | rofi -dmenu -i -no-custom -p "emoji" -matching normal) || exit 0 |
|
| 25 | 28 | [ -n "$CHOICE" ] || exit 0 |
|
| 26 | 29 | ||
| 29 | 32 | ||
| 30 | 33 | printf '%s' "$CHAR" | xclip -selection clipboard -i |
|
| 31 | 34 | ||
| 35 | + | if [ -n "$TARGET_WIN" ]; then |
|
| 36 | + | TARGET_CLASS=$(xdotool getwindowclassname "$TARGET_WIN" 2>/dev/null || echo) |
|
| 37 | + | case "$TARGET_CLASS" in |
|
| 38 | + | *[Tt]erm*|kitty|st|st-256color|foot|footclient|tilix|konsole) |
|
| 39 | + | DEFAULT_PASTE_KEYS="ctrl+shift+v" ;; |
|
| 40 | + | *) |
|
| 41 | + | DEFAULT_PASTE_KEYS="ctrl+v" ;; |
|
| 42 | + | esac |
|
| 43 | + | PASTE_KEYS=${ROFI_EMOJI_PASTE_KEYS:-$DEFAULT_PASTE_KEYS} |
|
| 44 | + | xdotool windowactivate --sync "$TARGET_WIN" 2>/dev/null |
|
| 45 | + | xdotool key --clearmodifiers --window "$TARGET_WIN" "$PASTE_KEYS" 2>/dev/null |
|
| 46 | + | fi |
|
| 47 | + | ||
| 32 | 48 | # Rewrite the recents file with this pick first and its older copy dropped. |
|
| 33 | 49 | tmp="$RECENT.$$" |
|
| 34 | 50 | printf '%s\t%s\n' "$CHAR" "$NAME" > "$tmp" |
|
| 37 | 53 | rm -f "$tmp" |
|
| 38 | 54 | ||
| 39 | 55 | command -v dunstify >/dev/null 2>&1 && |
|
| 40 | - | dunstify -r 7302 "Copied $CHAR" "$NAME" || |
|
| 41 | - | notify-send "Copied $CHAR" "$NAME" |
|
| 56 | + | dunstify -r 7302 "Pasted $CHAR" "$NAME" || |
|
| 57 | + | notify-send "Pasted $CHAR" "$NAME" |
|