Skip to content
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
13 changes: 5 additions & 8 deletions src/subcommand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,19 +272,16 @@ impl Subcommand {
return Err(Error::NoChoosableRecipes);
}

let mut command = justfile.settings.shell_command(config);

let chooser = if let Some(chooser) = chooser {
chooser.as_str().into()
} else {
let mut chooser = String::new();
chooser.push_str("fzf --multi --preview 'just --unstable --color always --justfile \"");
chooser.push_str(search.justfile.as_str());
chooser.push_str("\" --show {}'");
chooser
command.env("JUST_JUSTFILE", &search.justfile);
"fzf --multi --preview 'just --unstable --color always --show {}'".into()
};

let result = justfile
.settings
.shell_command(config)
let result = command
.shell_arg(&chooser)
.current_dir(&search.working_directory)
.stdin(Stdio::piped())
Expand Down
46 changes: 45 additions & 1 deletion tests/choose.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ fn invoke_error_function() {
",
)
.stderr_regex(
r#"error: chooser `/ -cu fzf --multi --preview 'just --unstable --color always --justfile ".*justfile" --show \{\}'` invocation failed: .*\n"#,
r"error: chooser `/ -cu fzf --multi --preview 'just --unstable --color always --show \{\}'` invocation failed: .*\n",
)
.shell(false)
.args(["--shell", "/", "--choose"])
Expand Down Expand Up @@ -374,6 +374,50 @@ fn visit_modules_in_alphabetical_order() {
.success();
}

#[cfg(unix)]
#[test]
fn default_chooser_preview_finds_justfile() {
let tmp = tempdir();

fs::write(tmp.path().join("foo.just"), "foo:\n echo foo\n").unwrap();

let fzf = tmp.path().join("fzf");
fs::write(
&fzf,
format!(
"#!/usr/bin/env bash\neval \"${{3//\\{{\\}}/foo}}\" > '{}' 2>&1\necho foo\n",
tmp.path().join("output").display(),
),
)
.unwrap();
fs::set_permissions(&fzf, std::os::unix::fs::PermissionsExt::from_mode(0o700)).unwrap();

let path = env::join_paths(
[
tmp.path().to_owned(),
Path::new(JUST).parent().unwrap().to_owned(),
]
.into_iter()
.chain(env::split_paths(&env::var_os("PATH").unwrap())),
)
.unwrap();

let output = Command::new(JUST)
.arg("--choose")
.arg("--justfile=foo.just")
.current_dir(tmp.path())
.env("PATH", path)
.output()
.unwrap();

assert_stdout(&output, "foo\n");

assert_eq!(
fs::read_to_string(tmp.path().join("output")).unwrap(),
"foo:\n echo foo\n"
);
}

#[cfg(unix)]
#[test]
fn chooser_signal_exit_code_is_propagated() {
Expand Down
Loading