From 7f93cea6e316285d18357caa9daa84784c6b77a7 Mon Sep 17 00:00:00 2001 From: Sam Date: Sat, 15 Jun 2024 18:37:15 +0100 Subject: [PATCH] emoji-picker script --- .../desktop/dwm/scripts/emoji-picker.nix | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 home/common/optional/desktop/dwm/scripts/emoji-picker.nix diff --git a/home/common/optional/desktop/dwm/scripts/emoji-picker.nix b/home/common/optional/desktop/dwm/scripts/emoji-picker.nix new file mode 100644 index 0000000..e63a613 --- /dev/null +++ b/home/common/optional/desktop/dwm/scripts/emoji-picker.nix @@ -0,0 +1,33 @@ +{ 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 + echo "Symbol files not found. Fetching from: '$remote'..." + mkdir -p "$symbols_dir" + git clone "$remote" "$symbols_dir" + [ "$?" != 0 ] && echo "Error fetching from: $remote" && exit 1 + 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) + [ "$emoji_row" == "**** Recent ****" ] || [ "$emoji_row" == "****************" ] && echo "Invalid selection." && exit 1 + + # 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" + '') + ]; +}