nix-bash-completions
nix-bash-completions copied to clipboard
Error if extended globbing is not enabled in shell
I source _nix in my bashrc. I was getting this error when starting a new shell (on MacOS only):
bash: /Users/s/.nix-profile/share/bash-completion/completions/_nix: line 496: syntax error near unexpected token `('
bash: /Users/s/.nix-profile/share/bash-completion/completions/_nix: line 496: ` --install|-*([a-zA-Z])i*([a-zA-Z]))'
The code around line 496 is:
case "$word" in
--install|-*([a-zA-Z])i*([a-zA-Z])) # <-- this is line 496
command_options=(
${nix_env_common_opts[*]}
${nix_env_b[*]} $nix_env_from_profile
'(--preserve-installed|-P)'{--preserve-installed,-P}
'(--remove-all|-r)'{--remove-all,-r}
'(-A|--attr)'{-A,--attr}
':*->installed_packages')
break
;;
This pattern (and others in the file) use Bash Extended Globbing which was not in my shell, hence the error. The error was happening with bash installed with homerew and with nix. Interestingly on my linux machine I don't see the same error but possibly something else in my config there is enabling extended globbing.
The fix was to add this line to my bashrc before sourcing _nix:
shopt -s extglob
Not sure if it makes sense to just add that line to _nix itself. If not I think this error message and solution should be added to the readme.