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

Fix fzf chooser preview with space-separated module paths #2141

Merged
merged 3 commits into from
Jun 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 10 additions & 13 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,6 @@ const CHOOSE_HELP: &str = "Select one or more recipes to run using a binary choo
If `--chooser` is not passed the chooser defaults to the \
value of $JUST_CHOOSER, falling back to `fzf`";

pub(crate) fn chooser_default(justfile: &Path) -> OsString {
let mut chooser = OsString::new();
chooser.push("fzf --multi --preview 'just --unstable --color always --justfile \"");
chooser.push(justfile);
chooser.push("\" --show {}'");
chooser
}

#[derive(Debug, PartialEq)]
pub(crate) struct Config {
pub(crate) check: bool,
Expand Down Expand Up @@ -568,15 +560,20 @@ impl Config {
}
}

fn parse_module_path(path: ValuesRef<String>) -> ConfigResult<ModulePath> {
fn parse_module_path(values: ValuesRef<String>) -> ConfigResult<ModulePath> {
let path = values.clone().map(|s| (*s).as_str()).collect::<Vec<&str>>();

let path = if path.len() == 1 && path[0].contains(' ') {
path[0].split_whitespace().collect::<Vec<&str>>()
} else {
path
};

path
.clone()
.map(|s| (*s).as_str())
.collect::<Vec<&str>>()
.as_slice()
.try_into()
.map_err(|()| ConfigError::ModulePath {
path: path.cloned().collect(),
path: values.cloned().collect(),
})
}

Expand Down
10 changes: 9 additions & 1 deletion src/subcommand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,15 @@ impl Subcommand {
return Err(Error::NoChoosableRecipes);
}

let chooser = chooser.map_or_else(|| config::chooser_default(&search.justfile), From::from);
let chooser = if let Some(chooser) = chooser {
OsString::from(chooser)
} else {
let mut chooser = OsString::new();
chooser.push("fzf --multi --preview 'just --unstable --color always --justfile \"");
chooser.push(&search.justfile);
chooser.push("\" --show {}'");
chooser
};

let result = justfile
.settings
Expand Down
15 changes: 15 additions & 0 deletions tests/show.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,18 @@ fn show_invalid_path() {
.status(1)
.run();
}

#[test]
fn show_space_separated_path() {
Test::new()
.write("foo.just", "bar:\n @echo MODULE")
.justfile(
"
mod foo
",
)
.test_round_trip(false)
.args(["--unstable", "--show", "foo bar"])
.stdout("bar:\n @echo MODULE\n")
.run();
}