Add option: zoxide query -t : print last_accessed
Closes #1037 Co-authored-by: Azalea Colburn <62953415+azaleacolburn@users.noreply.github.com>
This commit is contained in:
parent
2299f2834b
commit
d37634fa76
|
@ -129,6 +129,8 @@ _arguments "${_arguments_options[@]}" : \
|
|||
'(-i --interactive)--list[List all matching directories]' \
|
||||
'-s[Print score with results]' \
|
||||
'--score[Print score with results]' \
|
||||
'-t[Print \`last_accessed\` with results, no effect without \`--list\` option]' \
|
||||
'--time[Print \`last_accessed\` with results, no effect without \`--list\` option]' \
|
||||
'-h[Print help]' \
|
||||
'--help[Print help]' \
|
||||
'-V[Print version]' \
|
||||
|
|
|
@ -111,6 +111,8 @@ Register-ArgumentCompleter -Native -CommandName 'zoxide' -ScriptBlock {
|
|||
[CompletionResult]::new('--list', '--list', [CompletionResultType]::ParameterName, 'List all matching directories')
|
||||
[CompletionResult]::new('-s', '-s', [CompletionResultType]::ParameterName, 'Print score with results')
|
||||
[CompletionResult]::new('--score', '--score', [CompletionResultType]::ParameterName, 'Print score with results')
|
||||
[CompletionResult]::new('-t', '-t', [CompletionResultType]::ParameterName, 'Print `last_accessed` with results, no effect without `--list` option')
|
||||
[CompletionResult]::new('--time', '--time', [CompletionResultType]::ParameterName, 'Print `last_accessed` with results, no effect without `--list` option')
|
||||
[CompletionResult]::new('-h', '-h', [CompletionResultType]::ParameterName, 'Print help')
|
||||
[CompletionResult]::new('--help', '--help', [CompletionResultType]::ParameterName, 'Print help')
|
||||
[CompletionResult]::new('-V', '-V ', [CompletionResultType]::ParameterName, 'Print version')
|
||||
|
|
|
@ -199,7 +199,7 @@ _zoxide() {
|
|||
return 0
|
||||
;;
|
||||
zoxide__query)
|
||||
opts="-a -i -l -s -h -V --all --interactive --list --score --exclude --base-dir --help --version [KEYWORDS]..."
|
||||
opts="-a -i -l -s -t -h -V --all --interactive --list --score --time --exclude --base-dir --help --version [KEYWORDS]..."
|
||||
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
|
||||
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
|
||||
return 0
|
||||
|
|
|
@ -99,6 +99,8 @@ set edit:completion:arg-completer[zoxide] = {|@words|
|
|||
cand --list 'List all matching directories'
|
||||
cand -s 'Print score with results'
|
||||
cand --score 'Print score with results'
|
||||
cand -t 'Print `last_accessed` with results, no effect without `--list` option'
|
||||
cand --time 'Print `last_accessed` with results, no effect without `--list` option'
|
||||
cand -h 'Print help'
|
||||
cand --help 'Print help'
|
||||
cand -V 'Print version'
|
||||
|
|
|
@ -67,6 +67,7 @@ complete -c zoxide -n "__fish_zoxide_using_subcommand query" -s a -l all -d 'Sho
|
|||
complete -c zoxide -n "__fish_zoxide_using_subcommand query" -s i -l interactive -d 'Use interactive selection'
|
||||
complete -c zoxide -n "__fish_zoxide_using_subcommand query" -s l -l list -d 'List all matching directories'
|
||||
complete -c zoxide -n "__fish_zoxide_using_subcommand query" -s s -l score -d 'Print score with results'
|
||||
complete -c zoxide -n "__fish_zoxide_using_subcommand query" -s t -l time -d 'Print `last_accessed` with results, no effect without `--list` option'
|
||||
complete -c zoxide -n "__fish_zoxide_using_subcommand query" -s h -l help -d 'Print help'
|
||||
complete -c zoxide -n "__fish_zoxide_using_subcommand query" -s V -l version -d 'Print version'
|
||||
complete -c zoxide -n "__fish_zoxide_using_subcommand remove" -s h -l help -d 'Print help'
|
||||
|
|
|
@ -81,6 +81,7 @@ module completions {
|
|||
--interactive(-i) # Use interactive selection
|
||||
--list(-l) # List all matching directories
|
||||
--score(-s) # Print score with results
|
||||
--time(-t) # Print `last_accessed` with results, no effect without `--list` option
|
||||
--exclude: path # Exclude the current directory
|
||||
--base-dir: path # Only search within this directory
|
||||
--help(-h) # Print help
|
||||
|
|
|
@ -248,6 +248,10 @@ const completion: Fig.Spec = {
|
|||
name: ["-s", "--score"],
|
||||
description: "Print score with results",
|
||||
},
|
||||
{
|
||||
name: ["-t", "--time"],
|
||||
description: "Print `last_accessed` with results, no effect without `--list` option",
|
||||
},
|
||||
{
|
||||
name: ["-h", "--help"],
|
||||
description: "Print help",
|
||||
|
|
|
@ -183,6 +183,10 @@ pub struct Query {
|
|||
#[clap(long, short)]
|
||||
pub score: bool,
|
||||
|
||||
/// Print `last_accessed` with results, no effect without `--list` option
|
||||
#[clap(long, short)]
|
||||
pub time: bool,
|
||||
|
||||
/// Exclude the current directory
|
||||
#[clap(long, value_hint = ValueHint::DirPath, value_name = "path")]
|
||||
pub exclude: Option<String>,
|
||||
|
|
|
@ -58,7 +58,13 @@ impl Query {
|
|||
if Some(dir.path.as_ref()) == self.exclude.as_deref() {
|
||||
continue;
|
||||
}
|
||||
let dir = if self.score { dir.display().with_score(now) } else { dir.display() };
|
||||
let dir = match (self.score, self.time) {
|
||||
(true, true) => dir.display().with_score(now).with_last_assessed(),
|
||||
(true, false) => dir.display().with_score(now),
|
||||
(false, true) => dir.display().with_last_assessed(),
|
||||
(false, false) => dir.display(),
|
||||
};
|
||||
|
||||
writeln!(handle, "{dir}").pipe_exit("stdout")?;
|
||||
}
|
||||
Ok(())
|
||||
|
|
|
@ -37,11 +37,12 @@ pub struct DirDisplay<'a> {
|
|||
dir: &'a Dir<'a>,
|
||||
now: Option<Epoch>,
|
||||
separator: char,
|
||||
show_last_accessed: bool,
|
||||
}
|
||||
|
||||
impl<'a> DirDisplay<'a> {
|
||||
fn new(dir: &'a Dir) -> Self {
|
||||
Self { dir, separator: ' ', now: None }
|
||||
Self { dir, separator: ' ', now: None, show_last_accessed: false }
|
||||
}
|
||||
|
||||
pub fn with_score(mut self, now: Epoch) -> Self {
|
||||
|
@ -49,6 +50,11 @@ impl<'a> DirDisplay<'a> {
|
|||
self
|
||||
}
|
||||
|
||||
pub fn with_last_assessed(mut self) -> Self {
|
||||
self.show_last_accessed = true;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_separator(mut self, separator: char) -> Self {
|
||||
self.separator = separator;
|
||||
self
|
||||
|
@ -61,6 +67,10 @@ impl Display for DirDisplay<'_> {
|
|||
let score = self.dir.score(now).clamp(0.0, 9999.0);
|
||||
write!(f, "{score:>6.1}{}", self.separator)?;
|
||||
}
|
||||
if self.show_last_accessed {
|
||||
let last_accessed = self.dir.last_accessed;
|
||||
write!(f, "{last_accessed:>6.1}{}", self.separator)?;
|
||||
}
|
||||
write!(f, "{}", self.dir.path)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue