From b8bb6f0f85a5c778c3d9ba08b1434024f24df20f Mon Sep 17 00:00:00 2001 From: Ajeet D'Souza <98ajeet@gmail.com> Date: Thu, 20 May 2021 02:54:06 +0530 Subject: [PATCH] Add value hints for completions (#216) --- contrib/completions/_zoxide | 8 ++++---- contrib/completions/zoxide.fish | 8 ++++---- src/app/_app.rs | 12 +++++++++--- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/contrib/completions/_zoxide b/contrib/completions/_zoxide index 81a4efd..4b49026 100644 --- a/contrib/completions/_zoxide +++ b/contrib/completions/_zoxide @@ -32,7 +32,7 @@ _zoxide() { _arguments "${_arguments_options[@]}" \ '-h[Prints help information]' \ '--help[Prints help information]' \ -':path:' \ +':path:_files -/' \ && ret=0 ;; (import) @@ -41,7 +41,7 @@ _arguments "${_arguments_options[@]}" \ '--merge[Merge into existing database]' \ '-h[Prints help information]' \ '--help[Prints help information]' \ -':path:' \ +':path:_files' \ && ret=0 ;; (init) @@ -56,7 +56,7 @@ _arguments "${_arguments_options[@]}" \ ;; (query) _arguments "${_arguments_options[@]}" \ -'--exclude=[Exclude a path from results]' \ +'--exclude=[Exclude a path from results]: :_files -/' \ '--all[Show deleted directories]' \ '(-l --list)-i[Use interactive selection]' \ '(-l --list)--interactive[Use interactive selection]' \ @@ -75,7 +75,7 @@ _arguments "${_arguments_options[@]}" \ '()*--interactive=[]' \ '-h[Prints help information]' \ '--help[Prints help information]' \ -'::path:' \ +'::path:_files -/' \ && ret=0 ;; esac diff --git a/contrib/completions/zoxide.fish b/contrib/completions/zoxide.fish index 84373f8..55a2e5e 100644 --- a/contrib/completions/zoxide.fish +++ b/contrib/completions/zoxide.fish @@ -5,9 +5,9 @@ complete -c zoxide -n "__fish_use_subcommand" -f -a "import" -d 'Import entries complete -c zoxide -n "__fish_use_subcommand" -f -a "init" -d 'Generate shell configuration' complete -c zoxide -n "__fish_use_subcommand" -f -a "query" -d 'Search for a directory in the database' complete -c zoxide -n "__fish_use_subcommand" -f -a "remove" -d 'Remove a directory from the database' -complete -c zoxide -n "__fish_seen_subcommand_from add" -r +complete -c zoxide -n "__fish_seen_subcommand_from add" -r -f -a "(__fish_complete_directories)" complete -c zoxide -n "__fish_seen_subcommand_from add" -s h -l help -d 'Prints help information' -complete -c zoxide -n "__fish_seen_subcommand_from import" -r +complete -c zoxide -n "__fish_seen_subcommand_from import" -r -F complete -c zoxide -n "__fish_seen_subcommand_from import" -l from -d 'Application to import from' -r -f -a "autojump z" complete -c zoxide -n "__fish_seen_subcommand_from import" -l merge -d 'Merge into existing database' complete -c zoxide -n "__fish_seen_subcommand_from import" -s h -l help -d 'Prints help information' @@ -17,12 +17,12 @@ complete -c zoxide -n "__fish_seen_subcommand_from init" -l hook -d 'Chooses eve complete -c zoxide -n "__fish_seen_subcommand_from init" -l no-aliases -d 'Prevents zoxide from defining any commands' complete -c zoxide -n "__fish_seen_subcommand_from init" -s h -l help -d 'Prints help information' complete -c zoxide -n "__fish_seen_subcommand_from query" -r -complete -c zoxide -n "__fish_seen_subcommand_from query" -l exclude -d 'Exclude a path from results' -r +complete -c zoxide -n "__fish_seen_subcommand_from query" -l exclude -d 'Exclude a path from results' -r -f -a "(__fish_complete_directories)" complete -c zoxide -n "__fish_seen_subcommand_from query" -l all -d 'Show deleted directories' complete -c zoxide -n "__fish_seen_subcommand_from query" -s i -l interactive -d 'Use interactive selection' complete -c zoxide -n "__fish_seen_subcommand_from query" -s l -l list -d 'List all matching directories' complete -c zoxide -n "__fish_seen_subcommand_from query" -s s -l score -d 'Print score with results' complete -c zoxide -n "__fish_seen_subcommand_from query" -s h -l help -d 'Prints help information' complete -c zoxide -n "__fish_seen_subcommand_from remove" -s i -l interactive -r -complete -c zoxide -n "__fish_seen_subcommand_from remove" -r +complete -c zoxide -n "__fish_seen_subcommand_from remove" -r -f -a "(__fish_complete_directories)" complete -c zoxide -n "__fish_seen_subcommand_from remove" -s h -l help -d 'Prints help information' diff --git a/src/app/_app.rs b/src/app/_app.rs index 64fd6ca..bf5e27a 100644 --- a/src/app/_app.rs +++ b/src/app/_app.rs @@ -1,4 +1,4 @@ -use clap::{AppSettings, ArgEnum, Clap}; +use clap::{AppSettings, ArgEnum, Clap, ValueHint}; use std::path::PathBuf; @@ -33,12 +33,14 @@ pub enum App { /// Add a new directory or increment its rank #[derive(Clap, Debug)] pub struct Add { + #[clap(value_hint = ValueHint::DirPath)] pub path: PathBuf, } /// Import entries from another application #[derive(Clap, Debug)] pub struct Import { + #[clap(value_hint = ValueHint::FilePath)] pub path: PathBuf, /// Application to import from @@ -116,7 +118,7 @@ pub struct Query { pub score: bool, /// Exclude a path from results - #[clap(long, value_name = "path")] + #[clap(long, value_hint = ValueHint::DirPath, value_name = "path")] pub exclude: Option, } @@ -126,6 +128,10 @@ pub struct Remove { // Use interactive selection #[clap(conflicts_with = "path", long, short, value_name = "keywords")] pub interactive: Option>, - #[clap(conflicts_with = "interactive", required_unless_present = "interactive")] + #[clap( + conflicts_with = "interactive", + required_unless_present = "interactive", + value_hint = ValueHint::DirPath + )] pub path: Option, }