-
-
Save ste1ee-dot/94b483dff30f7074f60656947529e51d to your computer and use it in GitHub Desktop.
A homemade emoji picker
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Dependencies: `uni`, `kitty`, `wtype` or `xdotool`, `fzf`, `wl-clipboard` or `xclip` | |
# `uni` project: https://github.com/arp242/uni | |
# Usage: `chmod a+x emoji.bash`, then run the script whenever you need to pick emojis | |
SCRIPT_DIR=$(dirname "$(realpath "$0")") | |
export EMOJI_CHAR_PATH="/tmp/unicode_result-$USER.txt" | |
touch "$EMOJI_CHAR_PATH" | |
if [ -n "$WAYLAND_DISPLAY" ]; then | |
CLIPBOARDCMD="wl-copy" | |
INPUTCMD="wtype" | |
elif [ -n "$DISPLAY" ]; then | |
CLIPBOARDCMD="xclip" | |
INPUTCMD="xdotool type" | |
else | |
echo "Display server not recognized." | |
exit 1 | |
fi | |
function _unicode_search { | |
local type=$1 | |
local char | |
local args | |
args=( | |
-format '%(emoji l:auto) %(name)' | |
-compact | |
emoji all | |
) | |
char=$(uni "${args[@]}" | fzf | cut -d' ' -f1) | |
echo -n "$char" >"$EMOJI_CHAR_PATH" | |
echo -n "$char" | |
} | |
function unicode_search { | |
local type=$1 | |
local char && char=$(_unicode_search "$type") | |
if [ "$CLIPBOARDCMD" = "xclip" ]; then | |
echo -n "$char" | $CLIPBOARDCMD -selection clipboard | |
else | |
echo -n "$char" | $CLIPBOARDCMD --trim-newline | |
fi | |
echo "Copied $char to clipboard" | |
} | |
function emoji_picker { | |
kitty \ | |
--title "Emoji Picker" \ | |
-o "remember_window_size=no" \ | |
-o "initial_window_width=45c" \ | |
-o "initial_window_height=15c" \ | |
-o "font_size=20" \ | |
bash -c \ | |
"$SCRIPT_DIR/emoji.bash _unicode_search" | |
char_to_type=$(cat "$EMOJI_CHAR_PATH") | |
$INPUTCMD "$char_to_type" | |
} | |
subcommand=${1:-emoji_picker} | |
"$subcommand" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment