lima icon indicating copy to clipboard operation
lima copied to clipboard

Allow command aliasing via PATH lookup

Open jandubois opened this issue 6 months ago • 6 comments

There have been several requests to add additional aliases to limactl commands, e.g. ps for list or ssh for shell.

Instead of adding more and more personal aliases into the app itself, I would like to see a generic command aliasing mechanism like git and kubectl already implement:

When a subcommand foo does not exist then limactl will look for limactl-foo on the PATH, and execute that program instead (passing all commandline arguments along).

Let's assume we add --running filter to the list subcommand, then a user could create limactl-ps:

#!/bin/sh
limactl list --running "$@"

jandubois avatar Jun 05 '25 18:06 jandubois

Sounds like the right way!

nirs avatar Jun 05 '25 18:06 nirs

Instead of adding more and more personal aliases into the app itself, I would like to see a generic command aliasing mechanism like git and kubectl already implement:

What are pros (and cons) of making them subcommands of git/kubectl/limactl, not independent commands?

AkihiroSuda avatar Jun 06 '25 04:06 AkihiroSuda

The main reason for the subcommands is that people have claimed they expected a certain alias to work, so they just typed it subconsciously.

E.g. when working mostly with docker and using docker ps to list containers, it feels natural to run limactl ps to list machines.

When you make it a different command, you still have to think about it and type the correct command. Then you can also just remember to type limactl ls.

@nirs explained that the same happens to him that he types limactl ssh instead of limactl shell.

We discussed different ways to accomplish this on Slack, and using this plugin mechanism seems like a well established pattern and seems fairly simple to implement.

jandubois avatar Jun 06 '25 06:06 jandubois

Aliasing ssh=shell should be fine and can be just implemented in the upstream, but aliasing ps=ls seems weird.

If we are going to have limactl ps, that should diverge from limactl ls and should print information specifically about running instances.

AkihiroSuda avatar Jun 06 '25 08:06 AkihiroSuda

Added #3613 to get more input on this. This is also easy task for new contributors.

nirs avatar Jun 06 '25 14:06 nirs

Aliasing ssh=shell should be fine and can be just implemented in the upstream, but aliasing ps=ls seems weird.

I replied in #3613 why I think aliasing ssh to shell is also weird.

If we are going to have limactl ps, that should diverge from limactl ls and should print information specifically about running instances.

Yes, but I don't think we should have a ps subcommand at all. We should add a --running option (and maybe --stopped or allow --running=false as well) to list.


But this issue is really about providing a plugin mechanism similar to git, gh, kubectl, docker, helm, kustomize, terraform (I'm sure there are plenty more).

The discussion about the specific examples is really a distraction; what is the argument why limactl should not support a similar plugin mechanism?

jandubois avatar Jun 06 '25 15:06 jandubois

can this be assigned to me?

olamilekan000 avatar Aug 14 '25 14:08 olamilekan000

I also think the PATH lookup implementation should be documented but I am not sure if it should be done in this pr or in a separate one.

olamilekan000 avatar Aug 14 '25 15:08 olamilekan000

I also think the PATH lookup implementation should be documented but I am not sure if it should be done in this pr or in a separate one.

It would be best to start with the documentation to make sure we agree on how the feature will work before spending time on coding. This will also ensure that we don't forget to document this feature.

nirs avatar Aug 14 '25 15:08 nirs

I also think the PATH lookup implementation should be documented but I am not sure if it should be done in this pr or in a separate one.

It would be best to start with the documentation to make sure we agree on how the feature will work before spending time on coding. This will also ensure that we don't forget to document this feature.

oh, I just opened a PR for it. I can always update based on how the conversation goes.

olamilekan000 avatar Aug 14 '25 15:08 olamilekan000

Reopening as:

  • limactl --help and limactl info should show the available plugins
  • PREFIX/libexec/lima should be scanned in addition to $PATH

AkihiroSuda avatar Sep 05 '25 09:09 AkihiroSuda

This can be done in another pr right? @AkihiroSuda

olamilekan000 avatar Sep 05 '25 10:09 olamilekan000

This can be done in another pr right? @AkihiroSuda

The original PR was merged, so there is no other option.

nirs avatar Sep 05 '25 11:09 nirs

This can be done in another pr right? @AkihiroSuda

The original PR was merged, so there is no other option.

I opened a PR for it.

olamilekan000 avatar Sep 05 '25 12:09 olamilekan000