You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Aliases should support variable arguments or 'rest' arguments #1716
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
Reacted by Ajeet D'Souza, Jonathan Knapp, Florian Touya, Zac Pullar-Strecker, good-unit and Kenichi Kamiya
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)```
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.
Custom command runs in a new scope so is not comparable.
eg. running on command line:
def mycd [dir] {cd $dir}
mycd foo
does nothing
One workaround solution would be to allow parameters to pass to the source
script invocation.
Then we could do something like (source mycd.nu) foo. (or some other
syntax) I think this does not exist at the moment or am I wrong?
I think in powershell you just do:
. mycd.ps1 foo
so sourcing with parameters is allowed.
But anyway this is a workaround it would be much better to have aliases
with parameters imo.
Activity
fdncred commentedon 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:
sophiajt commentedon 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 commentedon May 7, 2020
@jonathandturner my alias appears to be working with this change.
github-actions commentedon Jun 24, 2021
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 commentedon 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.
yashamon commentedon Nov 22, 2022
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 commentedon Nov 22, 2022
Custom commands is what you want.
yashamon commentedon Nov 22, 2022
fdncred commentedon Nov 22, 2022
You're right about
defbeing scoped but if you trydef-envit should work for your cd custom command. Sorry for not making that clear.yashamon commentedon Nov 22, 2022