forked from google/vroom
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsystem.vroom
100 lines (60 loc) · 2.02 KB
/
system.vroom
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
Sometimes, vim makes calls to the system at large. That could be bad during
testing if your plugin is hitting a network or launching the nukes.
Vroom provides you with two tools to handle vim system calls.
Firstly, you can verify that system calls match a certain expected pattern:
:.!echo "Hey system, talk to me."
! echo .*
System calls are matched in regex mode by default.
This works with :call as well.
:echomsg system('echo hi')
! echo hi (verbatim)
~ hi
If the system call that vim actually makes doesn't match the one you specify,
vroom will complain.
By default, any unexpected system calls will trigger a failure. This strictness
helps protect you from unknowingly triggering system calls that succeed in your
environment but fail when others try to run them, and also encourages you to
document your expectations. But if this gets annoying, you can always turn it
off with @system (RELAXED).
@system (RELAXED)
:.!echo "Come at me, bro."
This is nice, but it doesn't really give you much control over the system. To do
that, you need to hijack the system and hoodwink vim:
:.!echo "Hey system, talk to me."
! echo "Hey system, talk to me\."
$ No. I'm not talking.
Let's check whether or not that worked:
No. I'm not talking.
Good!
If you need newlines in your dummy output, string hijack commands together.
:.!echo "Please?"
! echo "Please\?"
$ No!
$ Go away.
No!
Go away.
You may use system hijack lines to change the exit status using the "status"
control word:
:.!echo "Testing"
$ 2 (status)
:echomsg v:shell_error
~ 2
Or even to change the command entirely:
:.!rm "Testing."
$ echo "Testing." (command)
Testing.
The default output channel is 'stdout'. You may explicitly mark it if you wish.
:.!echo "Testing"
$ .gnitseT (stdout)
.gnitseT
If you capture a command with a regex, the regex's match groups will be
available to hijack lines.
:.!rm hello
! rm (\w+)
$ echo \1 (command)
hello
:.!rm hello
! rm (\w+)
$ \1 \1
hello hello
@system