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

mutt: do not lose the + in mutt -f +foo<tab> #465

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

mgedmin
Copy link
Contributor

@mgedmin mgedmin commented Nov 11, 2020

Closes #464.

mgedmin added a commit to mgedmin/dotfiles that referenced this pull request Nov 11, 2020
This one's submitted upstream as
scop/bash-completion#465
@mgedmin
Copy link
Contributor Author

mgedmin commented Nov 11, 2020

I am baffled: I have a machine with Ubuntu 18.04 LTS (bash 4.4.20(1)-release, bash-completion 1:2.8-1ubuntu1) where mutt -f =<tab> eats the = and where a similar fix would be needed. On my other machine with Ubuntu 20.10 (bash 5.0.17(1)-release, bash-completion 1:2.11-2ubuntu1) mutt -f =<tab> works fine and only mutt -f +<tab> needs to restore the +.

@mgedmin
Copy link
Contributor Author

mgedmin commented Nov 11, 2020

I've found a solution that works on both Ubuntu 18.04 and 20.10, but I don't entirely understand the situation: mgedmin/dotfiles@4758e78

Update: I've incorporated that solution into this PR. The more I think about it, the more it seems right: it should adjust to changes in $COMP_WORDBREAKS automatically. (Although COMP_WORDBREAKS is not the reason completion behaves differently on Ubuntu 18.04 and 20.10. I wonder if there was a bash bug that got fixed)

I haven't fully understood how exactly this happens, but sometimes
(Ubuntu 18.04) '=foo' ends up as a single word in COMP_WORDS, despite
COMP_WORDBREAKS containing '='.  At other times '=foo' is split into two
words, '=' and 'foo'.

If COMP_WORDS[$COMP_CWORD] had the '+' or '=' prefix, we need to make
sure COMPREPLY also includes it, or we'll lose it.

Closes scop#464, in a better way.
@mgedmin
Copy link
Contributor Author

mgedmin commented Nov 12, 2020

Welp this doesn't actually work on Ubuntu 20.10. I thought I'd tested it! Back to the drawing board...

It was broken by my previous fixes and would expand to mutt -f =\=.

I've tested the new code on Ubuntu 18.04 as well as 20.10.  I've tested
these cases:

  mutt -f =<tab>
  mutt -f +<tab>
  mutt -f =mailb<tab>
  mutt -f +mailb<tab>

They all work now.
@mgedmin
Copy link
Contributor Author

mgedmin commented Nov 12, 2020

Welp this doesn't actually work on Ubuntu 20.10. I thought I'd tested it!

I did test it, and mutt -f =fold<tab> is correctly expanded to mutt -f =folder.

What breaks is mutt -f =<tab> instead of showing all possible mailboxes it expands to mutt -f =\=.

Fixed now.

@mgedmin
Copy link
Contributor Author

mgedmin commented Nov 12, 2020

I now have tests for this in #467. Without this fix they fail as follows:

____________________________________ TestMutt.test_plus_is_not_eaten ____________________________________

self = <test_mutt.TestMutt object at 0x7fa06943ff10>, completion = <CompletionResult ['\x08\x08foo.mbx']>

    @pytest.mark.complete("mutt -F muttrc -f +f", require_cmd=True, cwd="mutt")
    def test_plus_is_not_eaten(self, completion):
>       assert completion == "oo.mbx".split()
E       AssertionError: assert <CompletionRe...\x08foo.mbx']> == ['oo.mbx']
E         Use -v to get the full diff

/home/mg/src/bash-completion/test/t/test_mutt.py:30: AssertionError

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

Successfully merging this pull request may close these issues.

mutt -f +file<tab> loses the + upon expansion
1 participant