Aliases for common cargo commands

I’m using the cargo module that provides access to Cargo commands with nice in-editor output. I wanted to shorten some commonly used commands, so :cargo test could just be :ct, :cargo build could be :cb, etc.

I can’t figure out how to do a more complex one where the arguments to my “shortcut” would be passed on to the thing that actually executes cargo. an example would be doing a Cargo run that could be invoked like :cr --release -- --argument value --other-arg other-value. I tried the following in my .kakrc:

def cr -file-completion -params .. -command-completion -docstring "cargo run <params>" %{
    write-all -sync
    cargo run "$@"
}

The "$@" clearly isn’t right, but the intent is: "take all the arguments to this command and pass them to cargo run". How can this be accomplished?

%arg{@}?

1 Like

This might not have been documented when you started using the Cargo plugin, but it provides a “cargo” user-mode for quick access to the most common commands. Following step 4 of the installation instructions, instead of :ct<ret> to run my tests, I can type ,ct to do the same thing, and save a keystroke!

Of course, that doesn’t let me add extra command-line arguments like the :cargo command does. Generally, if there’s a variation I run a lot, i just add it to the “cargo” user mode myself. For example, I have the following mapping to build tests for Windows and run them in Wine:

map -docstring "test Windows" global cargo w %{: cargo test --no-fail-fast --target x86_64-pc-windows-gnu<ret>}
1 Like

OK, cool.

%arg{@} does work for this particular case (adding a new “wrapper” command. But also, I’ve never tried user modesb or the key mapping feature. Those look helpful as well for other situations.

Actually, yeah, the key mapping is really useful. I converted most of my little “commands” into those and now they’re easier to access via the comma prefix. Nice.