Make fish completions consistent with Bash

This commit is contained in:
Ajeet D'Souza 2021-12-03 03:51:19 +05:30
parent 2a2848f55c
commit 72fd48ed97
3 changed files with 9 additions and 4 deletions

View File

@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
- fzf: better default options.
- fish: interactive completions are only triggered when the last argument is empty.
### Fixed

View File

@ -1,4 +1,5 @@
use std::io::{self, Read};
use std::mem;
use std::process::{Child, ChildStdin, Command, Stdio};
use anyhow::{bail, Context, Result};
@ -50,8 +51,11 @@ impl Fzf {
}
pub fn select(mut self) -> Result<String> {
// Drop stdin to prevent deadlock.
mem::drop(self.child.stdin.take());
let mut stdout = self.child.stdout.take().unwrap();
let mut output = String::new();
let stdout = self.child.stdout.as_mut().unwrap();
stdout.read_to_string(&mut output).context("failed to read from fzf")?;
let status = self.child.wait().context("wait failed on fzf")?;

View File

@ -78,10 +78,10 @@ function __zoxide_z_complete
set -l curr_tokens (commandline -cop)
if test (count $tokens) -le 2 -a (count $curr_tokens) -eq 1
# If there is only one argument, use `cd` completions.
# If there are < 2 arguments, use `cd` completions.
__fish_complete_directories "$tokens[2]" ''
else
# Otherwise, use interactive selection.
else if test (count $tokens) -eq (count $curr_tokens)
# If the last argument is empty, use interactive selection.
set -l query $tokens[2..-1]
set -l result (zoxide query -i -- $query)
and commandline -p "$tokens[1] "(string escape $result)