-
Notifications
You must be signed in to change notification settings - Fork 0
/
veditline.v
48 lines (47 loc) · 1.16 KB
/
veditline.v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import os
fn main() {
mut final_editor_cmd := os.args[0][1..]
if os.args.len < 2 {
eprintln('Usage: `v${final_editor_cmd} FILE:LINE: ...`')
exit(1)
}
if '--install' in os.args {
aliases_names := os.args[1..].filter(!it.starts_with('-'))
exepath := os.executable()
for aname in aliases_names {
target := os.join_path('/usr/local/bin', aname)
os.system('sudo rm -f ${target}')
os.system('sudo ln -s ${exepath} ${target}')
}
return
}
mut res := []string{}
for x in os.args[1..] {
parts := x.split(':')
match parts.len {
0 {
res << x
}
1 {
res << parts[0]
}
else {
match final_editor_cmd {
'e' { res << ['+${parts[1]}', parts[0]] }
'emacs' { res << ['+${parts[1]}', parts[0]] }
'kate' { res << [parts[0], '--line', parts[1]] }
'jed' { res << [parts[0], '-g', parts[1]] }
'vim' { res << ['+${parts[1]}', parts[0]] }
'pico' { res << ['+${parts[1]}', parts[0]] }
'nano' { res << ['+${parts[1]}', parts[0]] }
else { res << parts[0] }
}
}
}
}
if final_editor_cmd == 'e' {
final_editor_cmd = 'emacsclient'
res.insert(0, ["-a=''", '-t', '-r'])
}
os.execvp(final_editor_cmd, res)!
}