To implement
- Emit
if status is-interactive on case $- in *i*)
Description
This may be a specific use case, but is valuable in a lot of scenarios.
Consider the following script:
f() {
echo 'f function you also want to source'
}
case $- in
*i*) return
esac
main() {
f
}
main
In the case statement, we check if the shell is interactive. If it is, the script exits early. This allows the f() function to be imported into our environment without needing to manually add it to .profile. As a result, the script can be executed or sourced without extra redundancy.
Most of my scripts, if not all, take this form, as it allows them to gracefully handle being both sourced and executed without duplicating helper functions in the shell .profile.
Currently, babelfish will try to transliterate it as-is:
switch "$-"
case '*i*'
return
end
That previous code will fail, but iwe can achieve a similar result inn fish with:
if status is-interactive
return
end
We could emit that code whenever a simple case $- in *i*) is detected.
Any thoughts or feedback are welcome! 💙
To implement
if status is-interactiveoncase $- in *i*)Description
This may be a specific use case, but is valuable in a lot of scenarios.
Consider the following script:
In the
casestatement, we check if the shell is interactive. If it is, the script exits early. This allows thef()function to be imported into our environment without needing to manually add it to.profile. As a result, the script can be executed or sourced without extra redundancy.Most of my scripts, if not all, take this form, as it allows them to gracefully handle being both sourced and executed without duplicating helper functions in the shell
.profile.Currently,
babelfishwill try to transliterate it as-is:That previous code will fail, but iwe can achieve a similar result inn
fishwith:We could emit that code whenever a simple
case $- in *i*)is detected.Any thoughts or feedback are welcome! 💙