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]' \
|
'(-i --interactive)--list[List all matching directories]' \
|
||||||
'-s[Print score with results]' \
|
'-s[Print score with results]' \
|
||||||
'--score[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]' \
|
'-h[Print help]' \
|
||||||
'--help[Print help]' \
|
'--help[Print help]' \
|
||||||
'-V[Print version]' \
|
'-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('--list', '--list', [CompletionResultType]::ParameterName, 'List all matching directories')
|
||||||
[CompletionResult]::new('-s', '-s', [CompletionResultType]::ParameterName, 'Print score with results')
|
[CompletionResult]::new('-s', '-s', [CompletionResultType]::ParameterName, 'Print score with results')
|
||||||
[CompletionResult]::new('--score', '--score', [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('-h', '-h', [CompletionResultType]::ParameterName, 'Print help')
|
||||||
[CompletionResult]::new('--help', '--help', [CompletionResultType]::ParameterName, 'Print help')
|
[CompletionResult]::new('--help', '--help', [CompletionResultType]::ParameterName, 'Print help')
|
||||||
[CompletionResult]::new('-V', '-V ', [CompletionResultType]::ParameterName, 'Print version')
|
[CompletionResult]::new('-V', '-V ', [CompletionResultType]::ParameterName, 'Print version')
|
||||||
|
|
|
@ -199,7 +199,7 @@ _zoxide() {
|
||||||
return 0
|
return 0
|
||||||
;;
|
;;
|
||||||
zoxide__query)
|
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
|
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
|
||||||
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
|
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
|
||||||
return 0
|
return 0
|
||||||
|
|
|
@ -99,6 +99,8 @@ set edit:completion:arg-completer[zoxide] = {|@words|
|
||||||
cand --list 'List all matching directories'
|
cand --list 'List all matching directories'
|
||||||
cand -s 'Print score with results'
|
cand -s 'Print score with results'
|
||||||
cand --score '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 -h 'Print help'
|
||||||
cand --help 'Print help'
|
cand --help 'Print help'
|
||||||
cand -V 'Print version'
|
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 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 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 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 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 query" -s V -l version -d 'Print version'
|
||||||
complete -c zoxide -n "__fish_zoxide_using_subcommand remove" -s h -l help -d 'Print help'
|
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
|
--interactive(-i) # Use interactive selection
|
||||||
--list(-l) # List all matching directories
|
--list(-l) # List all matching directories
|
||||||
--score(-s) # Print score with results
|
--score(-s) # Print score with results
|
||||||
|
--time(-t) # Print `last_accessed` with results, no effect without `--list` option
|
||||||
--exclude: path # Exclude the current directory
|
--exclude: path # Exclude the current directory
|
||||||
--base-dir: path # Only search within this directory
|
--base-dir: path # Only search within this directory
|
||||||
--help(-h) # Print help
|
--help(-h) # Print help
|
||||||
|
|
|
@ -248,6 +248,10 @@ const completion: Fig.Spec = {
|
||||||
name: ["-s", "--score"],
|
name: ["-s", "--score"],
|
||||||
description: "Print score with results",
|
description: "Print score with results",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: ["-t", "--time"],
|
||||||
|
description: "Print `last_accessed` with results, no effect without `--list` option",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: ["-h", "--help"],
|
name: ["-h", "--help"],
|
||||||
description: "Print help",
|
description: "Print help",
|
||||||
|
|
|
@ -183,6 +183,10 @@ pub struct Query {
|
||||||
#[clap(long, short)]
|
#[clap(long, short)]
|
||||||
pub score: bool,
|
pub score: bool,
|
||||||
|
|
||||||
|
/// Print `last_accessed` with results, no effect without `--list` option
|
||||||
|
#[clap(long, short)]
|
||||||
|
pub time: bool,
|
||||||
|
|
||||||
/// Exclude the current directory
|
/// Exclude the current directory
|
||||||
#[clap(long, value_hint = ValueHint::DirPath, value_name = "path")]
|
#[clap(long, value_hint = ValueHint::DirPath, value_name = "path")]
|
||||||
pub exclude: Option<String>,
|
pub exclude: Option<String>,
|
||||||
|
|
|
@ -58,7 +58,13 @@ impl Query {
|
||||||
if Some(dir.path.as_ref()) == self.exclude.as_deref() {
|
if Some(dir.path.as_ref()) == self.exclude.as_deref() {
|
||||||
continue;
|
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")?;
|
writeln!(handle, "{dir}").pipe_exit("stdout")?;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
@ -37,11 +37,12 @@ pub struct DirDisplay<'a> {
|
||||||
dir: &'a Dir<'a>,
|
dir: &'a Dir<'a>,
|
||||||
now: Option<Epoch>,
|
now: Option<Epoch>,
|
||||||
separator: char,
|
separator: char,
|
||||||
|
show_last_accessed: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> DirDisplay<'a> {
|
impl<'a> DirDisplay<'a> {
|
||||||
fn new(dir: &'a Dir) -> Self {
|
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 {
|
pub fn with_score(mut self, now: Epoch) -> Self {
|
||||||
|
@ -49,6 +50,11 @@ impl<'a> DirDisplay<'a> {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn with_last_assessed(mut self) -> Self {
|
||||||
|
self.show_last_accessed = true;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
pub fn with_separator(mut self, separator: char) -> Self {
|
pub fn with_separator(mut self, separator: char) -> Self {
|
||||||
self.separator = separator;
|
self.separator = separator;
|
||||||
self
|
self
|
||||||
|
@ -61,6 +67,10 @@ impl Display for DirDisplay<'_> {
|
||||||
let score = self.dir.score(now).clamp(0.0, 9999.0);
|
let score = self.dir.score(now).clamp(0.0, 9999.0);
|
||||||
write!(f, "{score:>6.1}{}", self.separator)?;
|
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)
|
write!(f, "{}", self.dir.path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue