Skip to content

Commit 83988ab

Browse files
relastleHiroki-Konishi
authored andcommitted
Merge branch 'feature/onlineCommandExecution' into develop
2 parents 9ec8835 + 4f86ce0 commit 83988ab

File tree

4 files changed

+42
-16
lines changed

4 files changed

+42
-16
lines changed

resources/pmy_rules_neo.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
"regexpLeft": "^cd +(?P<path>.*)$",
5757
"cmdGroups": [
5858
{
59-
"tag": "directory",
59+
"tag": "",
6060
"stmt": "command ls ${PMY_LS_OPTION} -1 <path> | egrep '/$'",
6161
"after": "awk '{print $0}'"
6262
}

shell/pmy.zsh

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,26 @@ pmy-widget() {
1717
else
1818
eval ${out}
1919

20-
# get result from fzf
21-
local fzf_res=$(echo "${__pmy_out_sources}" | fzf -0 -1)
22-
# get tag
23-
local tag="$(echo -n ${fzf_res} | awk 'BEGIN{ORS = ""}{print $1}' | base64)"
24-
tag=${tag/\//a_a} # original escape of base64 `/`
25-
tag=${tag/+/b_b} # original escape of base64 `+`
26-
tag=${tag/=/c_c} # original escape of base64 `+`
27-
# get rest statement
28-
local fzf_res_rest=$(echo ${fzf_res} | awk '{for(i=2;i<NF;i++){printf("%s%s",$i,OFS=" ")}print $NF}')
29-
# get after command
30-
local after_cmd_variable="__pmy_out_${tag}_after"
31-
local after_cmd=$(eval echo \$$after_cmd_variable)
32-
local res=$(echo ${fzf_res_rest} | eval ${after_cmd})
20+
if [[ -z ${__pmy_out_imm_cmd} ]] then
21+
# get result from fzf
22+
local fzf_res=$(echo -n "${__pmy_out_sources}" | fzf -0 -1)
23+
# get tag
24+
local tag="$(echo -n ${fzf_res} | awk 'BEGIN{ORS = ""}{print $1}' | base64)"
25+
tag=${tag//\//a_a} # original escape of base64 `/`
26+
tag=${tag//+/b_b} # original escape of base64 `+`
27+
tag=${tag//=/c_c} # original escape of base64 `+`
28+
# get rest statement
29+
local fzf_res_rest=$(echo ${fzf_res} | awk '{for(i=2;i<NF;i++){printf("%s%s",$i,OFS=" ")}print $NF}')
30+
# get after command
31+
local after_cmd_variable="__pmy_out_${tag}_after"
32+
local after_cmd=$(eval echo \$$after_cmd_variable)
33+
local res=$(echo ${fzf_res_rest} | eval ${after_cmd})
34+
else
35+
# get result from fzf
36+
local fzf_res=$(eval "${__pmy_out_imm_cmd}" | fzf -0 -1)
37+
local after_cmd=${__pmy_out_imm_after_cmd}
38+
local res=$(echo ${fzf_res} | eval ${after_cmd})
39+
fi
3340
LBUFFER="${__pmy_out_buffer_left}${res}"
3441
RBUFFER="${__pmy_out_buffer_right}"
3542
fi

src/cmd.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func (cg *CmdGroup) toPipeLine() []([]string) {
4747
}
4848

4949
func (cg *CmdGroup) setLines(out []byte) {
50-
strList := strings.Split(strings.TrimSuffix(string(out), "\n"), "\n")
50+
strList := strings.Split(strings.Trim(string(out), "\n"), "\n")
5151
cg.Lines = strList
5252
return
5353
}
@@ -82,6 +82,13 @@ func (cgs CmdGroups) getMaxTagLen() int {
8282
return maxLen
8383
}
8484

85+
func (cgs CmdGroups) getImmCmdGroup() (*CmdGroup, bool) {
86+
if len(cgs) == 1 && cgs[0].Tag == "" {
87+
return cgs[0], true
88+
}
89+
return nil, false
90+
}
91+
8592
func (cgs CmdGroups) organizeLines() string {
8693
resString := ""
8794
maxTagLen := cgs.getMaxTagLen()

src/out.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ const (
1515
shellCommandVariableName = "__pmy_out_command"
1616
shellSourcesVariableName = "__pmy_out_sources"
1717
shellAfterVariableName = "__pmy_out_%s_after"
18+
shellImmCmdVariableName = "__pmy_out_imm_cmd"
19+
shellImmAfterCmdVariableName = "__pmy_out_imm_after_cmd"
1820
)
1921

2022
type afterCmd struct {
@@ -30,6 +32,8 @@ type pmyOut struct {
3032
bufferRight string
3133
cmdGroups CmdGroups
3234
sources string
35+
immCmd string
36+
immAfterCmd string
3337
}
3438

3539
// newPmyOutFromRule create new pmyOut from rule
@@ -44,7 +48,13 @@ func newPmyOutFromRule(rule *pmyRule) pmyOut {
4448
// expand all parameters
4549
out.expandAll(rule.paramMap)
4650
// get sources
47-
out.sources, _ = out.cmdGroups.GetSources()
51+
if immCmdGroup, ok := out.cmdGroups.getImmCmdGroup(); ok {
52+
out.immCmd = immCmdGroup.Stmt
53+
out.immAfterCmd = immCmdGroup.After
54+
} else {
55+
out.sources, _ = out.cmdGroups.GetSources()
56+
}
57+
// get sources
4858
return out
4959
}
5060

@@ -65,6 +75,8 @@ func (out *pmyOut) toShellVariables() string {
6575
res += fmt.Sprintf("%v=$'%v';", shellBufferLeftVariableName, utils.Escape(out.bufferLeft, "'"))
6676
res += fmt.Sprintf("%v=$'%v';", shellBufferRightVariableName, utils.Escape(out.bufferRight, "'"))
6777
res += fmt.Sprintf("%v=$'%v';", shellSourcesVariableName, utils.Escape(out.sources, "'"))
78+
res += fmt.Sprintf("%v=$'%v';", shellImmCmdVariableName, utils.Escape(out.immCmd, "'"))
79+
res += fmt.Sprintf("%v=$'%v';", shellImmAfterCmdVariableName, utils.Escape(out.immAfterCmd, "'"))
6880
for _, cg := range out.cmdGroups {
6981
res += fmt.Sprintf(
7082
"%v=$'%v';",

0 commit comments

Comments
 (0)