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 5 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
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
5 changes: 5 additions & 0 deletions pkg/config/user_config.go
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-command-for-copying-to-clipboard
Shell string `yaml:"shell,omitempty"`
ShellArg string `yaml:"shellArg,omitempty"`
}

type CustomCommandAfterHook struct {
Expand Down
6 changes: 5 additions & 1 deletion pkg/gui/gui.go
Expand Up @@ -535,7 +535,11 @@ func NewGui(
)

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

shell := gui.UserConfig.OS.Shell
if shell != "" {
osCommand.Platform.Shell = shell
osCommand.Platform.ShellArg = gui.UserConfig.OS.ShellArg
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be better to move this logic into NewOsCommand? We want all os commands to inherit that setting, right? Or do we only want the command runner for custom commands to use the shell and shellArgs from the userconfig?

Copy link
Author

Choose a reason for hiding this comment

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

Sounds good. I don't know how to access config.OS from there, though 😕

Copy link
Contributor

Choose a reason for hiding this comment

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

On second thought, I think it would make more sense to pass the OSConfig struct into oscommands.GetPlatform and get that function to extract the shell and shellArg values from there and use them there directly.

Sounds good. I don't know how to access config.OS from there, though 😕

You would be able to access the config through the Common struct that's passed into NewOsCommand function.

gui.os = osCommand

// storing this stuff on the gui for now to ease refactoring
Expand Down
28 changes: 28 additions & 0 deletions pkg/integration/tests/custom_commands/custom_shell.go
Copy link
Contributor

Choose a reason for hiding this comment

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

I am not sure, but perhaps an integration test is not the right thing for this feature? Maybe this should just be a unit test in pkg/commands/oscommands/os_test.go

@@ -0,0 +1,28 @@
package custom_commands

import (
"github.com/jesseduffield/lazygit/pkg/config"
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)

var CustomShell = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Confirms a popup appears on first opening Lazygit",
ExtraCmdArgs: []string{},
Skip: false,
SetupConfig: func(config *config.AppConfig) {
config.UserConfig.OS.Shell = "sh"
config.UserConfig.OS.ShellArg = "-c"
},
SetupRepo: func(shell *Shell) {},
Run: func(t *TestDriver, keys config.KeybindingConfig) {
t.Views().Files().
IsEmpty().
IsFocused().
Press(keys.Universal.ExecuteCustomCommand)

t.ExpectPopup().Prompt().
Title(Equals("Custom command:")).
Type("echo hello world").
Confirm()
},
})
1 change: 1 addition & 0 deletions pkg/integration/tests/test_list.go
Expand Up @@ -97,6 +97,7 @@ var tests = []*components.IntegrationTest{
custom_commands.BasicCmdFromConfig,
custom_commands.CheckForConflicts,
custom_commands.ComplexCmdAtRuntime,
custom_commands.CustomShell,
custom_commands.FormPrompts,
custom_commands.MenuFromCommand,
custom_commands.MenuFromCommandsOutput,
Expand Down
7 changes: 7 additions & 0 deletions schema/config.json
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-command-for-copying-to-clipboard"
Copy link
Contributor

Choose a reason for hiding this comment

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

The URL here needs to point to the "Custom Shell for executing arbitrary commands" section of the Config.md file.

},
"shellArg": {
"type": "string"
}
},
"additionalProperties": false,
Expand Down