Commit graph

90 commits

Author SHA1 Message Date
b0ee7f59a3
commands: deprecate plain wipe command in favor of db wipe
Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: I62dbcc00b6b79f160318f9704fab001b6a6a6964
2026-04-03 14:46:08 +03:00
da9bf5ea3e
treewide: make logging format more consistent; make clipboard persistence opt-in
Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: I9092f93c29fcbe99c90483875f4acd0c6a6a6964
2026-04-03 14:12:00 +03:00
77ac70f0d3 db/nonblocking: add test-only imports for the Fnv1aHasher
Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: I66effd259c6654bd4efac2f4e6bc4e176a6a6964
2026-04-01 16:25:21 +03:00
d643376cd7 stash: deduplicate Fnv1aHasher; add derive for u64 wrapper
Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: Ic2886815721f6eefc66a8ddacd44fb286a6a6964
2026-04-01 16:23:58 +03:00
d9bee33aba
stash: consolidate confirmation prompts; install color_eyre hook
Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: I7fb4ba67098f897849fc9b317c7fde646a6a6964
2026-03-31 15:25:09 +03:00
030be21ea5
clipboard: persist clipboard contents after source application closes
When the source application closes, the forked child continues serving
clipboard data so it remains available for paste operations.

Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: I14fbcf8cbc47c40bfa1da7f8b09245936a6a6964
2026-03-31 11:50:47 +03:00
fe86356399
wayland: use arc-swap over Mutex for FOCUSED_APP for better concurrency
Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: Id6b40d5c533c35dda5bce7b852b836f26a6a6964
2026-03-31 11:50:46 +03:00
b1f43bdf7f
db: replace \CHECKED\ atomic flag with pattern-keyed regex cache
Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: I9d5fa5212c5418ce6bca02d05149e1356a6a6964
2026-03-05 16:07:49 +03:00
373affabee
db: improve content hashing; cache only positive scan result
Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: If8035bf1dcd598a992762b9c714253406a6a6964
2026-03-05 15:07:32 +03:00
0865a1f139
commands/list: debounce for rapid copy operations
Tracks the entry ID currently being copied in `TuiState` to prevent
concurrent `copy_entry()` calls on the same entity. Otherwise we hit a
race condition. Fun!


Track the entry ID currently being copied in TuiState to prevent
concurrent copy_entry() calls on the same entry. Fixes database
race conditions when users trigger copy commands in rapid succession.



Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: If8e8fe56bf6dc35960e47decf59636116a6a6964
2026-03-05 15:07:31 +03:00
cf5b1e8205
db: tests for determinism & async ops
Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: I2591e607a945c0aaa28a75247fc638436a6a6964
2026-03-05 15:07:30 +03:00
95bf1766ce
stash: async db operations; make hashes deterministic
Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: Iccc9980fa13a752e0e6c9fb630c28ba96a6a6964
2026-03-05 15:07:24 +03:00
7184c8b682
db: consolidate duplicated SQL queries
Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: I8b6889d1e420865d0a8d3b8da916d8086a6a6964
2026-03-05 12:56:56 +03:00
ffdc13e8f5
commands/list: allow printing in reversed order with --reverse
Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: I305cfdc68d877dc5d5083a76dccc62db6a6a6964
2026-03-05 09:34:37 +03:00
181edcefb1
db: add MIME sniffing for binary clipboard previews
Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: I70416269dd40496758b6e5431e77a9456a6a6964
2026-02-27 12:15:10 +03:00
3a14860ae1
various: validate lower and upper boundaries before storing; add CLI flags
Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: I6484f9579a8799d952b15adcb47c8eec6a6a6964
2026-02-27 07:59:28 +03:00
02ba05dc95
db: add new error variants for entries below minimum and above maximum sizes
Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: Icba2920cfef0ffb0ce6435ab6d7809166a6a6964
2026-02-27 07:58:46 +03:00
b850a54f7b
commands/list: implement clipboard history search
Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: I57f00cbd9d02b1981cf3ea5dc908e72c6a6a6964
2026-02-26 12:06:18 +03:00
88c1f0f158
commands/list: full TUI rewrite for better perf
Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: I49009a89542fdeeea31d3755108b53d06a6a6964
2026-02-26 12:06:17 +03:00
9afbe9ceca
watch: deprioritize text/html in MIME negotiation
Firefox and Electron apps offer `text/html` first when copying images,
which causes stash to store the HTML wrapper (`<img src="...">`) instead
of the actual image data, which is what we want. We handicap, i.e.,
deprioritize `text/html` in the "any" preference mode and prefer
`image/*` types first, then any non-html type. 

