@@ -13,25 +13,44 @@ const (
1313 shellBufferRightVariableName = "__pmy_out_buffer_right"
1414 shellCommandVariableName = "__pmy_out_command"
1515 shellSourcesVariableName = "__pmy_out_sources"
16+ shellAfterVariableName = "__pmy_out_%s_after"
1617)
1718
19+ type afterCmd struct {
20+ tag string
21+ after string
22+ }
23+
1824// pmyOut represents Output of pmy against zsh routine.
1925// This struct has strings exported to shell, whose embedded
2026// variables are all expanded.
2127type pmyOut struct {
2228 BufferLeft string `json:"bufferLeft"`
2329 BufferRight string `json:"bufferRight"`
2430 Sources string `json:"source"`
31+ afterCmds []* afterCmd
2532}
2633
2734// newPmyOutFromRule create new pmyOut from rule
2835// which matches query and already has paramMap
2936func newPmyOutFromRule (rule * pmyRule ) pmyOut {
3037 out := pmyOut {}
38+ // pass sources
3139 out .Sources , _ = rule .CmdGroups .GetSources ()
40+ // pass resulting buffer informaiton
3241 out .BufferLeft = rule .BufferLeft
3342 out .BufferRight = rule .BufferRight
43+ // expand all parameters
3444 out .expandAll (rule .paramMap )
45+ // set after commnad
46+ out .afterCmds = []* afterCmd {}
47+ for _ , cg := range rule .CmdGroups {
48+ ac := & afterCmd {
49+ tag : cg .Tag ,
50+ after : cg .After ,
51+ }
52+ out .afterCmds = append (out .afterCmds , ac )
53+ }
3554 return out
3655}
3756
@@ -42,6 +61,13 @@ func (out *pmyOut) toShellVariables() string {
4261 res += fmt .Sprintf ("%v=$'%v';" , shellBufferLeftVariableName , utils .Escape (out .BufferLeft , "'" ))
4362 res += fmt .Sprintf ("%v=$'%v';" , shellBufferRightVariableName , utils .Escape (out .BufferRight , "'" ))
4463 res += fmt .Sprintf ("%v=$'%v';" , shellSourcesVariableName , utils .Escape (out .Sources , "'" ))
64+ for _ , ac := range out .afterCmds {
65+ res += fmt .Sprintf (
66+ "%v=$'%v';" ,
67+ fmt .Sprintf (shellAfterVariableName , ac .tag ),
68+ utils .Escape (ac .after , "'" ),
69+ )
70+ }
4571 return res
4672}
4773
0 commit comments