#!/bin/bash ################################# About ################################ ## Author: Simon D. Woodtli ## Thanks to u/rustyflavor on reddit for some neat modifications ## Project: https://github.com/SimonWoodtli/dotfiles/blob/main/scripts/emoji ## Script Name: emoji ## License: Apache-2.0 ## Dependencies: fzf, curl ################################# Setup ############################## ## 1. Copy script into your $PATH and chmod it ## 2. Run script once to populate database ## 3. Add to your ~/.vimrc: (rm # char at beginning) ################################# vimrc ################################ #"print function: #function! InsertFirstCharAtCursor(text) # let rmTxt = split(a:text, ' ') # let firstChar = get(rmTxt, 0) # execute "normal! a" . firstChar . "\" #endfunction #" var used by :Emoji #let emoji = { # \ 'source': 'cat "$HOME/.local/share/emojidb/emoji.v15.1"', # \ 'sink': function('InsertFirstCharAtCursor'), # \ 'options': '--prompt "search: " --no-preview -i -e --info=default --layout=reverse', # \ } #" var used by :Gitmoji #let gitmoji = copy(emoji) #let gitmoji['source'] = 'cat "$HOME/.local/share/emojidb/gitmoji"' #"ex-command fzf window: #command! Emoji call fzf#run(fzf#wrap(emoji)) #command! Gitmoji call fzf#run(fzf#wrap(gitmoji)) #"leader-command: (adjust to what you like) #nnoremap g :Gitmoji #nnoremap e :Emoji ################################ Script ################################ emojidb="$HOME/.local/share/emojidb/emoji.v15.1" _checkCommand() { command -v "$@" &>/dev/null; } _checkDependencies() { local -a dependencies=( fzf curl ) local -a missingDependencies=() for dependency in "${dependencies[@]}"; do _checkCommand "$dependency" || missingDependencies+=( "$dependency" ) done if [[ -n "${missingDependencies[@]}" ]]; then echo "ERROR: Missing dependency(ies): "${missingDependencies[@]}"" exit 1 fi } _createEmojiList() { #update url manually if new release comes out local url="https://unicode.org/Public/emoji/15.1/emoji-test.txt" mkdir -p "${emojidb%/*}" curl -s "$url" | sed ' /^#/d # remove comments /^\s*$/d # remove empty lines /skin tone/d # remove skin tones s/^[^#]*# // # remove first column s/\bE[0-9.]\+// # remove E number ' > "$emojidb" } _printEmojiCopyClipboard() { ## Check if emojidb and emoji file are present or create them [[ -f "$emojidb" ]] || _createEmojiList # clear screen printf "\033c" # not running tmux if [[ -z "$TMUX" || -z "$TERM_PROGRAM" ]]; then local emoji="$(fzf --no-preview -i -e --prompt='emoji: ' \ --info=default --layout=reverse < "$emojidb")" # tmux -ge 3.2 popup elif [[ "$TERM_PROGRAM" = tmux ]] ; then local emoji="$(fzf-tmux --no-preview -p --prompt='emoji: ' \ -w 80% -h 70% -i -e --info=default --layout=reverse < "$emojidb")" # tmux -lt 3.2 regular split elif [[ -n "$TMUX" ]] ; then local emoji="$(fzf-tmux --no-preview --prompt='emoji: ' -i -e \ --info=default --layout=reverse < "$emojidb")" fi emoji=${emoji%% *} ##FIXME Currently terminal does not support multibinary emojis with ZWJ printf "%s\n" "$emoji" if _checkCommand xclip; then printf %s "$emoji" | xclip -sel clipboard else printf "%s\n" "Install xclip for automatic copy to clipboard" fi } _checkDependencies && _printEmojiCopyClipboard