Last active
November 17, 2020 09:10
-
-
Save spytheman/9156fac182726dea940125eb0af62a83 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
fn C.execvp(file charptr, argv &charptr) int | |
fn main() { | |
final_editor_cmd := os.file_name(os.args[0])[1..] | |
if os.args.len < 2 { | |
eprintln('Usage: `v$final_editor_cmd FILE:LINE: ...`') | |
exit(1) | |
} | |
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 { | |
'kate' { res << [parts[0], '--line', parts[1]] } | |
'jed' { res << [parts[0], '-g', parts[1]] } | |
'vim', 'emacs' { res << ['+${parts[1]}', parts[0]] } | |
else { res << parts[0] } | |
} } | |
} | |
} | |
mut a := []charptr{} | |
a << final_editor_cmd.str | |
for i in 0 .. res.len { | |
a << res[i].str | |
} | |
a << charptr(0) | |
C.execvp(final_editor_cmd.str, a.data) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment