From 07243d5641ffde6f3e509bea271dba85d3e7df91 Mon Sep 17 00:00:00 2001 From: Quinn Bushey Date: Thu, 11 Jun 2026 10:17:45 -0700 Subject: [PATCH] screenshot, clipboard: add --copy and --clear flags screenshot -c/--copy copies the capture to the clipboard instead of opening it (uses the shell picker openClip/openFreezeClip IPC for interactive region selection, wl-copy for explicit regions). clipboard -c/--clear wipes the cliphist history. Closes #57, closes #65 --- completions/caelestia.fish | 4 +++- src/caelestia/parser.py | 4 ++++ src/caelestia/subcommands/clipboard.py | 4 ++++ src/caelestia/subcommands/screenshot.py | 11 ++++++++--- 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/completions/caelestia.fish b/completions/caelestia.fish index 80f177cb..cb0370f9 100644 --- a/completions/caelestia.fish +++ b/completions/caelestia.fish @@ -101,6 +101,7 @@ complete -c caelestia -n "$seen scheme && $seen set" -s 'v' -l 'variant' -d 'Set # Screenshot complete -c caelestia -n "$seen screenshot" -s 'r' -l 'region' -d 'Capture region' complete -c caelestia -n "$seen screenshot" -s 'f' -l 'freeze' -d 'Freeze while selecting region' +complete -c caelestia -n "$seen screenshot" -s 'c' -l 'copy' -d 'Copy screenshot to clipboard instead of opening it' # Record complete -c caelestia -n "$seen record" -s 'r' -l 'region' -d 'Capture region' @@ -108,7 +109,8 @@ complete -c caelestia -n "$seen record" -s 's' -l 'sound' -d 'Capture sound' complete -c caelestia -n "$seen record" -s 'c' -l 'clipboard' -d 'Copy recording path to clipboard' # Clipboard -complete -c caelestia -n "$seen clipboard" -s 'd' -l 'delete' -d 'Delete from cliboard history' +complete -c caelestia -n "$seen clipboard" -s 'd' -l 'delete' -d 'Delete from clipboard history' +complete -c caelestia -n "$seen clipboard" -s 'c' -l 'clear' -d 'Clear clipboard history' # Wallpaper complete -c caelestia -n "$seen wallpaper" -s 'p' -l 'print' -d 'Print the scheme for a wallpaper' -rF diff --git a/src/caelestia/parser.py b/src/caelestia/parser.py index aafa8525..628fbc49 100644 --- a/src/caelestia/parser.py +++ b/src/caelestia/parser.py @@ -64,6 +64,9 @@ def parse_args() -> tuple[argparse.ArgumentParser, argparse.Namespace]: screenshot_parser.add_argument( "-f", "--freeze", action="store_true", help="freeze the screen while selecting a region" ) + screenshot_parser.add_argument( + "-c", "--copy", action="store_true", help="copy the screenshot to the clipboard instead of opening it" + ) # Create parser for record opts record_parser = command_parser.add_parser("record", help="start a screen recording") @@ -77,6 +80,7 @@ def parse_args() -> tuple[argparse.ArgumentParser, argparse.Namespace]: clipboard_parser = command_parser.add_parser("clipboard", help="open clipboard history") clipboard_parser.set_defaults(cls=clipboard.Command) clipboard_parser.add_argument("-d", "--delete", action="store_true", help="delete from clipboard history") + clipboard_parser.add_argument("-c", "--clear", action="store_true", help="clear the clipboard history") # Create parser for emoji-picker opts emoji_parser = command_parser.add_parser("emoji", help="emoji/glyph utilities") diff --git a/src/caelestia/subcommands/clipboard.py b/src/caelestia/subcommands/clipboard.py index c0eddb50..dddb0d7f 100644 --- a/src/caelestia/subcommands/clipboard.py +++ b/src/caelestia/subcommands/clipboard.py @@ -9,6 +9,10 @@ def __init__(self, args: Namespace) -> None: self.args = args def run(self) -> None: + if self.args.clear: + subprocess.run(["cliphist", "wipe"]) + return + clip = subprocess.check_output(["cliphist", "list"]) if self.args.delete: diff --git a/src/caelestia/subcommands/screenshot.py b/src/caelestia/subcommands/screenshot.py index 95b84fff..60b8b2b5 100644 --- a/src/caelestia/subcommands/screenshot.py +++ b/src/caelestia/subcommands/screenshot.py @@ -21,11 +21,16 @@ def run(self) -> None: def region(self) -> None: if self.args.region == "slurp": - subprocess.run( - ["qs", "-c", "caelestia", "ipc", "call", "picker", "openFreeze" if self.args.freeze else "open"] - ) + func = "open" + ("Freeze" if self.args.freeze else "") + ("Clip" if self.args.copy else "") + subprocess.run(["qs", "-c", "caelestia", "ipc", "call", "picker", func]) else: sc_data = subprocess.check_output(["grim", "-l", "0", "-g", self.args.region.strip(), "-"]) + + if self.args.copy: + subprocess.run(["wl-copy"], input=sc_data) + notify("Screenshot taken", "Screenshot copied to clipboard") + return + swappy = subprocess.Popen(["swappy", "-f", "-"], stdin=subprocess.PIPE, start_new_session=True) # Ensure stdin is not None for the type checker