~rjarry/aerc-devel

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

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

 1 files changed, 22 insertions(+), 0 deletions(-)
#1058749 alpine-edge.yml success
#1058750 openbsd.yml success



          
          
          
          
Next



          
          
          
          
Next
Vitaly Ovchinnikov, Sep 17, 2023 at 20:21:
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/44802/mbox | git am -3
Learn more about email & git

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

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>
---

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