This sounds a little illogical, but in user will almost always prefer
the image itself rather than the text representation. So it's intuitive.

Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: I6bd5969344893e15226c27071442475f6a6a6964
2026-02-01 14:55:31 +03:00
3fd48896c1
watch: respect source MIME type order in clipboard polling
Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: I3da2e187276611579f3686acb20aacf36a6a6964
2026-02-01 11:55:18 +03:00
b4dd704961
db: add an in-memory test helper
Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: I22cc10df47265fa4d08d5c03cadbe9c56a6a6964
2026-02-01 11:55:17 +03:00
bb8e882565
mime: expand test coverage
Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: I3f17b98ad68f17ebcf9554e5e88f62676a6a6964
2026-02-01 11:55:02 +03:00
ff2f272055
mime: refactor mime detection to separate module; streamline
Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: I489054d2537a4c0de32d79f793478c206a6a6964
2026-01-23 23:13:01 +03:00
b00e9b5f3a
watch: clear clipboard when expired entry content matches current clipboard
Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: I4bede5db16cea993ed8e8591e8d198d56a6a6964
2026-01-22 18:27:24 +03:00
5731fb08a5
cli: add db subcommand
Adds a `db` subcommand with `DbAction` for three new database
operations: wipe, vacuum and stats. We can extend this database later,
but this is a very good start for now and plays nicely with the
`--expired` flag. This soft-deprecates `stash wipe` in favor of a `stash
db wipe` with the addition of a new `--expired` flag that wipes the
expired entries only. 

The `list` subcommand has also been refactored to allow for a similar
`--expired` flag that lists only expired entries.

Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: I34107880185d231d207b0dab7782d5d96a6a6964
2026-01-22 16:56:44 +03:00
2e555ee043
commands/list: add include_expired parameter for filtering
Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: Ia1ab13345cfa5e2cf9a92f8b32a6a9826a6a6964
2026-01-22 16:56:43 +03:00
b070d4d93d
watch: implement soft-delete behaviour for expired entries
The previous `--expire-after` flag behave more like *delete* after
rather than *expire*. This fixes that, and changes the behaviour to
excluding expired entries from list commands and already-marked expired
entries from expiration queue. Updates log messages accordingly.

Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: Ib162dff3a76e23edcdfbd1af13b01b916a6a6964
2026-01-22 16:56:42 +03:00
d40b547c07
db: add is_expired column and implement vacuum/stats commands
Migrates schema to v5; `is_expired` column is added with partial index
and `include_expired` parameter to `list_entries()` and `list_json()`
methods. Also adds `vacuum()` and `stats()` methods for SQlite
"administration", and removes `next_sequence()` from trait and impl.

