From 3b7e3811eda5d383ee5a99a65fbd8cb962e067f9 Mon Sep 17 00:00:00 2001 From: karitham Date: Sat, 13 Jun 2026 22:31:03 +0200 Subject: [PATCH] editor: fast copy-remote-path --- modules/dev/editor/copy-remote-path.nu | 32 +++++++++++++++++++------- modules/dev/editor/helix.nix | 4 +--- modules/dev/tools/scripts/ll.nu | 6 ++--- modules/wsl/default.nix | 5 +++- 4 files changed, 32 insertions(+), 15 deletions(-) diff --git a/modules/dev/editor/copy-remote-path.nu b/modules/dev/editor/copy-remote-path.nu index 4ca9327..c26ca90 100755 --- a/modules/dev/editor/copy-remote-path.nu +++ b/modules/dev/editor/copy-remote-path.nu @@ -1,21 +1,37 @@ -#!/usr/bin/env nix-shell -#!nix-shell -i nu -p nushell jujutsu wl-clipboard +#!/usr/bin/env -S nu --no-config-file +# # Generates a remote git URL for the given file and line, and copies it to the clipboard. +# Requires `jj`, `nu`, and a clipboard command (`wl-copy` by default) to be available. +# Set COPY_REMOTE_PATH_CLIPBOARD to use a different clipboard command. +def clipboard-copy [text: string] { + let cmd = $env.COPY_REMOTE_PATH_CLIPBOARD? | default "wl-copy" + $text | run-external $cmd +} + def main [ file: string # Absolute or relative path to the file --line-start (-s): string # The starting line number (e.g., cursor line) --line-end (-e): string # The ending line number (for selections) ] { - let root = (jj workspace root | str trim) - let rel_path = ($file | path expand | path relative-to $root) - # Intersect current ancestry with the ancestry of all remote bookmarks - let ref = (jj log -r "heads(::@ & ::remote_bookmarks())" -n 1 --no-graph -T "commit_id" | str trim) + + # Spawn independent jj queries in parallel; each sends its result back to the main thread. + job spawn { (jj workspace root | str trim) | job send --tag 1 0 } + job spawn { (jj log -r "heads(::@ & ::remote_bookmarks('*', 'origin'))" -n 1 --no-graph -T "commit_id" | str trim) | job send --tag 2 0 } + job spawn { (jj git remote list) | job send --tag 3 0 } + + let root = job recv --tag 1 + let ref = job recv --tag 2 + let remote_list = job recv --tag 3 + + let rel_path = $file | path expand | path relative-to $root + if ($ref | is-empty) { print -e "Error: No pushed commits found in the current ancestry." exit 1 } + let remote_url = ( - jj git remote list | parse "{remote} {url}" | where remote == "origin" | get url.0 | if ($in | str contains "://") { $in } else { $"https://($in | str replace ':' '/')" } | url parse + $remote_list | lines | parse "{remote} {url}" | where remote == "origin" | get url.0 | if ($in | str contains "://") { $in } else { $"https://($in | str replace ':' '/')" } | url parse ) # Construct the line number suffix (GitHub format) let start = if ($line_start | is-empty) { "" } else { $line_start } @@ -23,6 +39,6 @@ def main [ let line_suffix = if ($start | is-empty) { "" } else { $"#L($start)($end)" } # Construct the final URL let url = $"https://($remote_url.host)($remote_url.path | str replace '.git' '')/blob/($ref)/($rel_path)($line_suffix)" - $url | wl-copy + clipboard-copy $url print -e $"Copied to clipboard: ($url)" } diff --git a/modules/dev/editor/helix.nix b/modules/dev/editor/helix.nix index 9ab4e5d..b13cbad 100644 --- a/modules/dev/editor/helix.nix +++ b/modules/dev/editor/helix.nix @@ -95,9 +95,7 @@ lib.mkIf osConfig.dev.editor.enable { keys = let plusMenu = { - g = '' - :sh ${./copy-remote-path.nu} "%{buffer_name}" --line-start "%{selection_line_start}" --line-end "%{selection_line_end}" - ''; + g = ":sh ${./copy-remote-path.nu} %{buffer_name} --line-start %{selection_line_start} --line-end %{selection_line_end}"; b = ":echo %sh{git blame -L %{cursor_line},+1 %{buffer_name}}"; p = ":sh echo %{buffer_name} | ${pkgs.wl-clipboard}/bin/wl-copy"; }; diff --git a/modules/dev/tools/scripts/ll.nu b/modules/dev/tools/scripts/ll.nu index 08dc896..3f4c879 100755 --- a/modules/dev/tools/scripts/ll.nu +++ b/modules/dev/tools/scripts/ll.nu @@ -2,11 +2,11 @@ # we assume jj & nushell & libnotify are in path def main [] { let now = (date now) - let date_path = ($now | format date "%Y/%m") - let day_file = ($now | format date "%d.md") + let date_path = $now | format date "%Y/%m" + let day_file = $now | format date "%d.md" let log_dir = $"($env.HOME)/notes/logs/($date_path)" mkdir $log_dir - let target = ($log_dir | path join $day_file) + let target = $log_dir | path join $day_file run-external $env.EDITOR $target cd $log_dir jj describe -m $"Log update: ($now | format date '%F %T')" diff --git a/modules/wsl/default.nix b/modules/wsl/default.nix index ba543bb..f5250af 100644 --- a/modules/wsl/default.nix +++ b/modules/wsl/default.nix @@ -36,7 +36,10 @@ in }; environment = { - variables.BROWSER = mkForce "wsl-open"; + variables = { + BROWSER = mkForce "wsl-open"; + COPY_REMOTE_PATH_CLIPBOARD = "clip.exe"; + }; systemPackages = [ pkgs.wsl-open ]; }; -- 2.51.2