noperator / sol

A de-minifier (formatter, exploder, beautifier) for shell one-liners
MIT License
468 stars 5 forks source link

`sol -a` fails if there are no bash aliases #1

Open bayramkzk opened 2 months ago

bayramkzk commented 2 months ago

https://github.com/noperator/sol/blob/7762c5115dd899bfac10d2f46d066de3c0e81774/shellenv.go#L287-L291

This call to bash fails if there are no bash aliases because compgen shell builtin returns non-zero error code if it can't find results.

From man bash:

       compgen [option] [word]
              Generate  possible  completion matches for word according to the options, which may be any option accepted by the complete builtin with the exception of -p and -r, and write the matches to the standard output.  When using the
              -F or -C options, the various shell variables set by the programmable completion facilities, while available, will not have useful values.

              The matches will be generated in the same way as if the programmable completion code had generated them directly from a completion specification with the same flags.  If word is specified, only those completions matching word
              will be displayed.

              The return value is true unless an invalid option is supplied, or no matches were generated. # <=== here

The same error is thrown on similar calls of compgen in the same file such as for functions. This prevents running sol -all on a clean bash setup without aliases and functions defined.

Possibly useful version information:

$ bash --version
GNU bash, version 5.2.32(1)-release (x86_64-pc-linux-gnu)
$ go version
go version go1.23.0 linux/amd64
noperator commented 2 months ago

Thanks for catching that. We can fail gracefully on those calls instead. Also need to update the shell-env logic to invoke whichever shell is currently running (vs. explicitly always running bash).