withfig / fig

Public issue tracker for Fig.
https://fig.io
MIT License
2.06k stars 63 forks source link

Suggestion: use posix shell syntax for scripts. Check them with ShellCheck #616

Open orent opened 2 years ago

orent commented 2 years ago

Sanity checks

Issue Details

Programming in portable posix shell is easy. The major bash-ism I see in your code is '[[' which can be easily replaced with 'test'/'['. There is really no need to consider sh/bash/zsh as separate languages -just one language with some extensions that can be checked with 'if'. Fish really is different, though.

ShellCheck is your friend and will help you avoid both portability issues and common bugs.

Whether or not you choose to do this, make sure to regularly run ShellCheck on all scripts. Preferably add it to the automatic workflow.

Environment

n/a
mschrage commented 2 years ago

Hey @orent! This is a good suggestion, I looked into this a while ago and what's tricky is that we do use some zsh specific syntax/functionality in ~/.fig/shell/zle.zsh, but you're totally right that besides that there is a lot of overlap.

I think our long term solution will be to move as much logic as possible into the CLI since most of what we do is getting & setting environment variables.

This would let us write any complicated logic in a more conventional programming language and it could be shared across all shells with minimal modifications.

For example:

if [ fig shell-integration --not-installed ]; then
    eval "$(fig shell-integration install --shell bash)" 
fi

Curious what you think of this approach?