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

Fix unbound variables in shell completion #2999

Merged
merged 16 commits into from
Oct 16, 2022

Conversation

cevhyruz
Copy link
Contributor

when set -o nounset is enabled
completion complains about these variables being unset:

orig_var
__fzf_no_space_commands

@junegunn
Copy link
Owner

junegunn commented Oct 12, 2022

Thanks, but are you setting set -o nounset in an interactive session? Wouldn't it cause a lot of problems with existing scripts? Also, if we apply this patch, bash will successfully load completion.bash file, but the completion still won't work.

$ set -o nounset
$ . shell/completion.bash
$ ssh **-bash: FZF_DEFAULT_OPTS: unbound variable
$ ls **-bash: dir: unbound variable

@cevhyruz
Copy link
Contributor Author

cevhyruz commented Oct 12, 2022

are you setting set -o nounset in an interactive session?

Yeah, I like it when I'm able to see if a variable is not created yet, rather than printing nothing when echoing.

Wouldn't it cause a lot of problems with existing scripts?

what do you mean by existing scripts?

@junegunn
Copy link
Owner

what do you mean by existing scripts?

Many scripts in the wild are written with the assumption that set -u is not set in an interactive session, so setting it is going to break them. You're lucky if you haven't run into such a script.

This feature is rather controversial, and has many extremely vocal advocates and opponents
(https://mywiki.wooledge.org/BashFAQ/112)

Making sure that a legacy script works with set -u can be a lot of work and it seems that the maintainers of the scripts are not so sure if it's worth it given that most users historically don't have set -u on interactive sessions.

But anyway, as I said above, the patch alone won't make fuzzy completion work (i.e. ls **<tab>)? Have you tested that?

@cevhyruz
Copy link
Contributor Author

cevhyruz commented Oct 13, 2022

Making sure that a legacy script works with set -u can be a lot of work and it seems that the maintainers of the scripts are not so sure if it's worth it given that most users historically don't have set -u on interactive sessions

I see the point. Well, It wont hurt to support both cases is it?

The only thing to lookout out for sure is maintaining the way it is which can be solve by adding a little test script.

But anyway, as I said above, the patch alone won't make fuzzy completion work (i.e. ls **)? Have you tested that?

Got it working on my end now there seems a couple of little refactoring needed. Will push later after testing.

Just wanna know what are your thoughts about this?

@junegunn
Copy link
Owner

Just wanna know what are your thoughts about this?

Not just the fuzzy completion, none of the key bindings (CTRL-T, ALT-C, and CTRL-R) works with set -u and you're the first one to report this compatibility issue says a lot about common users' configuration. Also, zsh implementation has the same problem, but no complaints so far.

Well, It wont hurt to support both cases is it?

The code will have things like ${XXX-} all over the place, they'll likely make the code less readable, and harder to maintain as we always need to put extra care whenever we change the code.

But after all, if we can make things (key bindings and fuzzy completion of bash and zsh) work with set -u with not too many intrusive changes, I'm okay with the direction.

@cevhyruz cevhyruz changed the title Fix unbound variables in completion.bash Fix unbound variables in shell completion Oct 14, 2022
@cevhyruz cevhyruz marked this pull request as draft October 14, 2022 06:35
@cevhyruz cevhyruz marked this pull request as ready for review October 14, 2022 07:34
shell/completion.bash Outdated Show resolved Hide resolved
shell/completion.bash Outdated Show resolved Hide resolved
shell/completion.bash Outdated Show resolved Hide resolved
shell/key-bindings.zsh Outdated Show resolved Hide resolved
shell/key-bindings.bash Outdated Show resolved Hide resolved
shell/key-bindings.bash Outdated Show resolved Hide resolved
shell/completion.bash Outdated Show resolved Hide resolved
shell/completion.bash Outdated Show resolved Hide resolved
shell/completion.bash Outdated Show resolved Hide resolved
@junegunn
Copy link
Owner

Please allow me to push more commits to your branch.

(https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/allowing-changes-to-a-pull-request-branch-created-from-a-fork)

@cevhyruz
Copy link
Contributor Author

looks good to me, what do you think?

@junegunn
Copy link
Owner

Looks good to me too. Thanks for the work.

@junegunn junegunn merged commit 4603d54 into junegunn:master Oct 16, 2022
@cevhyruz cevhyruz deleted the patch branch October 16, 2022 08:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants