mirror of
https://github.com/Llewellynvdm/zoxide.git
synced 2024-06-06 17:30:50 +00:00
Fix interactive remove
This commit is contained in:
parent
fd088b43db
commit
0a9081383d
|
@ -240,7 +240,8 @@ Add this to your configuration (usually `~/.zshrc`):
|
|||
eval "$(zoxide init zsh)"
|
||||
```
|
||||
|
||||
For completions to work, this line must be added _after_ calling `compinit`.
|
||||
For completions to work, the above line must be added _after_ `compinit` is
|
||||
called.
|
||||
|
||||
</details>
|
||||
|
||||
|
|
4
contrib/completions/_zoxide
generated
4
contrib/completions/_zoxide
generated
|
@ -79,8 +79,8 @@ _arguments "${_arguments_options[@]}" \
|
|||
;;
|
||||
(remove)
|
||||
_arguments "${_arguments_options[@]}" \
|
||||
'()*-i+[]:keywords: ' \
|
||||
'()*--interactive=[]:keywords: ' \
|
||||
'-i[Use interactive selection]' \
|
||||
'--interactive[Use interactive selection]' \
|
||||
'-h[Print help information]' \
|
||||
'--help[Print help information]' \
|
||||
'-V[Print version information]' \
|
||||
|
|
4
contrib/completions/_zoxide.ps1
generated
4
contrib/completions/_zoxide.ps1
generated
|
@ -73,8 +73,8 @@ Register-ArgumentCompleter -Native -CommandName 'zoxide' -ScriptBlock {
|
|||
break
|
||||
}
|
||||
'zoxide;remove' {
|
||||
[CompletionResult]::new('-i', 'i', [CompletionResultType]::ParameterName, 'i')
|
||||
[CompletionResult]::new('--interactive', 'interactive', [CompletionResultType]::ParameterName, 'interactive')
|
||||
[CompletionResult]::new('-i', 'i', [CompletionResultType]::ParameterName, 'Use interactive selection')
|
||||
[CompletionResult]::new('--interactive', 'interactive', [CompletionResultType]::ParameterName, 'Use interactive selection')
|
||||
[CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Print help information')
|
||||
[CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Print help information')
|
||||
[CompletionResult]::new('-V', 'V', [CompletionResultType]::ParameterName, 'Print version information')
|
||||
|
|
8
contrib/completions/zoxide.bash
generated
8
contrib/completions/zoxide.bash
generated
|
@ -126,14 +126,6 @@ _zoxide() {
|
|||
return 0
|
||||
fi
|
||||
case "${prev}" in
|
||||
--interactive)
|
||||
COMPREPLY=($(compgen -f "${cur}"))
|
||||
return 0
|
||||
;;
|
||||
-i)
|
||||
COMPREPLY=($(compgen -f "${cur}"))
|
||||
return 0
|
||||
;;
|
||||
*)
|
||||
COMPREPLY=()
|
||||
;;
|
||||
|
|
4
contrib/completions/zoxide.elv
generated
4
contrib/completions/zoxide.elv
generated
|
@ -66,8 +66,8 @@ set edit:completion:arg-completer[zoxide] = [@words]{
|
|||
cand --version 'Print version information'
|
||||
}
|
||||
&'zoxide;remove'= {
|
||||
cand -i 'i'
|
||||
cand --interactive 'interactive'
|
||||
cand -i 'Use interactive selection'
|
||||
cand --interactive 'Use interactive selection'
|
||||
cand -h 'Print help information'
|
||||
cand --help 'Print help information'
|
||||
cand -V 'Print version information'
|
||||
|
|
2
contrib/completions/zoxide.fish
generated
2
contrib/completions/zoxide.fish
generated
|
@ -23,6 +23,6 @@ complete -c zoxide -n "__fish_seen_subcommand_from query" -s l -l list -d 'List
|
|||
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 'Print help information'
|
||||
complete -c zoxide -n "__fish_seen_subcommand_from query" -s V -l version -d 'Print version information'
|
||||
complete -c zoxide -n "__fish_seen_subcommand_from remove" -s i -l interactive -r
|
||||
complete -c zoxide -n "__fish_seen_subcommand_from remove" -s i -l interactive -d 'Use interactive selection'
|
||||
complete -c zoxide -n "__fish_seen_subcommand_from remove" -s h -l help -d 'Print help information'
|
||||
complete -c zoxide -n "__fish_seen_subcommand_from remove" -s V -l version -d 'Print version information'
|
||||
|
|
5
contrib/completions/zoxide.ts
generated
5
contrib/completions/zoxide.ts
generated
|
@ -181,10 +181,7 @@ const completion: Fig.Spec = {
|
|||
options: [
|
||||
{
|
||||
name: ["-i", "--interactive"],
|
||||
args: {
|
||||
name: "interactive",
|
||||
isOptional: true,
|
||||
},
|
||||
description: "Use interactive selection",
|
||||
},
|
||||
{
|
||||
name: ["-h", "--help"],
|
||||
|
|
|
@ -123,13 +123,9 @@ pub struct Query {
|
|||
/// Remove a directory from the database
|
||||
#[derive(Debug, Parser)]
|
||||
pub struct Remove {
|
||||
// Use interactive selection
|
||||
#[clap(conflicts_with = "paths", long, short, value_name = "keywords")]
|
||||
pub interactive: Option<Vec<String>>,
|
||||
#[clap(
|
||||
conflicts_with = "interactive",
|
||||
required_unless_present = "interactive",
|
||||
value_hint = ValueHint::DirPath
|
||||
)]
|
||||
/// Use interactive selection
|
||||
#[clap(long, short)]
|
||||
pub interactive: bool,
|
||||
#[clap(value_hint = ValueHint::DirPath)]
|
||||
pub paths: Vec<String>,
|
||||
}
|
||||
|
|
|
@ -13,41 +13,39 @@ impl Run for Remove {
|
|||
let mut db = DatabaseFile::new(data_dir);
|
||||
let mut db = db.open()?;
|
||||
|
||||
match &self.interactive {
|
||||
Some(keywords) => {
|
||||
let now = util::current_time()?;
|
||||
let mut stream = db.stream(now).with_keywords(keywords);
|
||||
if self.interactive {
|
||||
let keywords = &self.paths;
|
||||
let now = util::current_time()?;
|
||||
let mut stream = db.stream(now).with_keywords(keywords);
|
||||
|
||||
let mut fzf = Fzf::new(true)?;
|
||||
let stdin = fzf.stdin();
|
||||
let mut fzf = Fzf::new(true)?;
|
||||
let stdin = fzf.stdin();
|
||||
|
||||
let selection = loop {
|
||||
let dir = match stream.next() {
|
||||
Some(dir) => dir,
|
||||
None => break fzf.select()?,
|
||||
};
|
||||
|
||||
match writeln!(stdin, "{}", dir.display_score(now)) {
|
||||
Err(e) if e.kind() == io::ErrorKind::BrokenPipe => break fzf.select()?,
|
||||
result => result.context("could not write to fzf")?,
|
||||
}
|
||||
let selection = loop {
|
||||
let dir = match stream.next() {
|
||||
Some(dir) => dir,
|
||||
None => break fzf.select()?,
|
||||
};
|
||||
|
||||
let paths = selection.lines().filter_map(|line| line.get(5..));
|
||||
for path in paths {
|
||||
if !db.remove(path) {
|
||||
bail!("path not found in database: {}", path);
|
||||
}
|
||||
match writeln!(stdin, "{}", dir.display_score(now)) {
|
||||
Err(e) if e.kind() == io::ErrorKind::BrokenPipe => break fzf.select()?,
|
||||
result => result.context("could not write to fzf")?,
|
||||
}
|
||||
};
|
||||
|
||||
let paths = selection.lines().filter_map(|line| line.get(5..));
|
||||
for path in paths {
|
||||
if !db.remove(path) {
|
||||
bail!("path not found in database: {}", path);
|
||||
}
|
||||
}
|
||||
None => {
|
||||
for path in &self.paths {
|
||||
if !db.remove(path) {
|
||||
let path_abs = util::resolve_path(path)?;
|
||||
let path_abs = util::path_to_str(&path_abs)?;
|
||||
if path_abs != path && !db.remove(path_abs) {
|
||||
bail!("path not found in database: {} ({})", path, path_abs)
|
||||
}
|
||||
} else {
|
||||
for path in &self.paths {
|
||||
if !db.remove(path) {
|
||||
let path_abs = util::resolve_path(path)?;
|
||||
let path_abs = util::path_to_str(&path_abs)?;
|
||||
if path_abs != path && !db.remove(path_abs) {
|
||||
bail!("path not found in database: {} ({})", path, path_abs)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user