From 72fd48ed97385a87f45c38a845cccecc2e3c3d36 Mon Sep 17 00:00:00 2001 From: Ajeet D'Souza <98ajeet@gmail.com> Date: Fri, 3 Dec 2021 03:51:19 +0530 Subject: [PATCH] Make fish completions consistent with Bash --- CHANGELOG.md | 1 + src/fzf.rs | 6 +++++- templates/fish.txt | 6 +++--- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dab3c6ce..5dedb8a8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/fzf.rs b/src/fzf.rs index 8e21d247..205df328 100644 --- a/src/fzf.rs +++ b/src/fzf.rs @@ -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 { + // 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")?; diff --git a/templates/fish.txt b/templates/fish.txt index 4fa0506d..c670e455 100644 --- a/templates/fish.txt +++ b/templates/fish.txt @@ -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)