2024-06-15 18:37:15 +01:00
|
|
|
{ pkgs, ... }:
|
|
|
|
{
|
|
|
|
home.packages = with pkgs; [
|
|
|
|
(writeShellScriptBin "emoji-picker" ''
|
|
|
|
# Define variables
|
|
|
|
symbols_dir="$HOME/.local/share/symbols"
|
|
|
|
emoji_file="$symbols_dir/emoji"
|
|
|
|
nerdfont_file="$symbols_dir/nerdfont"
|
|
|
|
recent="$symbols_dir/recent"
|
|
|
|
remote="https://git.bitlab21.com/sam/symbols.git"
|
|
|
|
|
|
|
|
# Check if emoji files are installed, if not pull from remote
|
|
|
|
if [ ! -f "$emoji_file" ] || [ ! -f "$nerdfont_file" ]; then
|
2024-06-15 20:06:09 +01:00
|
|
|
notify-send "Emoji Picker" "Symbol files not found. Fetching from: '$remote'..."
|
2024-06-15 18:37:15 +01:00
|
|
|
mkdir -p "$symbols_dir"
|
|
|
|
git clone "$remote" "$symbols_dir"
|
2024-06-15 20:06:09 +01:00
|
|
|
[ "$?" != 0 ] && notify-send "Emoji Picker" "Error fetching from: $remote" && exit 1
|
2024-06-15 18:37:15 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Concat all emoji files and pipe into dmenu. Remove empty rows with sed. Exit if invalid selection.
|
|
|
|
emoji_row=$(cat "$recent" "$emoji_file" "$nerdfont_file" | sed '/^$/d' | dmenu -l 20)
|
2024-06-15 20:06:09 +01:00
|
|
|
[ "$emoji_row" == "**** Recent ****" ] || [ "$emoji_row" == "****************" ] && notify-send "Emoji Picker" "Invalid selection." && exit 1
|
2024-06-15 18:37:15 +01:00
|
|
|
|
|
|
|
# Add selected emoji to recent.
|
|
|
|
sed -i "/$emoji_row/d" "$recent" && sed -i "2s/^/$emoji_row\n/" "$recent"
|
|
|
|
|
|
|
|
# Copy to clipboard
|
|
|
|
emoji=$(echo "$emoji_row" | sed 's/\s.*//g')
|
|
|
|
echo "$emoji" | xclip -i -r -selection CLIPBOARD
|
|
|
|
notify-send "Emoji Picker" "$emoji_row copied to clipboard"
|
|
|
|
'')
|
|
|
|
];
|
|
|
|
}
|