feat: add --score option (#1030)

This commit is contained in:
Azalea Colburn 2025-03-30 23:13:40 -07:00 committed by GitHub
parent 7617799eb5
commit e1e2f41ecb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 32 additions and 2 deletions

View File

@ -30,6 +30,8 @@ _zoxide() {
case $line[1] in
(add)
_arguments "${_arguments_options[@]}" : \
'-s+[The rank to increment the entry if it exists or initialize it with if it doesn'\''t]:SCORE: ' \
'--score=[The rank to increment the entry if it exists or initialize it with if it doesn'\''t]:SCORE: ' \
'-h[Print help]' \
'--help[Print help]' \
'-V[Print version]' \

View File

@ -34,6 +34,8 @@ Register-ArgumentCompleter -Native -CommandName 'zoxide' -ScriptBlock {
break
}
'zoxide;add' {
[CompletionResult]::new('-s', '-s', [CompletionResultType]::ParameterName, 'The rank to increment the entry if it exists or initialize it with if it doesn''t')
[CompletionResult]::new('--score', '--score', [CompletionResultType]::ParameterName, 'The rank to increment the entry if it exists or initialize it with if it doesn''t')
[CompletionResult]::new('-h', '-h', [CompletionResultType]::ParameterName, 'Print help')
[CompletionResult]::new('--help', '--help', [CompletionResultType]::ParameterName, 'Print help')
[CompletionResult]::new('-V', '-V ', [CompletionResultType]::ParameterName, 'Print version')

View File

@ -63,12 +63,20 @@ _zoxide() {
return 0
;;
zoxide__add)
opts="-h -V --help --version <PATHS>..."
opts="-s -h -V --score --help --version <PATHS>..."
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
fi
case "${prev}" in
--score)
COMPREPLY=($(compgen -f "${cur}"))
return 0
;;
-s)
COMPREPLY=($(compgen -f "${cur}"))
return 0
;;
*)
COMPREPLY=()
;;

View File

@ -30,6 +30,8 @@ set edit:completion:arg-completer[zoxide] = {|@words|
cand remove 'Remove a directory from the database'
}
&'zoxide;add'= {
cand -s 'The rank to increment the entry if it exists or initialize it with if it doesn''t'
cand --score 'The rank to increment the entry if it exists or initialize it with if it doesn''t'
cand -h 'Print help'
cand --help 'Print help'
cand -V 'Print version'

View File

@ -32,6 +32,7 @@ complete -c zoxide -n "__fish_zoxide_needs_command" -f -a "import" -d 'Import en
complete -c zoxide -n "__fish_zoxide_needs_command" -f -a "init" -d 'Generate shell configuration'
complete -c zoxide -n "__fish_zoxide_needs_command" -f -a "query" -d 'Search for a directory in the database'
complete -c zoxide -n "__fish_zoxide_needs_command" -f -a "remove" -d 'Remove a directory from the database'
complete -c zoxide -n "__fish_zoxide_using_subcommand add" -s s -l score -d 'The rank to increment the entry if it exists or initialize it with if it doesn\'t' -r
complete -c zoxide -n "__fish_zoxide_using_subcommand add" -s h -l help -d 'Print help'
complete -c zoxide -n "__fish_zoxide_using_subcommand add" -s V -l version -d 'Print version'
complete -c zoxide -n "__fish_zoxide_using_subcommand edit; and not __fish_seen_subcommand_from decrement delete increment reload" -s h -l help -d 'Print help'

View File

@ -6,6 +6,15 @@ const completion: Fig.Spec = {
name: "add",
description: "Add a new directory or increment its rank",
options: [
{
name: ["-s", "--score"],
description: "The rank to increment the entry if it exists or initialize it with if it doesn't",
isRepeatable: true,
args: {
name: "score",
isOptional: true,
},
},
{
name: ["-h", "--help"],
description: "Print help",

View File

@ -33,7 +33,9 @@ impl Run for Add {
if !Path::new(path).is_dir() {
bail!("not a directory: {path}");
}
db.add_update(path, 1.0, now);
let by = self.score.unwrap_or(1.0);
db.add_update(path, by, now);
}
if db.dirty() {

View File

@ -58,6 +58,10 @@ pub enum Cmd {
pub struct Add {
#[clap(num_args = 1.., required = true, value_hint = ValueHint::DirPath)]
pub paths: Vec<PathBuf>,
/// The rank to increment the entry if it exists or initialize it with if it doesn't
#[clap(short, long)]
pub score: Option<f64>,
}
/// Edit the database