This has been a valuable addition to stash, as the database is now *less
abstract* in the sense that user is made aware of its presence (stash
wipe -> stash db wipe) and can modify it.

Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: Icfab67753d7f18e3798c0a930b16d05e6a6a6964
2026-01-22 16:56:41 +03:00
f4936e56ff
cli: add --expire-after flag to watch and --expired flag to list
Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: I833e7bfaecb5e3254d2ea16f2b880e246a6a6964
2026-01-22 16:56:40 +03:00
dd7a55c760
watch: implement expiration queue w/ sub-second precision
This adds a Neg wrapper struct for min-heap behaviour on BinaryHeap
which has proven *really* valuable. Also modify `watch()` to take the
`expire_after` argument for various new features. See my previous commit
for what is actually new.

Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: I8705d404eae5d93ad48f738a24f698196a6a6964
2026-01-22 16:56:39 +03:00
71fc1ff40f
db: add `expires_at column and expiration management methods
Schema v4: add expires_at REAL column with partial index for NULL values

Other relevant methods that were added:

- `now()` for Unix timestamp with sub-second precision
- `cleanup_expired()` to remove all expired entries
- `get_expired_entries()` for for diagnostic output (`stash list --expired`)
- `get_next_expiration()` for heap initialization
- `set_expiration()` to update expiration timestamp

This feature has proven larger than I had anticipated (and hoped) but
that's the reality of dealing with databases. Some of the methods are
slightly redundant but it helps keep tracing the code manageable and
semantically correct. We'll probably not regret those later. Probably.

Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: Ie9e5b0767673e74389b8e59c466afd946a6a6964
2026-01-22 16:56:38 +03:00
047445b143
db: distinguish HEIC from HEIF in mime type detection
Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: I1a25c6d30fde6b4cc33c2a1666b2e1606a6a6964
2026-01-22 13:48:30 +03:00
c65073e0d1
db: rewrite migration with transactional schema versioning
This makes Stash's database handler a bit more robust. The changes
started as me trying to add an entry expiry, but I've realized that the
database system is a little fragile and it assumed the database does not
change, ever. Well that's not true, it does change and when it does
there's a chance that everything implodes.

We now wrap migrations in transaction for atomicity and track version
via PRAGMA user_version (0 -> 3). We also check column existence before
ALTER TABLE and use `last_insert_rowid()` instead of `next_sequence()`.

Last but not least, a bunch of regression tests have been added to the
database system because I'd rather not discover regressions in
production.

Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: Ifeab42b0816a5161d736767cb82065346a6a6964
2026-01-22 13:41:58 +03:00
3165543580
commands: prevent usize underflow when navigating empty entry list
Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: I0432dcc88b22226772f6bb6e05cc64d36a6a6964
2026-01-22 13:41:57 +03:00
20b6a12461
stash: make db module public for test visibility
Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: I5f75e6515114e7479a3fe63771a4e7fe6a6a6964
2026-01-22 13:41:56 +03:00
59423f9ae4
list: add content_hash and last_accessed tracking with de-duplication
Adds a `content_hash` column and index for deduplication, and a
`last_accessed` column & index for time tracking. We now de-duplicate on
copy by not copying if present, but instead bubbling up matching entry.

Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: Icbcdbd6ac28bbb21324785cae30911f96a6a6964
2026-01-22 13:41:54 +03:00
f2274aa524
multicall: auto-select MIME type more intelligently when not specified
Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: Idfd5ab25079161d694bda429e70500a16a6a6964
2025-12-23 10:11:28 +03:00
bbfe583423
multicall: prevent newline corruption of binary data in wl-copy
Previously we unconditionally appended a newline to all clipboard
contents, which ended up corrupting binary files like PNG images when
using shell redirection (e.g., `wl-paste > file.png`). Now we
intelligently (in quotes) detect content type via MIME type and only
append newlines to text-based content such as `text/*`,
`application/json` and so on. Binary data on another hand is written
exactly as it is. Falls back to UTF-8 validation when MIME type is
unavailable.

On paper this is also fully backwards compatible; text content still
gets newline by default *unless* the `--no-newline` flag is used.

Fixes #52

Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: I8b1e6f7013d081150be761820cafd1926a6a6964
2025-12-23 09:41:19 +03:00
raf
1f0312b2f6
Merge pull request #56 from NotAShelf/notashelf/push-umuwyuqntslp
various: bump dependencies
2025-12-22 17:14:53 +03:00
c2182d21dc
chore: bump dependencies; fix lifetime warnings for Rust 1.90+
Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: If755ceefb970311c7660118cb2019c2c6a6a6964
2025-12-22 16:59:12 +03:00
a68946d54d
various: fix clippy lints
Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: I4bb649a5161460d8794dc5c93baa6cc46a6a6964
2025-11-13 00:05:52 +03:00
2d8ccf2a4f
multicall: go back to forking solution
Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: I2a24a3c7efc41fc45c675fd98e08782e6a6a6964
2025-11-13 00:05:48 +03:00
61ff65e9e8
stash: make log messages lowercase
Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: I45a9055b6bc3bfbf2179627470d0cedd6a6a6964
2025-10-28 13:02:59 +03:00
d59ac77b9f
stash: utilize clap for multicall functionality; simplify CLI handler
Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: I84d9f46bb9bba0e893aa4f99d6ff48f76a6a6964
2025-10-28 12:40:17 +03:00
78acc38044
multicall: cleanup; modularize
Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: I658f22fdf983777354a5beb32df631916a6a6964
2025-10-27 11:11:13 +03:00
955a5d51f8
multicall: cleanup; match wl-copy/wl-paste interfaces more closely
Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: I8cc05c0141cccff8378ef4fd83ccf77d6a6a6964
2025-10-25 08:38:53 +03:00
78fa23a764
multicall: remove program name prefixes from log and error messages
Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: I6a6a6964f65a0f1e473a50abfa985365ad8f1fa1
2025-10-09 14:44:45 +03:00
6496d3963d
stash: add multicall support for stash-copy and stash-paste
We can finally tell the users that they can uninstall `wl-copy` and
`wl-paste` on their systems. Stash now somewhat supports being invoked
under the names `stash-copy` and `stash-paste` to fully reimplement the
functionality of `wl-copy` and `wl-paste` respectively.

A build wrapper has been added generate symlinks for `stash-copy`, `stash-paste`,
`wl-copy`, and `wl-paste`. `wl-copy` and `wl-paste` links are provided
only for backwards compatibility, but they will not go away anytime
soon.

Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: I6a6a6964463b35427cb720fbab68b252944cc90c
2025-10-09 14:40:54 +03:00
f8440926b1
list: log clipboard copy errors and update notification message
Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: I6a6a69649bdd37a44f254d520e33a54634958ada
2025-10-09 11:45:37 +03:00