tangled
alpha
login
or
join now
karitham.dev
/
dotfiles
0
fork
atom
a dotfile but it's really big
0
fork
atom
overview
issues
pulls
pipelines
editor: pull out copy-remote-path script
karitham.dev
1 month ago
2d0a9a2d
68bec351
verified
This commit was signed with the committer's
known signature
.
karitham.dev
SSH Key Fingerprint:
SHA256:ODeRMGYuG7M/0G+fRF6IfwUk7r5AgG5MYdFTN+uvimc=
+41
-10
2 changed files
expand all
collapse all
unified
split
modules
dev
editor
copy-remote-path.nu
helix.nix
+40
modules/dev/editor/copy-remote-path.nu
···
1
1
+
#!/usr/bin/env nix-shell
2
2
+
#!nix-shell -i nu -p nushell jujutsu wl-clipboard
3
3
+
4
4
+
# Generates a remote git URL for the given file and line, and copies it to the clipboard.
5
5
+
def main [
6
6
+
file: string # Absolute or relative path to the file
7
7
+
--line-start (-s): string # The starting line number (e.g., cursor line)
8
8
+
--line-end (-e): string # The ending line number (for selections)
9
9
+
] {
10
10
+
let root = (jj workspace root | str trim)
11
11
+
let rel_path = ($file | path expand | path relative-to $root)
12
12
+
13
13
+
# Intersect current ancestry with the ancestry of all remote bookmarks
14
14
+
let ref = (jj log -r "heads(::@ & ::remote_bookmarks())" -n 1 --no-graph -T "commit_id" | str trim)
15
15
+
16
16
+
if ($ref | is-empty) {
17
17
+
print -e "Error: No pushed commits found in the current ancestry."
18
18
+
exit 1
19
19
+
}
20
20
+
21
21
+
let remote_url = (
22
22
+
jj git remote list
23
23
+
| parse "{remote} {url}"
24
24
+
| where remote == "origin"
25
25
+
| get url.0
26
26
+
| if ($in | str contains "://") { $in } else { $"https://($in | str replace ':' '/')" }
27
27
+
| url parse
28
28
+
)
29
29
+
30
30
+
# Construct the line number suffix (GitHub format)
31
31
+
let start = if ($line_start | is-empty) { "" } else { $line_start }
32
32
+
let end = if ($line_end | is-empty) { "" } else { $"-L($line_end)" }
33
33
+
let line_suffix = if ($start | is-empty) { "" } else { $"#L($start)($end)" }
34
34
+
35
35
+
# Construct the final URL
36
36
+
let url = $"https://($remote_url.host)($remote_url.path | str replace '.git' '')/blob/($ref)/($rel_path)($line_suffix)"
37
37
+
38
38
+
$url | wl-copy
39
39
+
print -e $"Copied to clipboard: ($url)"
40
40
+
}
+1
-10
modules/dev/editor/helix.nix
···
49
49
let
50
50
plusMenu = {
51
51
g = ''
52
52
-
:sh ${pkgs.nushell}/bin/nu -c '
53
53
-
let line = ("%{selection_line_start}" | default "%{cursor_line}")
54
54
-
let line_end = (if ("%{selection_line_end}" | is-not-empty) {$"-L%{selection_line_end}"} else "")
55
55
-
let root = (${pkgs.jujutsu}/bin/jj workspace root | str trim)
56
56
-
let rel_path = ("%{file_path_absolute}" | path relative-to $root)
57
57
-
let ref = (${pkgs.jujutsu}/bin/jj log -r "heads(::@ & bookmarks())" -n 1 --no-graph -T "commit_id")
58
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
59
-
let url = $"https://($remote_url.host)($remote_url.path | str replace ".git" "")/blob/($ref)/($rel_path)#L($line)($line_end)"
60
60
-
$url | ${pkgs.wl-clipboard}/bin/wl-copy
61
61
-
'
52
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";