summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author2 * r + 2 * t <61896496+soramanew@users.noreply.github.com>2025-06-23 14:11:05 +1000
committer2 * r + 2 * t <61896496+soramanew@users.noreply.github.com>2025-06-23 14:11:05 +1000
commitdcd3cdc8642239700bddc07846b3743013a5daec (patch)
tree1a77b027f09f7a9236c6e4538fe7072e59f3f401
parentemojis: add missing emojis (diff)
downloadcaelestia-cli-dcd3cdc8642239700bddc07846b3743013a5daec.tar.gz
caelestia-cli-dcd3cdc8642239700bddc07846b3743013a5daec.tar.bz2
caelestia-cli-dcd3cdc8642239700bddc07846b3743013a5daec.zip
emoji: add fetch option
-rw-r--r--completions/caelestia.fish6
-rw-r--r--src/caelestia/parser.py4
-rw-r--r--src/caelestia/subcommands/emoji.py86
3 files changed, 89 insertions, 7 deletions
diff --git a/completions/caelestia.fish b/completions/caelestia.fish
index 4448f27..8822c2f 100644
--- a/completions/caelestia.fish
+++ b/completions/caelestia.fish
@@ -18,7 +18,7 @@ complete -c caelestia -n $not_seen -a 'scheme' -d 'Manage the colour scheme'
complete -c caelestia -n $not_seen -a 'screenshot' -d 'Take a screenshot'
complete -c caelestia -n $not_seen -a 'record' -d 'Start a screen recording'
complete -c caelestia -n $not_seen -a 'clipboard' -d 'Open clipboard history'
-complete -c caelestia -n $not_seen -a 'emoji-picker' -d 'Toggle the emoji picker'
+complete -c caelestia -n $not_seen -a 'emoji' -d 'Emoji/glyph utilities'
complete -c caelestia -n $not_seen -a 'wallpaper' -d 'Manage the wallpaper'
complete -c caelestia -n $not_seen -a 'pip' -d 'Picture in picture utilities'
@@ -122,5 +122,9 @@ complete -c caelestia -n "$seen wallpaper" -s 'n' -l 'no-filter' -d 'Do not filt
complete -c caelestia -n "$seen wallpaper" -s 't' -l 'threshold' -d 'The threshold to filter by' -r
complete -c caelestia -n "$seen wallpaper" -s 'N' -l 'no-smart' -d 'Disable smart mode switching'
+# Emoji
+complete -c caelestia -n "$seen emoji" -s 'p' -l 'picker' -d 'Open emoji/glyph picker'
+complete -c caelestia -n "$seen emoji" -s 'f' -l 'fetch' -d 'Fetch emoji/glyph data from remote'
+
# Pip
complete -c caelestia -n "$seen pip" -s 'd' -l 'daemon' -d 'Start in daemon mode'
diff --git a/src/caelestia/parser.py b/src/caelestia/parser.py
index 37ce591..ad0fd99 100644
--- a/src/caelestia/parser.py
+++ b/src/caelestia/parser.py
@@ -95,8 +95,10 @@ def parse_args() -> (argparse.ArgumentParser, argparse.Namespace):
clipboard_parser.add_argument("-d", "--delete", action="store_true", help="delete from clipboard history")
# Create parser for emoji-picker opts
- emoji_parser = command_parser.add_parser("emoji-picker", help="toggle the emoji picker")
+ emoji_parser = command_parser.add_parser("emoji", help="emoji/glyph utilities")
emoji_parser.set_defaults(cls=emoji.Command)
+ emoji_parser.add_argument("-p", "--picker", action="store_true", help="open the emoji/glyph picker")
+ emoji_parser.add_argument("-f", "--fetch", action="store_true", help="fetch emoji/glyph data from remote")
# Create parser for wallpaper opts
wallpaper_parser = command_parser.add_parser("wallpaper", help="manage the wallpaper")
diff --git a/src/caelestia/subcommands/emoji.py b/src/caelestia/subcommands/emoji.py
index f04b502..5e9de21 100644
--- a/src/caelestia/subcommands/emoji.py
+++ b/src/caelestia/subcommands/emoji.py
@@ -1,5 +1,7 @@
+import json
import subprocess
from argparse import Namespace
+from urllib.request import urlopen
from caelestia.utils.paths import cli_data_dir
@@ -11,8 +13,82 @@ class Command:
self.args = args
def run(self) -> None:
- emojis = (cli_data_dir / "emojis.txt").read_text()
- chosen = subprocess.check_output(
- ["fuzzel", "--dmenu", "--placeholder=Type to search emojis"], input=emojis, text=True
- )
- subprocess.run(["wl-copy"], input=chosen.split()[0], text=True)
+ if self.args.picker:
+ emojis = (cli_data_dir / "emojis.txt").read_text()
+ chosen = subprocess.check_output(
+ ["fuzzel", "--dmenu", "--placeholder=Type to search emojis"], input=emojis, text=True
+ )
+ subprocess.run(["wl-copy"], input=chosen.split()[0], text=True)
+ elif self.args.fetch:
+ self.fetch_emojis()
+ else:
+ print((cli_data_dir / "emojis.txt").read_text(), end="")
+
+ def fetch_emojis(self) -> None:
+ data = [
+ "¿? question upside down reversed spanish",
+ "← left arrow",
+ "↑ up arrow",
+ "→ right arrow",
+ "↓ down arrow",
+ "←↑→↓ all directions up down left right arrows",
+ "⇇ leftwards paired arrows",
+ "⇉ rightwards paired arrows",
+ "⇈ upwards paired arrows",
+ "⇊ downwards paired arrows",
+ "⬱ three leftwards arrows",
+ "⇶ three rightwards arrows",
+ "• dot circle separator",
+ "「」 japanese quote square bracket",
+ "¯\\_(ツ)_/¯ shrug idk i dont know",
+ "(ง🔥ロ🔥)ง person with fire eyes eyes on fire",
+ "↵ enter key return",
+ "° degrees",
+ "™ tm trademark",
+ "® registered trademark",
+ "© copyright",
+ "— em dash",
+ "󰖳 windows super key",
+ ]
+
+ # Fetch emojis
+ with urlopen(
+ "https://raw.githubusercontent.com/milesj/emojibase/refs/heads/master/packages/data/en/compact.raw.json"
+ ) as f:
+ emojis = json.load(f)
+
+ for emoji in emojis:
+ line = [emoji["unicode"]]
+
+ if "emoticon" in emoji:
+ if isinstance(emoji["emoticon"], str):
+ line.append(emoji["emoticon"])
+ else:
+ line.extend(emoji["emoticon"])
+
+ line.append(emoji["label"])
+
+ if "tags" in emoji:
+ line.extend(emoji["tags"])
+
+ data.append(" ".join(line))
+
+ # Fetch nerd font glyphs
+ with urlopen("https://raw.githubusercontent.com/ryanoasis/nerd-fonts/refs/heads/master/glyphnames.json") as f:
+ glyphs = json.load(f)
+
+ buckets = {}
+ for name, glyph in glyphs.items():
+ if name == "METADATA":
+ continue
+
+ unicode = glyph["char"]
+ if unicode not in buckets:
+ buckets[unicode] = []
+ buckets[unicode].append(f"nf-{name}")
+
+ for glyph, names in buckets.items():
+ data.append(f"{glyph} {' '.join(names)}")
+
+ # Write to file
+ (cli_data_dir / "emojis.txt").write_text("\n".join(data))