Skip to content
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

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

Open
bayramkzk opened this issue Sep 6, 2024 · 1 comment
Open

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

bayramkzk opened this issue Sep 6, 2024 · 1 comment

Comments

@bayramkzk
Copy link

bayramkzk commented Sep 6, 2024

sol/shellenv.go

Lines 287 to 291 in 7762c51

// Aliases
aliases, err := exec.Command("bash", "-ic", "compgen -a").Output()
if err != nil {
return nil, fmt.Errorf("could not get aliases: %w", err)
}

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
Copy link
Owner

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants