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

Aliases should support variable arguments or 'rest' arguments #1716

Closed
kvrhdn opened this issue May 6, 2020 · 10 comments
Closed

Aliases should support variable arguments or 'rest' arguments #1716

kvrhdn opened this issue May 6, 2020 · 10 comments
Labels
enhancement New feature or request Stale used for marking issues and prs as stale

Comments

@kvrhdn
Copy link
Contributor

kvrhdn commented May 6, 2020

Is your feature request related to a problem? Please describe.
I want to create an alias which will basically add a prefix to a command.

Use case: I use aws-vault to run commands with the correct AWS credentials:

aws-vault exec <my-profile> -- <some command>

I tried to create an alias like this:

alias kaws [cmd] { aws-vault exec <my-profile> -- $cmd }

But this will only capture one 'word'. For example, this fails:

kaws aws s3 ls
error: kaws unexpected s3
- shell:1:14
1 | kaws aws s3 ls
  |          ^^ unexpected argument (try kaws -h)

Describe the solution you'd like
I'd need a way to describe a parameter which captures multiple inputs.

Maybe something like:

alias kaws [...cmd] { aws-vault exec <my-profile> -- $cmd }

Describe alternatives you've considered
@jonathandturner proposed creating an alias with many arguements, with the idea that arguments that are not specified are left blank. But this doesn't work.

alias kaws [arg1 arg2 arg3 arg4 arg5] { .... }
kaws aws s3 ls
error: Alias failed to run
- shell:1:14
1 | kaws aws s3 ls
  | ^^^^ alias failed to run
- shell:1:14
1 | kaws aws s3 ls
  | ---- Type Error
(expected:
string,
actual:
nothing)

Additional context

@thegedge thegedge added the enhancement New feature or request label May 6, 2020
@fdncred
Copy link
Collaborator

fdncred commented May 6, 2020

Here's another similar example.

Alias:
alias build-profile [arg1 arg2 arg3] { with-env [RUSTFLAGS '-C debuginfo=2 -C opt-level=0 -C link_args=/PROFILE'] { cargo build $arg1 $arg2 $arg3 }}

Error:

error: Alias failed to run
- shell:1:13
1 | build-profile
  | ^^^^^^^^^^^^^ alias failed to run
- shell:1:13
1 | build-profile
  | ------------- Type Error
(expected:
string,
actual:
nothing)```

@sophiajt
Copy link
Contributor

sophiajt commented May 6, 2020

Can you try it again with #1722 and see if that helps the issue? It might take a few tries, but this approach is what seemed to make sense initially

@fdncred
Copy link
Collaborator

fdncred commented May 7, 2020

@jonathandturner my alias appears to be working with this change.

@github-actions
Copy link

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

@github-actions github-actions bot added the Stale used for marking issues and prs as stale label Jun 24, 2021
@github-actions
Copy link

github-actions bot commented Jul 7, 2021

This issue has been marked stale for more than 10 days without activity. Closing this issue, but if you find that the issue is still valid, please reopen.

@github-actions github-actions bot closed this as completed Jul 7, 2021
@yashamon
Copy link

What is the the status of this? Passing variables to aliases no longer appears possible.
alias ls [$dir] = ls $dir
is giving an error.

@fdncred
Copy link
Collaborator

fdncred commented Nov 22, 2022

Custom commands is what you want.

@yashamon
Copy link

yashamon commented Nov 22, 2022 via email

@fdncred
Copy link
Collaborator

fdncred commented Nov 22, 2022

You're right about def being scoped but if you try def-env it should work for your cd custom command. Sorry for not making that clear.

@yashamon
Copy link

yashamon commented Nov 22, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Stale used for marking issues and prs as stale
Projects
None yet
Development

No branches or pull requests

5 participants