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

A way to set command aliases #3626

Open
lyderic opened this issue Mar 3, 2024 · 1 comment
Open

A way to set command aliases #3626

lyderic opened this issue Mar 3, 2024 · 1 comment
Labels
enhancement New feature or request patience Patience required, there is no date for this being fixed

Comments

@lyderic
Copy link

lyderic commented Mar 3, 2024

Is your feature request related to a problem? Please describe.

This is not related to a problem but that'd be a nice to have.

Command aliases would be a cool feature indeed. Silly example, for illustration purpose: I could be typing chezmoi s instead of chezmoi status --verbose.

In git for example, this is achieved as follows:

$ git config alias.s 'status --verbose'

Describe the solution you'd like

An alias could be set like this:

$ chezmoi alias s 'status --verbose'

The command chezmoi alias without arguments could display a list of the current aliases.

Another way of setting up an alias could be to put entries directly in the config file:

$ cat ~/.config/chezmoi/chezmoi.yaml
aliases:
  s: "status --verbose"

Describe alternatives you've considered

The only alternative I found is to create a script and use the chezmoi-${COMMAND} facility. It works, but it is a little cumbersome for a mere alias and it's not portable across operating systems and/or shells:

$ cat > ~/bin/chezmoi-s <<EOF
> #!/bin/bash
> 
> chezmoi status --verbose
> EOF
$ chmod +x ~/bin/chezmoi-s
$ chezmoi s
(outputs status)

NOTE: setting up a bash alias doesn't work:

$ alias 'chezmoi s'='chezmoi status --verbose'
-bash: alias: `chezmoi s': invalid alias name

Additional context

The alternative I suggest works for me, using bash on Linux. I am not sure bash is provided on Mac OS anymore and I guess a bash script won't work on Windows.

@lyderic lyderic added the enhancement New feature or request label Mar 3, 2024
@twpayne
Copy link
Owner

twpayne commented Mar 3, 2024

I'd like to add this, but it is not easy to do. chezmoi uses github.com/spf13/cobra for command line parsing, and sadly cobra does not support this kind of alias.

@twpayne twpayne added the patience Patience required, there is no date for this being fixed label Mar 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request patience Patience required, there is no date for this being fixed
Projects
None yet
Development

No branches or pull requests

2 participants