Skip to content

Commit

Permalink
Make fish completions consistent with Bash
Browse files Browse the repository at this point in the history
  • Loading branch information
ajeetdsouza committed Dec 2, 2021
1 parent 2a2848f commit 72fd48e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 5 additions & 1 deletion src/fzf.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::io::{self, Read};
use std::mem;
use std::process::{Child, ChildStdin, Command, Stdio};

use anyhow::{bail, Context, Result};
Expand Down Expand Up @@ -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")?;
Expand Down
6 changes: 3 additions & 3 deletions templates/fish.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 72fd48e

Please sign in to comment.