foundry-rs / foundry-rs/foundry

feat(`cli`): enhance shell completions for arguments and parameters

Open
#11,095 4 comments 0 reactions 0 assignees View on GitHub
A-compatibility T-feature T-to-discuss
Dominant language
Rust
Stars
10.6k
Forks
2.6k
Avg merge
18h 20m
Merged PRs (30d)
510

Description

### Component

Cast, Forge

### Describe the feature you would like

I'm writing to propose a feature that I believe would significantly enhance the developer experience: expanding the shell completion capabilities beyond just subcommands to include common arguments and parameters.

#### **Motivation**

The current shell completion (for Bash, Zsh, etc.) is great for discovering and typing subcommands (e.g., `forge t` -> `forge test`). However, a large part of our interaction with Foundry involves providing specific arguments that are often long, cumbersome to remember, and easy to mistype.

Automating the completion of these values would dramatically improve DX, reduce cognitive load, and streamline common workflows.

#### **Proposed Enhancements**

Here are some specific areas where argument completion would be extremely valuable. The completions should be context-aware of the current Foundry project.

1. **`--rpc-url` Completion**
* **Context:** When a user types `--rpc-url ` and hits `Tab`.
* **Behavior:** It should suggest the chain aliases defined in the `[rpc_endpoints]` section of `foundry.toml`.
* **Example:** If `foundry.toml` has `mainnet = "..."`, `sepolia = "..."`, typing `--rpc-url s` would complete to `--rpc-url sepolia`.

2. **`--account` Completion**
* **Context:** When a user types `--account ` and hits `Tab`.
* **Behavior:** It should suggest the account aliases available from `cast wallet list`.
* **Example:** If I have wallets named `deployer` and `tester`, typing `--account d` would complete to `--account deployer`.

3. **Function Signature Completion for `cast` and `forge`**
* **Context:** For commands like `cast call`, `cast send`, `cast logs`, `cast calldata`, `cast decode-*`, `cast abi-encode`, etc.
* **Behavior:** It should suggest function signatures based on the project's compiled ABIs (essentially, the data source for `forge selectors list`).
* **Example:** `cast call 0x... tr` would suggest `transfer(address,uint256)`.

4. **`forge script` Contract Name Completion**
* **Context:** When specifying a script contract with the `:` syntax.
* **Behavior:** After typing the file path and a colon (`:`), hitting `Tab` should list the valid contract names within that script file.
* **Example:** `forge script script/Counter.s.sol:C` would complete to `forge script script/Counter.s.sol:CounterScript`.

5. **`forge script -s / --sig` Signature Completion**
* **Context:** When using the `-s` or `--sig` flag with `forge script`.
* **Behavior:** It should suggest function signatures available within the specified target script contract.
* **Example:** `forge script ... -s r` would suggest `run()`.

6. **`forge test` Filter Completion**
* **Context:** When using filter flags like `--match-contract`, `--match-test`, `--match-path`.
* **Behavior:**
* `--match-contract`: Should complete with contract names within the project.
* `--match-test`: Should complete with test function names (e.g., `testFuzz_...`, `test_...`) from the matched contracts.
* `--match-path`: Should complete with file/directory paths.
* **Example:** `forge test --match-contract C` would suggest `CounterTest`. Then, `forge test --match-contract CounterTest --match-test testI` would suggest `testIncrement()`.

#### **Implementation Considerations**

Foundry already has internal access to all the information needed for these completions (TOML config, wallet list, compiled ABIs, file-contract mappings). The main effort would be to create the logic within the shell completion scripts to query this information and present it to the user.

This feature would be a massive quality-of-life improvement for all Foundry users and would further solidify its position as the leading toolkit for smart contract development.

### Additional context

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.