-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Detect the user's shell for running custom commands #2096
Detect the user's shell for running custom commands #2096
Conversation
This makes it possible to use any shell, and by adding the `-i` flag it makes it interactive (running aliases and functions is possible now)
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 thing
Shell: "bash", | ||
ShellArg: "-c", | ||
Shell: getShell(), | ||
ShellArg: "-ic", |
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.
what does the i flag do and how many shells support it?
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.
It makes the shell interactive
which in turn reads startup files (among other things), which allows you to use aliases, functions and variables defined in your e.g. .zshrc
.
I tried it with bash
, zsh
and fish
and all of them support the i
flag.
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.
Wow very cool. I wonder if this will slow things down for users that have extensive e.g. zshrc files.
"runtime" | ||
) | ||
|
||
func getShell() string { | ||
defaultShell := "bash" | ||
if shell := os.Getenv("SHELL"); shell != defaultShell { |
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.
This logic isn't quite right:
If shell != default shell, we return shell
if shell == default shell, we return default shell which is really just shell
So we're returning shell either way.
I would instead say that if SHELL is blank string, we default to bash
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.
We presume the shell is bash
.
If we read the environment variable SHELL
(which actually returns the absolute path, my bad) and it turns out to be zsh
(!= bash
), we return zsh
which... yeah, okay
So we're returning shell either way.
Well, when you put it that way... 😅
cc @Ryooooooga for additional input, on #1642 they said:
|
An interesting side-effect of applying these changes that I've seen was that upon returning from committing, the lazygit app gets suspended. Here's the example output I see after committing something from within lazygit:
When I bring the app back to the foreground with I don't know if the underlying issue is with the go terminal UI library (gocui?) and Warp, as a root cause is not currently known. I'm simply posting these details to relate the filed issue for Warp with this PR in case someone figures out what's wrong with how Warp handling the lazygit response. Being that Warp does not quite play by the same rules as other terminals and shells. |
- **PR Description** When executing an interactive custom command, use the user's shell rather than "bash", and pass the -i flag. This makes it possible to use shell aliases or shell functions which are not available in non-interactive shells. In previous attempts to solve this, concerns were brought up: [this one](#2096 (comment)) is addressed by using the interactive shell only for custom commands but not anything else. [This one](#2096 (comment)) is a little dubious and unconfirmed, so I'm not very worried about it. Supersedes #2096 and #3299. Fixes #770, #899, and #1642.
This makes it possible to use any shell, and by adding the
-i
flag itmakes it interactive (running aliases and functions is possible now)
Should close #770 .
Tests are still
TODO