Fish · 1056 bytes Raw Blame History
1 ## open file at a specific line in editor (agnostic. sorta)
2 #
3 function open_at_line
4 set -l file $argv[1]; set -l line $argv[2]
5 if test -z "$file" -o -z "$line"
6 echo "usage: open_at_line <file> <line>"; return 1
7 end
8
9 # Extract the base command from $EDITOR ("code --wait" -> "code")
10 set -l editor_base (basename -- (string split ' ' -- $EDITOR)[1])
11
12 switch $editor_base
13 case 'code' 'code-insiders'
14 # VS Code: --goto file:line
15 $EDITOR -g "$file":$line
16
17 case 'hx'
18 # Helix understands path:row[:col] in recent builds; fall back to +LINE
19 hx "$file":$line; or hx +$line "$file"
20
21 case 'micro'
22 # Micro: enable parsecursor so file:line works reliably
23 micro --parsecursor "$file":$line
24
25 case 'nvim' 'vim' 'vi' 'kak' 'nano'
26 # Many TUI editors accept +LINE
27 $EDITOR +$line "$file"
28
29 case '*'
30 # Generic fallback used by many editors (sed-like)
31 $EDITOR +$line "$file"
32 end
33 end