~rjarry/aerc-devel

aerc: commands: run a command by its first letters v1 NEEDS REVISION

Vitaly Ovchinnikov: 1
 commands: run a command by its first letters

 1 files changed, 22 insertions(+), 0 deletions(-)
#1058447 alpine-edge.yml success
#1058448 openbsd.yml success
2023. szept. 17. 2:57:21 Vitaly Ovchinnikov <v@postbox.nz>:
Next
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~rjarry/aerc-devel/patches/44796/mbox | git am -3
Learn more about email & git

[PATCH aerc] commands: run a command by its first letters Export this patch

Check if the command entered after : is a prefix 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>
---

The reason behind the patch is that I want exit aerc with :q - something
that I used to with vim. I tried adding a command alias (quit/exit/q),
but it is added to the completion list which is not good. I also tried
adding a binding: :q = :quit, but it crashes aerc when pressed. So here
is another approach that gives the command a second chance if there is
no direct matching.
 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 5m38s

[commands: run a command by its first letters][0] from [Vitaly Ovchinnikov][1]

[0]: https://lists.sr.ht/~rjarry/aerc-devel/patches/44796
[1]: mailto:v@postbox.nz

✓ #1058448 SUCCESS aerc/patches/openbsd.yml     https://builds.sr.ht/~rjarry/job/1058448
✓ #1058447 SUCCESS aerc/patches/alpine-edge.yml https://builds.sr.ht/~rjarry/job/1058447