Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to specify other shell(Arg) #3299

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions docs/Config.md
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,13 @@ os:
os:
open: 'open {{filename}}'
```
## Custom Shell for executing arbitrary commands
```yaml
os:
shell: 'bash'
shellArg: '-c'
```
Specify a shell and optional argument to prepend to custom commands called from within Lazygit.

## Custom Command for Copying to Clipboard
```yaml
Expand Down
2 changes: 1 addition & 1 deletion pkg/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func NewApp(config config.AppConfigurer, test integrationTypes.IntegrationTest,
Common: common,
}

app.OSCommand = oscommands.NewOSCommand(common, config, oscommands.GetPlatform(), oscommands.NewNullGuiIO(app.Log))
app.OSCommand = oscommands.NewOSCommand(common, config, oscommands.GetPlatform(common.UserConfig.OS), oscommands.NewNullGuiIO(app.Log))

updater, err := updates.NewUpdater(common, config, app.OSCommand)
if err != nil {
Expand Down
11 changes: 9 additions & 2 deletions pkg/commands/oscommands/os_default_platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,21 @@ package oscommands

import (
"runtime"

"github.com/jesseduffield/lazygit/pkg/config"
)

func GetPlatform() *Platform {
return &Platform{
func GetPlatform(osConfig config.OSConfig) *Platform {
platform := Platform{
OS: runtime.GOOS,
Shell: "bash",
ShellArg: "-c",
OpenCommand: "open {{filename}}",
OpenLinkCommand: "open {{link}}",
}
if osConfig.Shell != "" {
platform.Shell = osConfig.Shell
platform.ShellArg = osConfig.ShellArg
}
Comment on lines +20 to +23
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think at this point, we should probably just consider setting bash and -c as default parameters for Shell and ShellArg in the user_config file. That way, we can just directly take the values from osConfig and use them in the Platform literal.

return &platform
}
5 changes: 5 additions & 0 deletions pkg/config/user_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,11 @@ type OSConfig struct {
// CopyToClipboardCmd is the command for copying to clipboard.
// See https://github.com/jesseduffield/lazygit/blob/master/docs/Config.md#custom-command-for-copying-to-clipboard
CopyToClipboardCmd string `yaml:"copyToClipboardCmd,omitempty"`

// Shell and ShellArg are the shell and corresponding argument to be used for executing custom commands.
// See https://github.com/jesseduffield/lazygit/blob/master/docs/Config.md#custom-shell-for-executing-arbitrary-commands
Shell string `yaml:"shell,omitempty"`
ShellArg string `yaml:"shellArg,omitempty"`
}

type CustomCommandAfterHook struct {
Expand Down
3 changes: 1 addition & 2 deletions pkg/gui/gui.go
Original file line number Diff line number Diff line change
Expand Up @@ -534,8 +534,7 @@ func NewGui(
credentialsHelper.PromptUserForCredential,
)

osCommand := oscommands.NewOSCommand(cmn, config, oscommands.GetPlatform(), guiIO)

osCommand := oscommands.NewOSCommand(cmn, config, oscommands.GetPlatform(gui.UserConfig.OS), guiIO)
gui.os = osCommand

// storing this stuff on the gui for now to ease refactoring
Expand Down
9 changes: 8 additions & 1 deletion schema/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -1292,6 +1292,13 @@
"copyToClipboardCmd": {
"type": "string",
"description": "CopyToClipboardCmd is the command for copying to clipboard.\nSee https://github.com/jesseduffield/lazygit/blob/master/docs/Config.md#custom-command-for-copying-to-clipboard"
},
"shell": {
"type": "string",
"description": "Shell and ShellArg are the shell and corresponding argument to be used for executing custom commands.\nSee https://github.com/jesseduffield/lazygit/blob/master/docs/Config.md#custom-shell-for-executing-arbitrary-commands"
},
"shellArg": {
"type": "string"
}
},
"additionalProperties": false,
Expand Down Expand Up @@ -1516,4 +1523,4 @@
},
"additionalProperties": false,
"type": "object"
}
}