-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Wrap custom commands on shell #387
Wrap custom commands on shell #387
Conversation
Here's the result using the issue's example: (base) ➜ lazydocker git:(master) ✗ go run -mod=vendor main.go
docker-compose config --quiet
+ bash -c docker run -it -v "$(pwd)":/data redis
1:C 15 Oct 2022 19:27:44.265 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
1:C 15 Oct 2022 19:27:44.265 # Redis version=7.0.5, bits=64, commit=00000000, modified=0, pid=1, just started
1:C 15 Oct 2022 19:27:44.265 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
1:M 15 Oct 2022 19:27:44.265 * monotonic clock: POSIX clock_gettime
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 7.0.5 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 1
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | https://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'
1:M 15 Oct 2022 19:27:44.266 # Server initialized
1:M 15 Oct 2022 19:27:44.269 * Ready to accept connections
^C1:signal-handler (1665862067) Received SIGINT scheduling shutdown...
1:M 15 Oct 2022 19:27:47.999 # User requested shutdown...
1:M 15 Oct 2022 19:27:47.999 * Saving the final RDB snapshot before exiting.
1:M 15 Oct 2022 19:27:48.022 * DB saved on disk
1:M 15 Oct 2022 19:27:48.023 # Redis is now ready to exit, bye bye...
Press enter to return to lazydocker (this prompt can be disabled in your config by setting `gui.returnImmediately: true`) |
@jesseduffield This is ready, let me know your thoughts! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good, one comment.
Also we should remove RunDirectCommand
given that's not being used and seemed to do something similar
Also one thing we'll want to test @gusandrioli is whether an existing custom command which already used bash -c explicitly now breaks with this new code |
Good point, i'll test that out. |
@jesseduffield It does fail! Thanks for catching that: + bash -c bash -c docker run -it -v "$(pwd)":/data redis
Usage: docker [OPTIONS] COMMAND
A self-sufficient runtime for containers One alternative is to leave the command as is if it contains |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jesseduffield Updated the config to have a invokeShell
bool (default: false
). Tested on both cases and worked fine.
Also, for these type of PRs with a lot of commits, do you prefer if i squash them or leave as is?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
couple things
pkg/gui/custom_commands.go
Outdated
@@ -50,10 +52,13 @@ func (gui *Gui) createCommandMenu(customCommands []config.CustomCommand, command | |||
return option.customCommand.InternalFunction() | |||
} | |||
|
|||
if option.invokeShell { | |||
option.command = gui.OSCommand.NewCommandStringWithShell(option.command) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rather than mutate option.command here I would have a separate resolvedCommand
variable that we use. This means that if we want to reuse options
from outside this callback down the line there's no chance of the callback's code interfering
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. Okay, makes sense.
3e8b584
to
e44d50d
Compare
@jesseduffield Fixed :) Thanks for the feedback. |
Nice work :) I'll give this a local test soon |
Hey @jesseduffield! Hope you're doing well. Are we still going to use this PR? If so, i can solve the conflicts. |
@gusandrioli sorry this fell through the cracks. I'll take another look this afternoon |
@jesseduffield No worries at all, let me know :) |
e44d50d
to
d77b895
Compare
Code looks good, I've just fixed some merge conflicts |
can you confirm this still works on your end after I resolved those merge conflicts @gusandrioli ? |
Hey @jesseduffield, just tested and it's working. Thanks for solving the conflicts! Testing ResultsUsing the following config customCommands:
images:
- name: tryout
attach: true
shell: false
command: bash -c "docker run -it -v "$(pwd)":/data redis"
serviceNames: []
- name: tryout2
attach: true
shell: true
command: docker run -v "$(pwd)":/data redis
serviceNames: [] |
Merged. Thanks @gusandrioli ! |
This broke the custom commands like these:
Results with the error:
Setting |
This changeset broke For now I've downgrade to wget https://raw.githubusercontent.com/jesseduffield/homebrew-lazydocker/b6d29bcd59058d1b7ec371df12f75d7048b40789/lazydocker.rb
brew uninstall lazydocker
brew install -s lazydocker.rb
rm ./lazydocker.rb |
Context
This solves #354
Implementation
Ideally, we'd re-use
ICmdObjBuilder
fromlazygit
across both projects, but that'd require a complete refactor here. So i ported the string replacement for Windows OS and the wrapping of new shell.