Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fzf not working in git bash windows 10 #2798

Closed
5 tasks
ghost opened this issue Apr 22, 2022 · 5 comments
Closed
5 tasks

fzf not working in git bash windows 10 #2798

ghost opened this issue Apr 22, 2022 · 5 comments

Comments

@ghost
Copy link

ghost commented Apr 22, 2022

  • [x ] I have read through the manual page (man fzf)
  • [ x] I have the latest version of fzf
  • [ x] I have searched through the existing issues

Info

  • OS
    • Linux
    • Mac OS X
    • [x ] Windows
    • Etc.
  • Shell
    • [ x] bash
    • zsh
    • fish

Problem / Steps to reproduce

Installation via scoop.
scoop install fzf
It's working out of box for cmd/powershell but on git bash all I can do is fzf --help
When i use fzf in git-bash it seems to start but nothing happens.

@DanSM-5
Copy link
Contributor

DanSM-5 commented May 25, 2022

I saw that behavior on the default git bash terminal. I'd suggest you to use a different terminal like windows terminal.

@sindrom91
Copy link

sindrom91 commented Jun 23, 2022

I am also experiencing this issue.

EDIT: I now realize this is a know behavior: https://github.com/junegunn/fzf/wiki/Cygwin

@ghost
Copy link
Author

ghost commented Jun 28, 2022

I found the solution, fzf not wroking on git bash
but you can use

winpty fzf

or in .bashrc file for git bash (idk if it exist or not)

alias fzf  ="winpty fzf"

@knutze
Copy link
Contributor

knutze commented Aug 28, 2022

I am working on this issue in MSYS2 + mintty environment.

winpty solves the problem when stdin is a tty, but hangs when stdin is a pipe (same as #2255).
This means that the CTRL+R and CTRL+T functions provided by key-bindings.bash are not available.

I am trying the following wrappers and so far they are working fine in my environment.

fzf_winpty=~/.fzf/bin/fzf-winpty
cat >"${fzf_winpty}" <<'EOF'
#!/usr/bin/env bash
set -eo pipefail

prefix="$(basename "${BASH_SOURCE:-$0}")-${UID:-$(id -u)}"
tmpdir=$(mktemp -dp "${TMPDIR:-/tmp}" "${prefix}.XXXXX")
trap "rm -rf -- '${tmpdir}'" EXIT

args=
[[ $# -ge 1 ]] && args=$(printf ' %q' "$@")

if [[ -t 0 ]]; then
  winpty </dev/tty >/dev/tty -- bash -c \
    "command fzf${args} >'${tmpdir}'/output"
  cat "${tmpdir}"/output
else
  cat - >"${tmpdir}"/input
  winpty </dev/tty >/dev/tty -- bash -c \
    "command fzf${args} <'${tmpdir}'/input >'${tmpdir}'/output"
  cat "${tmpdir}"/output
fi
EOF
chmod +x "${fzf_winpty}"
fzf() { "${fzf_winpty}" "$@" ; }

@Elger9 Elger9 mentioned this issue Oct 8, 2022
10 tasks
@Konfekt
Copy link
Contributor

Konfekt commented May 19, 2024

Thank you @knutze. @junegunn: Could a check such as

if [ "$TERM_PROGRAM" = "mintty" ]; then fzf() {
  OLD_SHELL_OPTS=$(set +o)
  set -eo pipefail
  # Generate a unique temporary directory based on the script name and user ID
  prefix="$(basename "${BASH_SOURCE:-$0}")-${UID:-$(id -u)}"
  tmpdir=$(mktemp -dp "${TMPDIR:-/tmp}" "${prefix}.XXXXX")
  trap "rm -rf -- '${tmpdir}'; eval \"$OLD_SHELL_OPTS\"" EXIT

  # Prepare arguments for fzf command
  args=
  [[ $# -ge 1 ]] && args=$(printf ' %q' "$@")

  # Check if standard input is a terminal
  if [[ -t 0 ]]; then
    # If it is, run fzf directly using winpty and output to a temporary file
    winpty </dev/tty >/dev/tty -- bash -c \
      "command fzf${args} >'${tmpdir}/output'"
    cat "${tmpdir}/output" else
    # If standard input is not a terminal, read from standard input to a
    # temporary file
    cat - >"${tmpdir}/input"
    # Then run fzf using winpty with input redirection
    winpty </dev/tty >/dev/tty -- bash -c \
      "command fzf${args} <'${tmpdir}/input' >'${tmpdir}/output'"
    cat "${tmpdir}/output" fi
  }
fi

not be added to the shell setup of fzf ?

Konfekt added a commit to Konfekt/fzf that referenced this issue May 19, 2024
@junegunn junegunn closed this as completed Jul 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants