diff --git a/docs/Config.md b/docs/Config.md index 04bfbbc40ba..c4839f6ee5c 100644 --- a/docs/Config.md +++ b/docs/Config.md @@ -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 diff --git a/pkg/app/app.go b/pkg/app/app.go index a16fbcc1fe7..671322d5da8 100644 --- a/pkg/app/app.go +++ b/pkg/app/app.go @@ -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 { diff --git a/pkg/commands/oscommands/os_default_platform.go b/pkg/commands/oscommands/os_default_platform.go index fd4967d9576..9d2c9371680 100644 --- a/pkg/commands/oscommands/os_default_platform.go +++ b/pkg/commands/oscommands/os_default_platform.go @@ -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 + } + return &platform } diff --git a/pkg/config/user_config.go b/pkg/config/user_config.go index 916b6dc90ea..acd6c47f62c 100644 --- a/pkg/config/user_config.go +++ b/pkg/config/user_config.go @@ -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 { diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go index 66ef453dacc..77c368ff96a 100644 --- a/pkg/gui/gui.go +++ b/pkg/gui/gui.go @@ -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 diff --git a/schema/config.json b/schema/config.json index 0a78da23aaa..615a5f86aaf 100644 --- a/schema/config.json +++ b/schema/config.json @@ -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, @@ -1516,4 +1523,4 @@ }, "additionalProperties": false, "type": "object" -} \ No newline at end of file +}