Check if the command entered after : is an abbreviation of an existing
command and run that. This is only done if there is no complete name
matching first-hand.
Signed-off-by: Vitaly Ovchinnikov <v@postbox.nz>
Thanks! Yesterday I forgot to test what happens when you put in something
ambiguous. When executing :co, I get an error for :cp usage, so I think it
found copy, but it should have given an error about ambiguous abbreviation,
since we have :copy, :compose and two other commands starting with :co.
That's interesting. I tested it with :ex and it worked just fine. Test
with :co fails. It seems that there is a few commands list and one of
them has just one command starting with "co" - `:copy` which matches the
search.
It sounds like I need to move the check higher at the call stack. Will
see what can be done about that. Thank you!
OK, so I did it a different way one level up the stack. I even like
this approach more as it is separated from the command execution logic.
See v3 for the new stuff. For some reasons the openbsd build failed due
to the lack of gmake. Not sure why it happens, probably an unrelated
issue?
--
+36305425054
bence.ferdinandy.com
---
The reason behind the patch is that I want exit aerc with :q - something
that I used to do with vim.
I tried making a command alias (like: quit/exit/q), but this appears in
the completion list which is not a good idea.
I also tried adding a binding: :q = :quit, but it crashes aerc when
pressed. Stack overflow? Didn't check it too deep...
So here is another approach that gives the command a second
chance if there is no direct match.
- v1 - initial version
- v2 - commit message refined
commands/commands.go | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
diff --git a/commands/commands.go b/commands/commands.go
index 9366be9..e25e211 100644
--- a/commands/commands.go+++ b/commands/commands.go
@@ -132,6 +132,28 @@ func (cmds *Commands) ExecuteCommand(
log.Tracef("executing command %v", args)
return cmd.Execute(aerc, args)
}
++ var partialCmd Command+ var partialName string+ for name, cmd := range cmds.dict() {+ if !strings.HasPrefix(name, args[0]) { // not matched+ continue+ }+ if partialCmd != nil { // more than two commands matched, can't exec that+ partialCmd = nil+ break+ }+ // match, store it+ partialCmd = cmd+ partialName = name+ }++ if partialCmd != nil {+ args[0] = partialName // so the command gets its full name+ log.Tracef("executing command %v", args)+ return partialCmd.Execute(aerc, args)+ }+ return NoSuchCommand(args[0])
}
--
2.39.2 (Apple Git-143)
aerc/patches: SUCCESS in 4m52s
[commands: run a command by its first letters][0] v2 from [Vitaly Ovchinnikov][1]
[0]: https://lists.sr.ht/~rjarry/aerc-devel/patches/44802
[1]: mailto:v@postbox.nz
✓ #1058750 SUCCESS aerc/patches/openbsd.yml https://builds.sr.ht/~rjarry/job/1058750
✓ #1058749 SUCCESS aerc/patches/alpine-edge.yml https://builds.sr.ht/~rjarry/job/1058749