-
Notifications
You must be signed in to change notification settings - Fork 498
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
Feature request: shell attributes #2177
Comments
This can be done by checking the $SHELL variable, which should be set to the user's login shell: tips:
#!/usr/bin/env bash
case "$SHELL" in
*/zsh)
echo zsh
;;
*/bash)
echo bash
;;
*/sh)
echo sh
;;
esac Does that work? |
Thanks for the code snippet @casey, it looks like that would work. The shell functionality request makes the recipes more portable and cleaner, simplifying justfiles used in cross platform projects. On Windows, if the shell is set to PowerShell and there is no bash installed, then a PowerShell specific set of checks would have to be done. |
I think this is covered by using In practice, for portability, |
Sounds like a good approach. Your suggestion would keep the |
I like the following trick:
If there was a function called # this option does not work for non-posix shells
# just_shell := env("SHELL")
# this option only works if you have already configured starship for your shell
# just_shell := env("STARSHIP_SHELL")
# this option somehow fails to detect bash (SHELL seems to be unset and _ results in `just`)
# just_shell := file_stem(env("SHELL", env("_", env("STARSHIP_SHELL", "sh"))))
# this option may require specialised shell detection logic
# just_shell := invocation_shell()
# this option seems to be the most flexible
just_shell := invocation_process_name()
# Initialize Shell Setup
init-shell:
just _init-shell-{{just_shell}}
_init-shell-bash:
# Bash init
_init-shell-elvish:
# Elvish init
_init-shell-pwsh:
# Init powershell When a user runs The Ideally, an Making the first non-just parent process name available as a function, could be a more generic solution that does not specifically implement shell detection logic, in which case the function could be
@casey Would you be open to having a function like |
You can get the shell from the |
This feature request is similar to some of the comments around these issues:
[not(macos)]
#1895Imagine the following
justfile
:If you invoke
just tips
from within abash
shell, the output will beYou are using bash. Setup your shell like this:
.If you invoke
just tips
from within azsh
shell, the output will beYou are using zsh. Setup your shell like this:
.Put simply, like
just
can detect the os you are running in and prefer the os-specific recipes using the os attribute family (linux
,windows
, etc), it would be great ifjust
could detect the shell you are running in and prefer shell-specific recipes using a shell attribute family.To allow for the graceful expansion of this feature, the shell attribute could accept a parameter, e.g.
shell
. The value ofshell
can determine how the recipe is executed.shell=this
can mean that the recipe is executed using the same shell that it was invoked from (it could still be a new process of that shell),shell=default
can mean the recipe is executed using the default configured shell for executions (e.g.sh
or whatever the user set), andshell=zsh
can mean the recipe is executed using the provided shell (assuming that shell can be found in the path).Perhaps an alternative to the
shell
parameter, is to piggy-back on the existing support for recipe shebangs. If the recipe contains no shebang, then it is executed using the globally configured executor, e.g.sh
, but if it has a shebang, then the recipe is executed using that. We might introduce a special shebang#!self
that means the same shell as the invoker. In my mind, however, once this is a feature, the expectation of the users will be to have the recipe execute using the same shell runner as specified by the attribute, e.g.#!self
will probably always be used, in which case an attribute parameter might be preferred.In terms of attribute names, they can be the common names of the shells:
pwsh
means pwsh if it exists, otherwise powershell as a fallbackpowershell
means powershell if it exists, otherwise pwsh as a fallbackbash
means bashThe text was updated successfully, but these errors were encountered: