Repository navigation
Conversation
fish sources a completion file in the scope of whatever triggers the first completion. With the default binding that is the interactive session, so an unscoped 'set' ends up global by accident. Bind <TAB> to a function that calls 'commandline --function complete' -- as fish-autopair's _autopair_tab does -- and the file is sourced inside that function, making $bat local to it. The completion helpers run later in a different scope, so $bat expands empty and 'bat -l' <TAB> fails with 'The expanded command was empty'. 'set -g' makes the scope explicit. Command substitution in fish is a fork and inherits non-exported globals, so the helpers now resolve $bat without exporting it into the environment of every child process. Verified on fish 4.9.3 for both the bat and batcat renderings: the --language candidates go from 0 to 8 when the file is sourced inside a function, stay at 8 when sourced at top level, and --theme is unaffected either way.
…-completion-subshell-3909
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fish sources a completion file in the scope of whatever triggers the first completion. With the default binding that is the interactive session itself, so an unscoped
setinbat.fish.inhappens to end up global and everything works. Bind<TAB>to a function that callscommandline --function complete— which is what fish-autopair's_autopair_tabdoes — and the file is sourced inside that function instead, soset bat batbecomes a local of_autopair_taband disappears the moment it returns. The helper functions are called later, from a different scope, and see an empty$bat:With that,
bat -lfollowed by<TAB>produces no language list at all. Reproduced on fish 4.9.3 by sourcing the rendered file inside a function and then invoking the helper from outside it: zero candidates, with exactly the error above.set -gmakes the scope explicit instead of leaving it to chance. The reason this is not an export problem is worth spelling out, because it looks like one: command substitution in fish is a fork, and a fork inherits non-exported globals. Soset -gxalso silences the error, but it does it by puttingbat=batinto the environment of every process the shell starts, where nothing needs it and a program that happens to read$batwould pick up a variable it was never meant to see. Measured, the export leaks while the global does not:Checking the fix against both renderings, since the executable name is substituted at build time and Debian/Ubuntu gets
batcat:--themeis unaffected either way — its list is built by a command substitution in thecomplete -aargument rather than by a helper function, so it is still evaluated where it can see the variable. Top-level behaviour is unchanged at 8, so this is a fix to the broken path rather than a change to the working one. The other three helpers in the file return cleanly from a foreign scope after the change, andfish --no-executeparses the rendered file for bothbatandbatcat.There are two earlier attempts at this that appear to have gone quiet — #3910 and #4006 — so if either is still worth reviving, happy to close this in favour of that instead.
Closes #3909