From 315f510109f9e8528b204837266a37719386ea93 Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Mon, 22 Dec 2025 16:55:47 +0100 Subject: [PATCH] Update stuff, enable automatic downloads cleanup, fix scratch buffers --- flake.lock | 66 +++--- modules/cli/home.nix | 34 ++++ modules/cli/nix/impermanence.nix | 6 - nvim/lua/plugins/scratch.lua | 8 +- overlays/default.nix | 3 - overlays/tmux-get_clipboard.diff | 332 ------------------------------- 6 files changed, 74 insertions(+), 375 deletions(-) delete mode 100644 overlays/tmux-get_clipboard.diff diff --git a/flake.lock b/flake.lock index 73abde7..ea02e69 100644 --- a/flake.lock +++ b/flake.lock @@ -3,11 +3,11 @@ "flake-compat": { "flake": false, "locked": { - "lastModified": 1761588595, - "narHash": "sha256-XKUZz9zewJNUj46b4AJdiRZJAvSZ0Dqj2BNfXvFlJC4=", + "lastModified": 1765121682, + "narHash": "sha256-4VBOP18BFeiPkyhy9o4ssBNQEvfvv1kXkasAYd0+rrA=", "owner": "edolstra", "repo": "flake-compat", - "rev": "f387cd2afec9419c8ee37694406ca490c3f34ee5", + "rev": "65f23138d8d09a92e30f1e5c87611b23ef451bf3", "type": "github" }, "original": { @@ -24,11 +24,11 @@ ] }, "locked": { - "lastModified": 1763759067, - "narHash": "sha256-LlLt2Jo/gMNYAwOgdRQBrsRoOz7BPRkzvNaI/fzXi2Q=", + "lastModified": 1765835352, + "narHash": "sha256-XswHlK/Qtjasvhd1nOa1e8MgZ8GS//jBoTqWtrS1Giw=", "owner": "hercules-ci", "repo": "flake-parts", - "rev": "2cccadc7357c0ba201788ae99c4dfa90728ef5e0", + "rev": "a34fae9c08a15ad73f295041fec82323541400a9", "type": "github" }, "original": { @@ -44,11 +44,11 @@ ] }, "locked": { - "lastModified": 1764544324, - "narHash": "sha256-GVBGjO7UsmzLrlOJV8NlKSxukHaHencrJqWkCA6FkqI=", + "lastModified": 1766387499, + "narHash": "sha256-AjK3/UKDzeXFeYNLVBaJ3+HLE9he1g5UrlNd4/BM3eA=", "owner": "nix-community", "repo": "home-manager", - "rev": "e4e25a8c310fa45f2a8339c7972dc43d2845a612", + "rev": "527ad07e6625302b648ed3b28c34b62a79bd103e", "type": "github" }, "original": { @@ -81,11 +81,11 @@ ] }, "locked": { - "lastModified": 1764547590, - "narHash": "sha256-PDVKI5QCPfzVCPY/ZYAQTHGwC9ksT8ISNVaVZDVzb54=", + "lastModified": 1766361902, + "narHash": "sha256-UvMyRzpHluglPn7b4wLBCA8DRSiUwzcS9PKhk0bCcmY=", "owner": "nix-community", "repo": "neovim-nightly-overlay", - "rev": "71ba04d8a26327031fd58284af4a4891d7b3c842", + "rev": "8d66aa1836d522d7cbfdf7a1f40046010f7cf558", "type": "github" }, "original": { @@ -97,11 +97,11 @@ "neovim-src": { "flake": false, "locked": { - "lastModified": 1764519732, - "narHash": "sha256-R0UspjBwPi5St0Dxq9Ej9ejJ34K8ivF5WeCS9dMvvVQ=", + "lastModified": 1766349065, + "narHash": "sha256-FjrwOMqBASOb0lBItQy3HyGPMcLBokzNQ/0oTiI05YA=", "owner": "neovim", "repo": "neovim", - "rev": "d62bbe24cbe5311ce595d73a0c40dc87af989666", + "rev": "d1189ea508c888ebf7468be3872c975e4ea264bb", "type": "github" }, "original": { @@ -117,11 +117,11 @@ ] }, "locked": { - "lastModified": 1764161084, - "narHash": "sha256-HN84sByg9FhJnojkGGDSrcjcbeioFWoNXfuyYfJ1kBE=", + "lastModified": 1766038392, + "narHash": "sha256-ht/GuKaw5NT3M12xM+mkUtkSBVtzjJ8IHIy6R/ncv9g=", "owner": "LnL7", "repo": "nix-darwin", - "rev": "e95de00a471d07435e0527ff4db092c84998698e", + "rev": "5fb45ece6129bd7ad8f7310df0ae9c00bae7c562", "type": "github" }, "original": { @@ -137,11 +137,11 @@ ] }, "locked": { - "lastModified": 1764475780, - "narHash": "sha256-77jL5H5x51ksLiOUDjY0ZK8e2T4ZXLhj3ap8ETvknWI=", + "lastModified": 1765267181, + "narHash": "sha256-d3NBA9zEtBu2JFMnTBqWj7Tmi7R5OikoU2ycrdhQEws=", "owner": "nix-community", "repo": "nix-index-database", - "rev": "5a3ff8c1a09003f399f43d5742d893c0b1ab8af0", + "rev": "82befcf7dc77c909b0f2a09f5da910ec95c5b78f", "type": "github" }, "original": { @@ -192,11 +192,11 @@ ] }, "locked": { - "lastModified": 1764072830, - "narHash": "sha256-ezkjlUCohD9o9c47Ey0/I4CamSS0QEORTqGvyGqMud0=", + "lastModified": 1765841014, + "narHash": "sha256-55V0AJ36V5Egh4kMhWtDh117eE3GOjwq5LhwxDn9eHg=", "owner": "nix-community", "repo": "NixOS-WSL", - "rev": "c7832dd786175e20f2697179e0e03efadffe4201", + "rev": "be4af8042e7a61fa12fda58fe9a3b3babdefe17b", "type": "github" }, "original": { @@ -223,11 +223,11 @@ }, "nixpkgs_2": { "locked": { - "lastModified": 1764517877, - "narHash": "sha256-pp3uT4hHijIC8JUK5MEqeAWmParJrgBVzHLNfJDZxg4=", + "lastModified": 1766309749, + "narHash": "sha256-3xY8CZ4rSnQ0NqGhMKAy5vgC+2IVK0NoVEzDoOh4DA4=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "2d293cbfa5a793b4c50d17c05ef9e385b90edf6c", + "rev": "a6531044f6d0bef691ea18d4d4ce44d0daa6e816", "type": "github" }, "original": { @@ -275,11 +275,11 @@ "tmux": { "flake": false, "locked": { - "lastModified": 1764577332, - "narHash": "sha256-v7GmXzUZpXh88+GptfUZ8JBm6SH2MYvcmURjJduAvyw=", + "lastModified": 1766397668, + "narHash": "sha256-itzAG88YfyiZUIHBWVbJ6wjADkYbx2r6lcHbdpxWVTA=", "owner": "tmux", "repo": "tmux", - "rev": "b2d6ebaa1067ddc7aa7b760318faa24822c77f8c", + "rev": "d607399850879359025fa4160c4dee943ad32be4", "type": "github" }, "original": { @@ -295,11 +295,11 @@ ] }, "locked": { - "lastModified": 1764476124, - "narHash": "sha256-QHvDAJdc7Sx8rIUpEjZYtn9n334F0Rg/8C/NcUWv7M4=", + "lastModified": 1766377218, + "narHash": "sha256-y3g3OqPB0tmRjbHJNnJKivSQRtAJR+/9S1xbxBWEatg=", "owner": "youwen5", "repo": "zen-browser-flake", - "rev": "0f07eb42107d2b82d8a2e94d3c01aa3d7f500733", + "rev": "2f61341b32dd69c07e147188e67e09ba2bb99c33", "type": "github" }, "original": { diff --git a/modules/cli/home.nix b/modules/cli/home.nix index 2c2396c..1a656c6 100644 --- a/modules/cli/home.nix +++ b/modules/cli/home.nix @@ -1,4 +1,8 @@ { + pkgs, + lib, + ... +}: { imports = [ ./zsh ./tools/git.nix @@ -26,5 +30,35 @@ }; }; + systemd.user.services.download-clears = let + script = pkgs.writeShellScriptBin "download-clears" '' + find ~/downloads -mtime +30 -delete + ''; + in { + Unit = { + Description = "Clean up files older than 30 days in Downloads"; + }; + Service = { + Type = "oneshot"; + ExecStart = lib.getExe script; + }; + Install = { + WantedBy = ["default.target"]; + }; + }; + + systemd.user.timers.download-clears = { + Unit = { + Description = "Clear old downloads"; + }; + Timer = { + OnCalendar = "daily"; + Persistent = true; + }; + Install = { + WantedBy = ["timers.target"]; + }; + }; + home.stateVersion = "22.11"; } diff --git a/modules/cli/nix/impermanence.nix b/modules/cli/nix/impermanence.nix index bdec4dc..e1d61ce 100644 --- a/modules/cli/nix/impermanence.nix +++ b/modules/cli/nix/impermanence.nix @@ -23,14 +23,8 @@ "/var/lib/flatpak" "/var/lib/tcc" "/var/lib/flood" - "/var/lib/transmission" - "/var/lib/gitea" "/var/lib/acme" - "/var/lib/loki" - "/var/lib/mimir" - "/var/lib/tempo" "/etc/NetworkManager/system-connections" - "/etc/tailord/" ]; files = [ "/etc/machine-id" diff --git a/nvim/lua/plugins/scratch.lua b/nvim/lua/plugins/scratch.lua index 334d835..8fad0a5 100644 --- a/nvim/lua/plugins/scratch.lua +++ b/nvim/lua/plugins/scratch.lua @@ -6,7 +6,13 @@ local function scratch() if ft == nil then return end - local buf = vim.api.nvim_create_buf(false, true) + + if vim.loop.fs_stat("/tmp/scratch") == nil then + vim.loop.fs_mkdir("/tmp/scratch", 448) -- 0o700 + end + + local buf = vim.api.nvim_create_buf(false, false) + vim.api.nvim_buf_set_name(buf, "/tmp/scratch/" .. tostring(os.time()) .. "." .. ft) vim.api.nvim_set_option_value("filetype", ft, { buf = buf }) vim.api.nvim_set_current_buf(buf) end) diff --git a/overlays/default.nix b/overlays/default.nix index 5dd0031..2c03c72 100644 --- a/overlays/default.nix +++ b/overlays/default.nix @@ -18,9 +18,6 @@ in { tmux = super.tmux.overrideAttrs { src = tmux; - patches = [ - ./tmux-get_clipboard.diff - ]; }; # they try to use passthrough if they detect tmux. we don't want that. diff --git a/overlays/tmux-get_clipboard.diff b/overlays/tmux-get_clipboard.diff deleted file mode 100644 index fe461f9..0000000 --- a/overlays/tmux-get_clipboard.diff +++ /dev/null @@ -1,332 +0,0 @@ -# source: https://github.com/tmux/tmux/issues/4275 -diff --git a/input.c b/input.c -index 3a61ec26..58a1b091 100644 ---- a/input.c -+++ b/input.c -@@ -3069,18 +3069,41 @@ input_osc_133(struct input_ctx *ictx, const char *p) - } - } - -+/* Handle OSC 52 reply. */ -+static void -+input_osc_52_reply(struct input_ctx *ictx) -+{ -+ struct paste_buffer *pb; -+ int state; -+ const char *buf; -+ size_t len; -+ -+ state = options_get_number(global_options, "get-clipboard"); -+ if (state == 0) -+ return; -+ if (state == 1) { -+ if ((pb = paste_get_top(NULL)) == NULL) -+ return; -+ buf = paste_buffer_data(pb, &len); -+ if (ictx->input_end == INPUT_END_BEL) -+ input_reply_clipboard(ictx->event, buf, len, "\007"); -+ else -+ input_reply_clipboard(ictx->event, buf, len, "\033\\"); -+ return; -+ } -+ input_add_request(ictx, INPUT_REQUEST_CLIPBOARD, ictx->input_end); -+} -+ - /* Handle the OSC 52 sequence for setting the clipboard. */ - static void - input_osc_52(struct input_ctx *ictx, const char *p) - { - struct window_pane *wp = ictx->wp; -+ size_t len; - char *end; -- const char *buf = NULL; -- size_t len = 0; - u_char *out; - int outlen, state; - struct screen_write_ctx ctx; -- struct paste_buffer *pb; - const char* allow = "cpqs01234567"; - char flags[sizeof "cpqs01234567"] = ""; - u_int i, j = 0; -@@ -3105,12 +3128,7 @@ input_osc_52(struct input_ctx *ictx, const char *p) - log_debug("%s: %.*s %s", __func__, (int)(end - p - 1), p, flags); - - if (strcmp(end, "?") == 0) { -- if ((pb = paste_get_top(NULL)) != NULL) -- buf = paste_buffer_data(pb, &len); -- if (ictx->input_end == INPUT_END_BEL) -- input_reply_clipboard(ictx->event, buf, len, "\007"); -- else -- input_reply_clipboard(ictx->event, buf, len, "\033\\"); -+ input_osc_52_reply(ictx); - return; - } - -@@ -3169,6 +3187,7 @@ input_osc_104(struct input_ctx *ictx, const char *p) - free(copy); - } - -+/* Send a clipboard reply. */ - void - input_reply_clipboard(struct bufferevent *bev, const char *buf, size_t len, - const char *end) -@@ -3305,6 +3324,9 @@ input_add_request(struct input_ctx *ictx, enum input_request_type type, int idx) - xsnprintf(s, sizeof s, "\033]4;%d;?\033\\", idx); - tty_puts(&c->tty, s); - break; -+ case INPUT_REQUEST_CLIPBOARD: -+ tty_putcode_ss(&c->tty, TTYC_MS, "", "?"); -+ break; - case INPUT_REQUEST_QUEUE: - break; - } -@@ -3312,6 +3334,39 @@ input_add_request(struct input_ctx *ictx, enum input_request_type type, int idx) - return (0); - } - -+/* Handle a palette reply. */ -+static void -+input_request_palette_reply(struct input_request *ir, void *data) -+{ -+ struct input_request_palette_data *pd = data; -+ -+ input_osc_colour_reply(ir->ictx, 0, 4, pd->idx, pd->c, ir->end); -+} -+ -+/* Handle a clipboard reply. */ -+static void -+input_request_clipboard_reply(struct input_request *ir, void *data) -+{ -+ struct input_ctx *ictx = ir->ictx; -+ struct input_request_clipboard_data *cd = data; -+ int state; -+ char *copy; -+ -+ state = options_get_number(global_options, "get-clipboard"); -+ if (state == 0 || state == 1) -+ return; -+ if (state == 3) { -+ copy = xmalloc(cd->len); -+ memcpy(copy, cd->buf, cd->len); -+ paste_add(NULL, copy, cd->len); -+ } -+ -+ if (ir->idx == INPUT_END_BEL) -+ input_reply_clipboard(ictx->event, cd->buf, cd->len, "\007"); -+ else -+ input_reply_clipboard(ictx->event, cd->buf, cd->len, "\033\\"); -+} -+ - /* Handle a reply to a request. */ - void - input_request_reply(struct client *c, enum input_request_type type, void *data) -@@ -3321,11 +3376,18 @@ input_request_reply(struct client *c, enum input_request_type type, void *data) - int complete = 0; - - TAILQ_FOREACH_SAFE(ir, &c->input_requests, centry, ir1) { -- if (ir->type == type && pd->idx == ir->idx) { -+ if (ir->type != type) { -+ input_free_request(ir); -+ continue; -+ } -+ if (type == INPUT_REQUEST_PALETTE && pd->idx == ir->idx) { -+ found = ir; -+ break; -+ } -+ if (type == INPUT_REQUEST_CLIPBOARD) { - found = ir; - break; - } -- input_free_request(ir); - } - if (found == NULL) - return; -@@ -3335,8 +3397,11 @@ input_request_reply(struct client *c, enum input_request_type type, void *data) - break; - if (ir->type == INPUT_REQUEST_QUEUE) - input_send_reply(ir->ictx, ir->data); -- else if (ir == found && ir->type == INPUT_REQUEST_PALETTE) { -- input_osc_colour_reply(ir->ictx, 0, 4, pd->idx, pd->c, ir->end); -+ else if (ir == found) { -+ if (ir->type == INPUT_REQUEST_PALETTE) -+ input_request_palette_reply(ir, data); -+ else if (ir->type == INPUT_REQUEST_CLIPBOARD) -+ input_request_clipboard_reply(ir, data); - complete = 1; - } - input_free_request(ir); -diff --git a/options-table.c b/options-table.c -index 6946a085..b3ba39cd 100644 ---- a/options-table.c -+++ b/options-table.c -@@ -84,6 +84,9 @@ static const char *options_table_popup_border_lines_list[] = { - static const char *options_table_set_clipboard_list[] = { - "off", "external", "on", NULL - }; -+static const char *options_table_get_clipboard_list[] = { -+ "off", "buffer", "request", "both", NULL -+}; - static const char *options_table_window_size_list[] = { - "largest", "smallest", "manual", "latest", NULL - }; -@@ -405,6 +408,18 @@ const struct options_table_entry options_table[] = { - .text = "Whether to send focus events to applications." - }, - -+ { .name = "get-clipboard", -+ .type = OPTIONS_TABLE_CHOICE, -+ .scope = OPTIONS_TABLE_SERVER, -+ .choices = options_table_get_clipboard_list, -+ .default_num = 1, -+ .text = "When an application requests the clipboard, whether to " -+ "ignore the request ('off'); respond with the newest buffer " -+ "('buffer'); request the clipboard from the most recently " -+ "used terminal ('request'); or to request the clipboard, " -+ "create a buffer, and send it to the application ('both')." -+ }, -+ - { .name = "history-file", - .type = OPTIONS_TABLE_STRING, - .scope = OPTIONS_TABLE_SERVER, -diff --git a/tmux.1 b/tmux.1 -index a25da1fb..2ae1b724 100644 ---- a/tmux.1 -+++ b/tmux.1 -@@ -4241,6 +4241,32 @@ passed through to applications running in - .Nm . - Attached clients should be detached and attached again after changing this - option. -+.It Xo Ic get-clipboard -+.Op Ic both | request | buffer | off -+.Xc -+Controls the behaviour when an application requests the clipboard from -+.Nm . -+.Pp -+If -+.Ic off , -+the request is ignored; -+if -+.Ic buffer , -+.Nm -+responds with the newest paste buffer; -+.Ic request -+causes -+.Nm -+to request the clipboard from the most recently used client (if possible) and -+send the reply (if any) back to the application; -+.Ic buffer -+is the same as -+.Ic request -+but also creates a paste buffer. -+.Pp -+See also the -+.Ic set-clipboard -+option. - .It Ic history-file Ar path - If not empty, a file to which - .Nm -diff --git a/tmux.h b/tmux.h -index c3959d2a..3dece217 100644 ---- a/tmux.h -+++ b/tmux.h -@@ -1129,6 +1129,7 @@ struct window_mode_entry { - /* Type of request to client. */ - enum input_request_type { - INPUT_REQUEST_PALETTE, -+ INPUT_REQUEST_CLIPBOARD, - INPUT_REQUEST_QUEUE - }; - -@@ -1138,6 +1139,12 @@ struct input_request_palette_data { - int c; - }; - -+/* Clipboard request reply data. */ -+struct input_request_clipboard_data { -+ char *buf; -+ size_t len; -+}; -+ - /* Request sent to client on behalf of pane. */ - TAILQ_HEAD(input_requests, input_request); - -diff --git a/tty-keys.c b/tty-keys.c -index 77254591..7acee80f 100644 ---- a/tty-keys.c -+++ b/tty-keys.c -@@ -1301,12 +1301,13 @@ tty_keys_mouse(struct tty *tty, const char *buf, size_t len, size_t *size, - static int - tty_keys_clipboard(struct tty *tty, const char *buf, size_t len, size_t *size) - { -- struct client *c = tty->client; -- struct window_pane *wp; -- size_t end, terminator = 0, needed; -- char *copy, *out; -- int outlen; -- u_int i; -+ struct client *c = tty->client; -+ struct window_pane *wp; -+ size_t end, terminator = 0, needed; -+ char *copy, *out; -+ int outlen; -+ u_int i; -+ struct input_request_clipboard_data cd; - - *size = 0; - -@@ -1364,12 +1365,6 @@ tty_keys_clipboard(struct tty *tty, const char *buf, size_t len, size_t *size) - buf++; - end--; - -- /* If we did not request this, ignore it. */ -- if (~tty->flags & TTY_OSC52QUERY) -- return (0); -- tty->flags &= ~TTY_OSC52QUERY; -- evtimer_del(&tty->clipboard_timer); -- - /* It has to be a string so copy it. */ - copy = xmalloc(end + 1); - memcpy(copy, buf, end); -@@ -1384,18 +1379,37 @@ tty_keys_clipboard(struct tty *tty, const char *buf, size_t len, size_t *size) - return (0); - } - free(copy); -- -- /* Create a new paste buffer and forward to panes. */ - log_debug("%s: %.*s", __func__, outlen, out); -- if (c->flags & CLIENT_CLIPBOARDBUFFER) { -- paste_add(NULL, out, outlen); -- c->flags &= ~CLIENT_CLIPBOARDBUFFER; -+ -+ /* Set reply if any. */ -+ if (c->clipboard_npanes == 0) { -+ cd.buf = out; -+ cd.len = outlen; -+ input_request_reply(c, INPUT_REQUEST_CLIPBOARD, &cd); -+ free(out); -+ return (0); - } -+ -+ /* If we did not request this, ignore it. */ -+ if (~tty->flags & TTY_OSC52QUERY) { -+ free(out); -+ return (0); -+ } -+ tty->flags &= ~TTY_OSC52QUERY; -+ evtimer_del(&tty->clipboard_timer); -+ -+ /* Create a new paste buffer and forward to panes. */ - for (i = 0; i < c->clipboard_npanes; i++) { - wp = window_pane_find_by_id(c->clipboard_panes[i]); - if (wp != NULL) - input_reply_clipboard(wp->event, out, outlen, "\033\\"); - } -+ if (~c->flags & CLIENT_CLIPBOARDBUFFER) -+ free (out); -+ else { -+ paste_add(NULL, out, outlen); -+ c->flags &= ~CLIENT_CLIPBOARDBUFFER; -+ } - free(c->clipboard_panes); - c->clipboard_panes = NULL; - c->clipboard_npanes = 0;