From e1e2f41ecbaceac855dd48c5064dc2b7aed8b0e6 Mon Sep 17 00:00:00 2001 From: Azalea Colburn <62953415+azaleacolburn@users.noreply.github.com> Date: Sun, 30 Mar 2025 23:13:40 -0700 Subject: [PATCH] feat: add --score option (#1030) --- contrib/completions/_zoxide | 2 ++ contrib/completions/_zoxide.ps1 | 2 ++ contrib/completions/zoxide.bash | 10 +++++++++- contrib/completions/zoxide.elv | 2 ++ contrib/completions/zoxide.fish | 1 + contrib/completions/zoxide.ts | 9 +++++++++ src/cmd/add.rs | 4 +++- src/cmd/cmd.rs | 4 ++++ 8 files changed, 32 insertions(+), 2 deletions(-) diff --git a/contrib/completions/_zoxide b/contrib/completions/_zoxide index 69882b4..dbf0196 100644 --- a/contrib/completions/_zoxide +++ b/contrib/completions/_zoxide @@ -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]' \ diff --git a/contrib/completions/_zoxide.ps1 b/contrib/completions/_zoxide.ps1 index af15c66..a26adda 100644 --- a/contrib/completions/_zoxide.ps1 +++ b/contrib/completions/_zoxide.ps1 @@ -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') diff --git a/contrib/completions/zoxide.bash b/contrib/completions/zoxide.bash index 73dbd45..8c524aa 100644 --- a/contrib/completions/zoxide.bash +++ b/contrib/completions/zoxide.bash @@ -63,12 +63,20 @@ _zoxide() { return 0 ;; zoxide__add) - opts="-h -V --help --version ..." + opts="-s -h -V --score --help --version ..." 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=() ;; diff --git a/contrib/completions/zoxide.elv b/contrib/completions/zoxide.elv index 6183d37..e4cb36b 100644 --- a/contrib/completions/zoxide.elv +++ b/contrib/completions/zoxide.elv @@ -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' diff --git a/contrib/completions/zoxide.fish b/contrib/completions/zoxide.fish index 96dd86e..108508b 100644 --- a/contrib/completions/zoxide.fish +++ b/contrib/completions/zoxide.fish @@ -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' diff --git a/contrib/completions/zoxide.ts b/contrib/completions/zoxide.ts index 0200591..87003b9 100644 --- a/contrib/completions/zoxide.ts +++ b/contrib/completions/zoxide.ts @@ -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", diff --git a/src/cmd/add.rs b/src/cmd/add.rs index e7d6e0b..302ae0a 100644 --- a/src/cmd/add.rs +++ b/src/cmd/add.rs @@ -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() { diff --git a/src/cmd/cmd.rs b/src/cmd/cmd.rs index cff7e79..184a5f2 100644 --- a/src/cmd/cmd.rs +++ b/src/cmd/cmd.rs @@ -58,6 +58,10 @@ pub enum Cmd { pub struct Add { #[clap(num_args = 1.., required = true, value_hint = ValueHint::DirPath)] pub paths: Vec, + + /// The rank to increment the entry if it exists or initialize it with if it doesn't + #[clap(short, long)] + pub score: Option, } /// Edit the database