A simple, modern fuzzy finder tool to run examples in a Cargo project.

Overview

cargo-rx

github crates.io docs.rs build status

cargo-rx is a simple, modern Runner for Examples in a Cargo project.

rx demo

This crate provides a single executable: rx. Basically anywhere you would use cargo run --example in a Rust project, run rx instead.

Installation

Ensure that you have a fairly recent version of rust/cargo installed. Then, run:

$ cargo install cargo-rx

Compiler support: requires rustc 1.58+

(Please check cargo's documentation to learn how cargo install works and how to set up your system so it finds binaries installed by cargo.)

Windows

Note that on a Windows environment, you will also need to have fzf (https://github.com/junegunn/fzf) installed, as the rx command will use the fzf executable as a fuzzy finder instead.

There is currently a feature request open on skim which proposes adding support for Windows, but this has not been currently implemented yet -- thus, the fzf tool serves as a stand-in alternative for now.

Features

  • Fuzzy finder to sort and search for examples in a Cargo project -- when called with just rx.
  • Pass arguments after -- to the selected example.
  • Automatically enables required-features when running an example.
  • Play back of most recently run example via --replay.

Contributing

Contributions are welcome! Open a pull request to fix a bug, or open an issue to discuss a new feature or change.

Check out the Contributing section in the docs for more info.

License

This project is proudly licensed under the MIT license (LICENSE or http://opensource.org/licenses/MIT).

cargo-rx can be distributed according to the MIT license. Contributions will be accepted under the same license.

Authors

Comments
  • add quotes around multi-word arguments, when displaying equivalent `cargo run --example` command

    add quotes around multi-word arguments, when displaying equivalent `cargo run --example` command

    Version

    0.1.0

    Platform

    Mac OS X

    Description

    When running rx against an example that takes arguments, when I add quotes around an argument, I would expect the terminal output which displays the command to similarly include quotes around my argument.

    For example, when I run following command and select an example my_example:

    $rx -- --my-arg 'my "name" here'
    

    the terminal output of the command being run is currently like:

    >> cargo run --example my_example -- --my-arg my name here
    

    when instead, I want it to display like:

    >> cargo run --example my_example -- --my-arg "my \"name\" here"
    

    ...which more closely matches the format of the command being run. it's also helpful so that we can use the command being printed out for debugging purposes, and if we just copy-paste the command into a terminal window verbatim, it should work the same to run cargo run --example and not cause any errors when running the example using that approach.

    bug 
    opened by rnag 0
  • v0.2.0: minor release

    v0.2.0: minor release

    Notable Issues

    This PR Resolves the following issues:

    • #2
      • At least on Linux/Mac, this was previously a problem. This was resolved after reading through a linked issue.
    • #5
    • #8
    • #13
    • #16

    Changes

    • Add support for options to cargo run --example, such as --release and --features. ๐ŸŽ‰
      • Automatically enables +nightly toolchain as required, when passed in unstable options to cargo run such as --unit-graph.
    • Display all example files supported by cargo, such as multi-file examples and ones with custom file paths. ๐ŸŽ‰
    • Patch colored output for Windows; the quickfix is implemented as suggested from here. ๐Ÿ™Œ
    • Examples displayed in the fuzzy finder are now properly sorted, A->Z as expected. ๐Ÿ–๏ธ
    • The terminal output of the command being run, i.e. cargo run --example <selected example> [..args], now correctly displays arguments in quotes such as --arg "Hello \"world\"!", which more closely matches the format of the command being run. ๐Ÿ‘
    • Rewire -p|--prompt-args to -i|--input-args, but retained existing option for backwards-compatibility reasons.
    • Rename short option for --replay to -R, since -r is now a shorthand for --release.
    • Update Cargo.toml dependencies.
      • Add cargo-options and path-absolutize
      • Update to use home instead of dirs, as overall it appears to be more stable
    opened by rnag 0
  • Add extra options that `cargo run` supports

    Add extra options that `cargo run` supports

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

    I would like to be able to pass options such as --features or --release -- which cargo run supports currently -- to the rx command.

    Describe the solution you'd like

    I would like to update rx to also accept same options that cargo run --example does.

    Additional context

    I need to pass --features in another project currently for some examples occasionally, so this would be helpful to enable. My use case is I have a separate feature for dev/prod environments; and occasionally I would like to run an example for a production environment, i.e. with the relevant feature enabled.

    enhancement 
    opened by rnag 0
  • examples nested in sub-folders should be included

    examples nested in sub-folders should be included

    Description

    This is a simple fix, but basically nested examples like examples/some_example/main.rs are not captured currently, since we only look one level deep, specifically for rust (.rs) source files.

    Here we will need to update our code to traverse directories in examples/ folder (at least one level deep for now, not sure if Cargo itself supports examples deeply nested in sub-folders) and search for any main.rs files. The example name displayed should of course be the subfolder name in this case.

    What does this involve exactly?

    Support following paths for rust files in the examples/ folder:

    • Files with custom paths not picked up by cargo by default, for instance example/my_folder/my_example_here.rs
      • In order to achieve this, we need to scan through the list of [[example]] sections in the Cargo.toml file
    • Multi-file examples with a main.rs file that cargo supports, such as examples/my_folder/main.rs
    bug 
    opened by rnag 0
  • fix color output for powershell in windows

    fix color output for powershell in windows

    • cargo-rx version: 0.1
    • Rust Compiler (rustc) version: ?
    • Operating System: windows 11 64-bit

    Description

    In powershell i see weird characters being shown instead of normal color output, for ex. when script outputs the >> cargo run --example <name> before running the script, for example.

    I need to research why it's happening and how to resolve it. I think it's the way we're invoking shell command in code, the pipe command which basically performs the equivalent of echo 'one\ntwo\nthree' | fzf apparently is not supported well in windows / powershell, at least from what I could tell when searching online.

    We need a way to not break colored text output in powershell when piping output of echo to another process like fzf.

    What I Did

    $ rx
    
    bug help wanted good first issue 
    opened by rnag 0
  • list of examples is not sorted

    list of examples is not sorted

    • cargo-rx version: 0.1.0
    • Rust Compiler (rustc) version: 1.59
    • Operating System: Mac OS X

    Description

    Output with list of examples is not sorted alphabetically (or even reverse sorted Z->A would be nice), but ideally I suppose it should be.

    example for my project smartsheet-rs:

    image

    What I Did

    I just cd into my project folder after a git clone and run:

    $ rx
    
    enhancement help wanted good first issue 
    opened by rnag 0
  • Work with workspaces?

    Work with workspaces?

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

    Some libraries like tract and axum use workspaces to indicate examples, but current cargo-rx does not seem to able to identify them.

    Describe the solution you'd like

    Identify workspaces for examples based on directory names?

    Additional context

    No.

    enhancement help wanted good first issue acknowledged 
    opened by Yevgnen 1
  • Automatically replace dashes `-` with underscores `_` in example names, if necessary

    Automatically replace dashes `-` with underscores `_` in example names, if necessary

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

    It would be cool if we can automatically replace dashes - with underscores _ (or vice versa) if we determine that a user-entered example name with dashes - is not a valid example, but that it would be instead valid with _.

    The main impetus for this is that it is somewhat easier to type a dash - on a keyboard - don't need to make a beeline for the shift key, for example. ๐Ÿค”

    Describe the solution you'd like

    Current output when running cargo run --example, when mis-typing _ as - for instance:

    PS serde-this-or-that> cargo run --example as-string
    error: no example target named `as-string`
    
            Did you mean `as_string`?
    

    Desired output:

    PS serde-this-or-that> cargo run --example as-string
    
    >> cargo run --example as_string
    [result of running the `as_string` example]
    
    enhancement help wanted good first issue 
    opened by rnag 0
  • Add a

    Add a "Did you mean?" prompt if user misspells example name, and optionally re-run if the user says "Yes!"

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

    I don't know if it's possible but I'd like to suggest auto-correction if a user misspells or mistypes an example name, similar to how cargo run --example does it already currently.

    Related Issues

    #18

    Describe the solution you'd like

    Potentially something like:

    
    Sorry bud, no such example `my_exmaple` exists.
    
    Did you mean `my_example`? [Y/N]:  $  
    Did you mean `my_example`? [Y/N]:  $  y
    
    [Runs the example file `my_example`...]
    

    Describe alternatives you've considered

    I haven't actually looked into any existing solutions for spelling correction yet. It would be cool to implement this, I feel. Preferably with the least overhead in terms of overall dependency size, compilation or build time, etc.

    Additional context

    It's not too necessary as when we call cargo run --example, it'll already offer an auto correction hint. But I think it's nice to add proactive spellchecking and correction -- this way it'll be a little faster, as we can catch the error earlier, and we don't need to waste time spawning a new process to call cargo run --example when we already know the example name is misspelled, for example.

    Just for completeness sake, Here's a sample auto correction hint from cargo run --example on one of my projects, which I think is really cool/nice:

    PS serde-this-or-that> cargo run --example d
    error: no example target named `d`
    
            Did you mean `demo`?
    
    enhancement help wanted good first issue 
    opened by rnag 0
  • format and stylize block comments as expected

    format and stylize block comments as expected

    Description

    See #11 for sample terminal output.

    Essentially, we need to figure out a way to support identifying block comments within /*! <snip> !*/ (for doc comments) or within /* <snip> */ for regular comments, so that we can format and stylize such comments (colored text, bolding, etc.) as expected.

    What I Did

    I just went into my project folder and ran:

    $ rx
    
    enhancement help wanted good first issue 
    opened by rnag 0
  • text wrap comments to completely fit within the preview pane

    text wrap comments to completely fit within the preview pane

    • cargo-rx version:
    • Rust Compiler (rustc) version:
    • Operating System:

    Description

    Instead of displaying the example file contents directly in the preview pane, it'd be ideal to leverage a text wrapping library such as textwrap to wrap the doc comments -- and regular comments if feasible -- so that we can be sure that the comments completely fit within the preview pane, and are displayed as expected without any text cutting off near the end.

    For example, note that comments in a line that are past a max width are hidden in the preview pane currently: image

    Related Issues

    This issue goes with #12

    What I Did

    I just cd into my project folder and ran:

    $ rx
    
    enhancement help wanted good first issue 
    opened by rnag 0
  • calculate width of left pane based on the max length of example filenames

    calculate width of left pane based on the max length of example filenames

    • cargo-rx version: 0.1
    • Rust Compiler (rustc) version: 1.59
    • Operating System: Mac OS X

    Description

    It would be ideal to calculate the current console width, then calculate the max width of the stem of each example file (filename without the extension). The max stem width can then be used to set the width of the left pane, and the remaining console width can be taken up by the preview pane on the right.

    For example (note the three dots ... below):

    Screen Shot 2022-04-04 at 11 15 11 AM

    What I Did

    Within my project folder, I just ran:

    $ rx
    
    enhancement help wanted good first issue 
    opened by rnag 0
Releases(v0.2.0)
Owner
Ritvik Nag
Python / Typescript developer, currently learning Rust ๐Ÿฆ€
Ritvik Nag
Skim - Fuzzy Finder in rust!

Life is short, skim! Half of our life is spent on navigation: files, lines, commandsโ€ฆ You need skim! It is a general fuzzy finder that saves you time.

Takayuki Maeda 0 May 16, 2021
Fzf - A command-line fuzzy finder

fzf is a general-purpose command-line fuzzy finder. It's an interactive Unix filter for command-line that can be used with any list; files, command hi

Junegunn Choi 49.1k Jan 8, 2023
Cargo subcommand to easily run targets/examples

cargo-select Cargo subcommand to easily run targets/examples/tests Fuzzy match against targets, examples or tests in current rust project. cargo-selec

null 13 Sep 15, 2022
Dead simple, memoized cargo subcommand to hoist cargo-built binaries into the current working directory, written in Rust.

cargo-hoist Dead simple cargo subcommand to hoist cargo-built binaries into scope. stable Install | User Docs | Crate Docs | Reference | Contributing

refcell.eth 6 Nov 9, 2023
A CLI tool that allow you to create a temporary new rust project using cargo with already installed dependencies

cargo-temp A CLI tool that allow you to create a new rust project in a temporary directory with already installed dependencies. Install Requires Rust

Yohan Boogaert 61 Oct 31, 2022
A simple, opinionated way to run containers for tests in your Rust project.

rustainers rustainers is a simple, opinionated way to run containers for tests. TLDR More information about this crate can be found in the crate docum

wefox 4 Nov 23, 2023
Helps cargo build and run apps for iOS

cargo-xcodebuild Helps cargo build and run apps for iOS. ?? โš™๏ธ ?? Setup You need to install Xcode (NOT just Command Line Tools!), xcodegen, cargo-xcod

Igor Shaposhnik 29 Nov 22, 2022
A cargo plugin to shrink cargo's output

cargo single-line A simple cargo plugin that shrinks the visible cargo output to a single line (okay, in the best case scenario). In principle, the pl

Denis 5 Oct 30, 2022
Cargo-eval - A cargo plugin to quickly evaluate some Rust source code.

cargo eval A cargo plugin to quickly evaluate some Rust source code. Installation $ cargo install --git https://github.com/timClicks/cargo-eval.git Us

Tim McNamara 9 Dec 21, 2022
Cargo-about - ๐Ÿ“œ Cargo plugin to generate list of all licenses for a crate ๐Ÿฆ€

?? cargo-about Cargo plugin for generating a license listing for all dependencies of a crate See the book ?? for in-depth documentation. Please Note:

Embark 281 Jan 1, 2023
Cargo subcommand for running cargo without dev-dependencies.

cargo-no-dev-deps Cargo subcommand for running cargo without dev-dependencies. This is an extraction of the --no-dev-deps flag of cargo-hack to be use

Taiki Endo 5 Jan 12, 2023
Save cli commands and fuzzy find them later

crow - cli command memorizer What is crow? | Installation | Usage | FAQ What is crow? crow (command row) is a CLI tool to help you memorize CLI comman

sandstorm 7 Feb 17, 2022
๐Ÿง  A command-line utility for switching git branches more easily. Switch branches interactively or use a fuzzy search to find that long-forgotten branch name.

git-smart-checkout A git command extension for switching git branches more efficiently. About Interactively switch branches or fuzzy search for that f

Cezar Craciun 51 Dec 29, 2022
Fuzzy Index for Python, written in Rust. Works like error-tolerant dict, keyed by a human input.

FuzzDex FuzzDex is a fast Python library, written in Rust. It implements an in-memory fuzzy index that works like an error-tolerant dictionary keyed b

Tomasz bla Fortuna 8 Dec 15, 2022
A multi-page fuzzy launcher for your terminal, written in Rust.

fr33zmenu A multi-page fuzzy launcher for your terminal, written in Rust. Supports theming and multiple keybind schemes, including basic vim keybinds.

null 3 Dec 15, 2022
Integrate Mcfly with fzf to combine a solid command history database with a widely-loved fuzzy search UI

McFly fzf integration Integrate McFly with fzf to combine a solid command history database with a widely-loved fuzzy search UI Features: Advanced hist

null 11 Jan 25, 2023
Fast TLSH-compatible Fuzzy Hashing Library in pure Rust

fast-tlsh: Fast TLSH-compatible Fuzzy Hashing Library in pure Rust TLSH stands for Trendmicro Locality Sensitive Hash. TLSH can be used to detect simi

Tsukasa OI 4 Mar 27, 2024
A command line tool written in Rust and designed to be a modern build tool + package manager for C/C++ projects.

CCake CCake is a command line tool written in Rust and designed to be a modern build tool + package manager for C/C++ projects. Goals To be easily und

Boston Vanseghi 4 Oct 24, 2022
๐Ÿค– just is a handy way to save and run project-specific commands.

just just is a handy way to save and run project-specific commands. (้žๅฎ˜ๆ–นไธญๆ–‡ๆ–‡ๆกฃ,่ฟ™้‡Œ,ๅฟซ็œ‹่ฟ‡ๆฅ!) Commands, called recipes, are stored in a file called justfile

Casey Rodarmor 8.2k Jan 5, 2023