a dotfile but it's really big

editor: pull out copy-remote-path script

karitham.dev 2d0a9a2d 68bec351

verified
+41 -10
+40
modules/dev/editor/copy-remote-path.nu
··· 1 + #!/usr/bin/env nix-shell 2 + #!nix-shell -i nu -p nushell jujutsu wl-clipboard 3 + 4 + # Generates a remote git URL for the given file and line, and copies it to the clipboard. 5 + def main [ 6 + file: string # Absolute or relative path to the file 7 + --line-start (-s): string # The starting line number (e.g., cursor line) 8 + --line-end (-e): string # The ending line number (for selections) 9 + ] { 10 + let root = (jj workspace root | str trim) 11 + let rel_path = ($file | path expand | path relative-to $root) 12 + 13 + # Intersect current ancestry with the ancestry of all remote bookmarks 14 + let ref = (jj log -r "heads(::@ & ::remote_bookmarks())" -n 1 --no-graph -T "commit_id" | str trim) 15 + 16 + if ($ref | is-empty) { 17 + print -e "Error: No pushed commits found in the current ancestry." 18 + exit 1 19 + } 20 + 21 + let remote_url = ( 22 + jj git remote list 23 + | parse "{remote} {url}" 24 + | where remote == "origin" 25 + | get url.0 26 + | if ($in | str contains "://") { $in } else { $"https://($in | str replace ':' '/')" } 27 + | url parse 28 + ) 29 + 30 + # Construct the line number suffix (GitHub format) 31 + let start = if ($line_start | is-empty) { "" } else { $line_start } 32 + let end = if ($line_end | is-empty) { "" } else { $"-L($line_end)" } 33 + let line_suffix = if ($start | is-empty) { "" } else { $"#L($start)($end)" } 34 + 35 + # Construct the final URL 36 + let url = $"https://($remote_url.host)($remote_url.path | str replace '.git' '')/blob/($ref)/($rel_path)($line_suffix)" 37 + 38 + $url | wl-copy 39 + print -e $"Copied to clipboard: ($url)" 40 + }
+1 -10
modules/dev/editor/helix.nix
··· 49 49 let 50 50 plusMenu = { 51 51 g = '' 52 - :sh ${pkgs.nushell}/bin/nu -c ' 53 - let line = ("%{selection_line_start}" | default "%{cursor_line}") 54 - let line_end = (if ("%{selection_line_end}" | is-not-empty) {$"-L%{selection_line_end}"} else "") 55 - let root = (${pkgs.jujutsu}/bin/jj workspace root | str trim) 56 - let rel_path = ("%{file_path_absolute}" | path relative-to $root) 57 - let ref = (${pkgs.jujutsu}/bin/jj log -r "heads(::@ & bookmarks())" -n 1 --no-graph -T "commit_id") 58 - let remote_url = (${pkgs.jujutsu}/bin/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) 59 - let url = $"https://($remote_url.host)($remote_url.path | str replace ".git" "")/blob/($ref)/($rel_path)#L($line)($line_end)" 60 - $url | ${pkgs.wl-clipboard}/bin/wl-copy 61 - ' 52 + :sh ${./copy-remote-path.nu} "%{file_path_absolute}" --line-start "%{selection_line_start}" --line-end "%{selection_line_end}" 62 53 ''; 63 54 b = ":echo %sh{git blame -L %{cursor_line},+1 %{buffer_name}}"; 64 55 p = ":sh echo %{buffer_name} | ${pkgs.wl-clipboard}/bin/wl-copy";