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

Chooser: Pass justfile path to preview command for default chooser #1759

Merged
merged 4 commits into from
Dec 14, 2023
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
2 changes: 1 addition & 1 deletion completions/just.elvish
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ edit:completion:arg-completer[just] = [@words]{
cand -v 'Use verbose output'
cand --verbose 'Use verbose output'
cand --changelog 'Print changelog'
cand --choose 'Select one or more recipes to run using a binary. If `--chooser` is not passed the chooser defaults to the value of $JUST_CHOOSER, falling back to `fzf`'
cand --choose 'Select one or more recipes to run using a binary chooser. If `--chooser` is not passed the chooser defaults to the value of $JUST_CHOOSER, falling back to `fzf`'
cand --dump 'Print justfile'
cand -e 'Edit justfile with editor given by $VISUAL or $EDITOR, falling back to `vim`'
cand --edit 'Edit justfile with editor given by $VISUAL or $EDITOR, falling back to `vim`'
Expand Down
2 changes: 1 addition & 1 deletion completions/just.fish
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ complete -c just -n "__fish_use_subcommand" -s u -l unsorted -d 'Return list and
complete -c just -n "__fish_use_subcommand" -l unstable -d 'Enable unstable features'
complete -c just -n "__fish_use_subcommand" -s v -l verbose -d 'Use verbose output'
complete -c just -n "__fish_use_subcommand" -l changelog -d 'Print changelog'
complete -c just -n "__fish_use_subcommand" -l choose -d 'Select one or more recipes to run using a binary. If `--chooser` is not passed the chooser defaults to the value of $JUST_CHOOSER, falling back to `fzf`'
complete -c just -n "__fish_use_subcommand" -l choose -d 'Select one or more recipes to run using a binary chooser. If `--chooser` is not passed the chooser defaults to the value of $JUST_CHOOSER, falling back to `fzf`'
complete -c just -n "__fish_use_subcommand" -l dump -d 'Print justfile'
complete -c just -n "__fish_use_subcommand" -s e -l edit -d 'Edit justfile with editor given by $VISUAL or $EDITOR, falling back to `vim`'
complete -c just -n "__fish_use_subcommand" -l evaluate -d 'Evaluate and print all variables. If a variable name is given as an argument, only print that variable\'s value.'
Expand Down
2 changes: 1 addition & 1 deletion completions/just.powershell
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Register-ArgumentCompleter -Native -CommandName 'just' -ScriptBlock {
[CompletionResult]::new('-v', 'v', [CompletionResultType]::ParameterName, 'Use verbose output')
[CompletionResult]::new('--verbose', 'verbose', [CompletionResultType]::ParameterName, 'Use verbose output')
[CompletionResult]::new('--changelog', 'changelog', [CompletionResultType]::ParameterName, 'Print changelog')
[CompletionResult]::new('--choose', 'choose', [CompletionResultType]::ParameterName, 'Select one or more recipes to run using a binary. If `--chooser` is not passed the chooser defaults to the value of $JUST_CHOOSER, falling back to `fzf`')
[CompletionResult]::new('--choose', 'choose', [CompletionResultType]::ParameterName, 'Select one or more recipes to run using a binary chooser. If `--chooser` is not passed the chooser defaults to the value of $JUST_CHOOSER, falling back to `fzf`')
[CompletionResult]::new('--dump', 'dump', [CompletionResultType]::ParameterName, 'Print justfile')
[CompletionResult]::new('-e', 'e', [CompletionResultType]::ParameterName, 'Edit justfile with editor given by $VISUAL or $EDITOR, falling back to `vim`')
[CompletionResult]::new('--edit', 'edit', [CompletionResultType]::ParameterName, 'Edit justfile with editor given by $VISUAL or $EDITOR, falling back to `vim`')
Expand Down
2 changes: 1 addition & 1 deletion completions/just.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ _just() {
'*-v[Use verbose output]' \
'*--verbose[Use verbose output]' \
'--changelog[Print changelog]' \
'--choose[Select one or more recipes to run using a binary. If `--chooser` is not passed the chooser defaults to the value of $JUST_CHOOSER, falling back to `fzf`]' \
'--choose[Select one or more recipes to run using a binary chooser. If `--chooser` is not passed the chooser defaults to the value of $JUST_CHOOSER, falling back to `fzf`]' \
'--dump[Print justfile]' \
'-e[Edit justfile with editor given by $VISUAL or $EDITOR, falling back to `vim`]' \
'--edit[Edit justfile with editor given by $VISUAL or $EDITOR, falling back to `vim`]' \
Expand Down
18 changes: 12 additions & 6 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,19 @@ use {
clap::{App, AppSettings, Arg, ArgGroup, ArgMatches, ArgSettings},
};

// These three strings should be kept in sync:
pub(crate) const CHOOSER_DEFAULT: &str =
"fzf --multi --preview 'just --unstable --color always --show {}'";
pub(crate) const CHOOSER_ENVIRONMENT_KEY: &str = "JUST_CHOOSER";
pub(crate) const CHOOSE_HELP: &str = "Select one or more recipes to run using a binary. If \
`--chooser` is not passed the chooser defaults to the value \
of $JUST_CHOOSER, falling back to `fzf`";

pub(crate) const CHOOSE_HELP: &str = "Select one or more recipes to run using a binary chooser. \
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)]
#[allow(clippy::struct_excessive_bools)]
Expand Down
2 changes: 1 addition & 1 deletion src/subcommand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ impl Subcommand {
let chooser = chooser
.map(OsString::from)
.or_else(|| env::var_os(config::CHOOSER_ENVIRONMENT_KEY))
.unwrap_or_else(|| OsString::from(config::CHOOSER_DEFAULT));
.unwrap_or_else(|| config::chooser_default(&search.justfile));

let result = justfile
.settings
Expand Down
2 changes: 1 addition & 1 deletion tests/choose.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ fn invoke_error_function() {
",
)
.stderr_regex(
r"error: Chooser `/ -cu fzf --multi --preview 'just --unstable --color always --show \{\}'` invocation failed: .*\n",
r#"error: Chooser `/ -cu fzf --multi --preview 'just --unstable --color always --justfile ".*justfile" --show \{\}'` invocation failed: .*\n"#,
)
.status(EXIT_FAILURE)
.shell(false)
Expand Down
Loading