Skip to content

Commit e9709ec

Browse files
jorgemxmian-s
authored andcommitted
Revert "Allow using shell aliases in interactive custom commands (jesseduffield#3793)"
Issues: 3903, 3923 This reverts commit c72be6c, reversing changes made to da94ee7.
1 parent c3cf48c commit e9709ec

File tree

7 files changed

+26
-58
lines changed

7 files changed

+26
-58
lines changed

pkg/commands/git_cmd_obj_builder.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,6 @@ func (self *gitCmdObjBuilder) NewShell(cmdStr string) oscommands.ICmdObj {
3838
return self.innerBuilder.NewShell(cmdStr).AddEnvVars(defaultEnvVar)
3939
}
4040

41-
func (self *gitCmdObjBuilder) NewInteractiveShell(cmdStr string) oscommands.ICmdObj {
42-
return self.innerBuilder.NewInteractiveShell(cmdStr).AddEnvVars(defaultEnvVar)
43-
}
44-
4541
func (self *gitCmdObjBuilder) Quote(str string) string {
4642
return self.innerBuilder.Quote(str)
4743
}

pkg/commands/oscommands/cmd_obj_builder.go

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ type ICmdObjBuilder interface {
1414
New(args []string) ICmdObj
1515
// NewShell takes a string like `git commit` and returns an executable shell command for it e.g. `sh -c 'git commit'`
1616
NewShell(commandStr string) ICmdObj
17-
// Like NewShell, but uses the user's shell rather than "bash", and passes -i to it
18-
NewInteractiveShell(commandStr string) ICmdObj
1917
// Quote wraps a string in quotes with any necessary escaping applied. The reason for bundling this up with the other methods in this interface is that we basically always need to make use of this when creating new command objects.
2018
Quote(str string) string
2119
}
@@ -45,33 +43,24 @@ func (self *CmdObjBuilder) NewWithEnviron(args []string, env []string) ICmdObj {
4543
}
4644

4745
func (self *CmdObjBuilder) NewShell(commandStr string) ICmdObj {
48-
quotedCommand := self.quotedCommandString(commandStr)
49-
cmdArgs := str.ToArgv(fmt.Sprintf("%s %s %s", self.platform.Shell, self.platform.ShellArg, quotedCommand))
50-
51-
return self.New(cmdArgs)
52-
}
53-
54-
func (self *CmdObjBuilder) NewInteractiveShell(commandStr string) ICmdObj {
55-
quotedCommand := self.quotedCommandString(commandStr)
56-
cmdArgs := str.ToArgv(fmt.Sprintf("%s %s %s %s", self.platform.InteractiveShell, self.platform.InteractiveShellArg, self.platform.ShellArg, quotedCommand))
57-
58-
return self.New(cmdArgs)
59-
}
60-
61-
func (self *CmdObjBuilder) quotedCommandString(commandStr string) string {
46+
var quotedCommand string
6247
// Windows does not seem to like quotes around the command
6348
if self.platform.OS == "windows" {
64-
return strings.NewReplacer(
49+
quotedCommand = strings.NewReplacer(
6550
"^", "^^",
6651
"&", "^&",
6752
"|", "^|",
6853
"<", "^<",
6954
">", "^>",
7055
"%", "^%",
7156
).Replace(commandStr)
57+
} else {
58+
quotedCommand = self.Quote(commandStr)
7259
}
7360

74-
return self.Quote(commandStr)
61+
cmdArgs := str.ToArgv(fmt.Sprintf("%s %s %s", self.platform.Shell, self.platform.ShellArg, quotedCommand))
62+
63+
return self.New(cmdArgs)
7564
}
7665

7766
func (self *CmdObjBuilder) CloneWithNewRunner(decorate func(ICmdObjRunner) ICmdObjRunner) *CmdObjBuilder {

pkg/commands/oscommands/dummies.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,11 @@ func NewDummyCmdObjBuilder(runner ICmdObjRunner) *CmdObjBuilder {
5151
}
5252

5353
var dummyPlatform = &Platform{
54-
OS: "darwin",
55-
Shell: "bash",
56-
InteractiveShell: "bash",
57-
ShellArg: "-c",
58-
InteractiveShellArg: "-i",
59-
OpenCommand: "open {{filename}}",
60-
OpenLinkCommand: "open {{link}}",
54+
OS: "darwin",
55+
Shell: "bash",
56+
ShellArg: "-c",
57+
OpenCommand: "open {{filename}}",
58+
OpenLinkCommand: "open {{link}}",
6159
}
6260

6361
func NewDummyOSCommandWithRunner(runner *FakeCmdObjRunner) *OSCommand {

pkg/commands/oscommands/os.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,11 @@ type OSCommand struct {
3535

3636
// Platform stores the os state
3737
type Platform struct {
38-
OS string
39-
Shell string
40-
InteractiveShell string
41-
ShellArg string
42-
InteractiveShellArg string
43-
OpenCommand string
44-
OpenLinkCommand string
38+
OS string
39+
Shell string
40+
ShellArg string
41+
OpenCommand string
42+
OpenLinkCommand string
4543
}
4644

4745
// NewOSCommand os command runner

pkg/commands/oscommands/os_default_platform.go

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,15 @@
44
package oscommands
55

66
import (
7-
"os"
87
"runtime"
98
)
109

1110
func GetPlatform() *Platform {
1211
return &Platform{
13-
OS: runtime.GOOS,
14-
Shell: "bash",
15-
InteractiveShell: getUserShell(),
16-
ShellArg: "-c",
17-
InteractiveShellArg: "-i",
18-
OpenCommand: "open {{filename}}",
19-
OpenLinkCommand: "open {{link}}",
12+
OS: runtime.GOOS,
13+
Shell: "bash",
14+
ShellArg: "-c",
15+
OpenCommand: "open {{filename}}",
16+
OpenLinkCommand: "open {{link}}",
2017
}
2118
}
22-
23-
func getUserShell() string {
24-
if shell := os.Getenv("SHELL"); shell != "" {
25-
return shell
26-
}
27-
28-
return "bash"
29-
}

pkg/commands/oscommands/os_windows.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@ package oscommands
22

33
func GetPlatform() *Platform {
44
return &Platform{
5-
OS: "windows",
6-
Shell: "cmd",
7-
InteractiveShell: "cmd",
8-
ShellArg: "/c",
9-
InteractiveShellArg: "",
5+
OS: "windows",
6+
Shell: "cmd",
7+
ShellArg: "/c",
108
}
119
}

pkg/gui/controllers/shell_command_action.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func (self *ShellCommandAction) Call() error {
3131

3232
self.c.LogAction(self.c.Tr.Actions.CustomCommand)
3333
return self.c.RunSubprocessAndRefresh(
34-
self.c.OS().Cmd.NewInteractiveShell(command),
34+
self.c.OS().Cmd.NewShell(command),
3535
)
3636
},
3737
HandleDeleteSuggestion: func(index int) error {

0 commit comments

Comments
 (0)