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

programs.fzf.enable breaks some bash completions #303195

Closed
tmuehlbacher opened this issue Apr 10, 2024 · 6 comments · Fixed by #304608
Closed

programs.fzf.enable breaks some bash completions #303195

tmuehlbacher opened this issue Apr 10, 2024 · 6 comments · Fixed by #304608
Assignees

Comments

@tmuehlbacher
Copy link
Contributor

Describe the bug

The last fzf update in nixos-unstable breaks certain bash-completions, for example git.

Steps To Reproduce

This happens since e3812e1

programs.fzf.enable = true;
programs.git.enable = true;

Then try bash completion for git.

My /etc/bashrc looks like this

# /etc/bashrc: DO NOT EDIT -- this file has been generated automatically.

# Only execute this file once per shell.
if [ -n "$__ETC_BASHRC_SOURCED" ] || [ -n "$NOSYSBASHRC" ]; then return; fi
__ETC_BASHRC_SOURCED=1

# If the profile was not loaded in a parent process, source
# it.  But otherwise don't do it because we don't want to
# clobber overridden values of $PATH, etc.
if [ -z "$__ETC_PROFILE_DONE" ]; then
    . /etc/profile
fi

# We are not always an interactive shell.
if [ -n "$PS1" ]; then
    # Show current working directory in VTE terminals window title.
# Supports both bash and zsh, requires interactive shell.
. /nix/store/9wxzfd8rx71cpk4jdf7z2bq0qjx3ja22-vte-0.74.2/etc/profile.d/vte.sh

shopt -s globstar
shopt -s histappend

HISTCONTROL=ignoreboth
HISTFILE="$HOME/.local/state/bash_history"
HISTFILESIZE=50000
HISTSIZE=50000

eval "$(direnv hook bash)"


source /nix/store/zp81cmraynjxpc5rkb9a3djvaiml42f2-nix-index-with-db-0.1.7/etc/profile.d/command-not-found.sh

eval "$(/nix/store/psmylmimp0023yibdx1w76hf8zds0sjj-fzf-0.49.0/bin/fzf --bash)"

# Check the window size after every command.
shopt -s checkwinsize

# Disable hashing (i.e. caching) of command lookups.
set +h

# Provide a nice prompt if the terminal supports it.
if [ "$TERM" != "dumb" ] || [ -n "$INSIDE_EMACS" ]; then
  PROMPT_COLOR="1;31m"
  ((UID)) && PROMPT_COLOR="1;32m"
  if [ -n "$INSIDE_EMACS" ]; then
    # Emacs term mode doesn't support xterm title escape sequence (\e]0;)
    PS1="\n\[\033[$PROMPT_COLOR\][\u@\h:\w]\\$\[\033[0m\] "
  else
    PS1="\n\[\033[$PROMPT_COLOR\][\[\e]0;\u@\h: \w\a\]\u@\h:\w]\\$\[\033[0m\] "
  fi
  if test "$TERM" = "xterm"; then
    PS1="\[\033]2;\h:\u:\w\007\]$PS1"
  fi
fi

eval "$(/nix/store/ifzwv2xqwdnv1gz87rxkizi67py5p3vj-coreutils-9.4/bin/dircolors -b)"

# Check whether we're running a version of Bash that has support for
# programmable completion. If we do, enable all modules installed in
# the system and user profile in obsolete /etc/bash_completion.d/
# directories. Bash loads completions in all
# $XDG_DATA_DIRS/bash-completion/completions/
# on demand, so they do not need to be sourced here.
if shopt -q progcomp &>/dev/null; then
  . "/nix/store/h7rc4ajxx8lrqg1i6cr8zhvz15rd2g0y-bash-completion-2.11/etc/profile.d/bash_completion.sh"
  nullglobStatus=$(shopt -p nullglob)
  shopt -s nullglob
  for p in $NIX_PROFILES; do
    for m in "$p/etc/bash_completion.d/"*; do
      . "$m"
    done
  done
  eval "$nullglobStatus"
  unset nullglobStatus p m
fi

alias -- eza='eza --hyperlink --all --git'
alias -- ip='ip -color=auto -iec'
alias -- l='eza --long'
alias -- ll='ls -l'
alias -- ls='ls --color=tty'
alias -- open='xdg-open'
alias -- t='l --tree'
alias -- tree='eza --tree'
alias -- wget='wget --hsts-file=~/.cache/wget-hsts'

# Bind gpg-agent to this TTY if gpg commands are used.
export GPG_TTY=$(tty)


fi

# Read system-wide modifications.
if test -f /etc/bashrc.local; then
    . /etc/bashrc.local
fi

Expected behavior

The regular bash completions for git should work.

As a fix I found this old issue in fzf junegunn/fzf#72

To test this, I tried simply replacing /etc/bashrc with an edited version that
puts the fzf eval after the bash completions code (and before the alias
declarations). This fixes the issue. However, I am not sure how to solve this
cleanly in NixOS.

The bash completion code is inserted using programs.bash.promptPluginInit but
I don't know how to enforce ordering so that the fzf eval happens after the
completions.

Notify maintainers

@SebTM

Metadata

Please run nix-shell -p nix-info --run "nix-info -m" and paste the result.

[user@system:~]$ nix-shell -p nix-info --run "nix-info -m"
 - system: `"x86_64-linux"`
 - host os: `Linux 6.8.4, NixOS, 24.05 (Uakari), 24.05.20240408.4cba8b5`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.18.2`
 - nixpkgs: `/etc/nix/inputs/nixpkgs`

Add a 👍 reaction to issues you find important.

@SebTM
Copy link
Contributor

SebTM commented Apr 10, 2024

Thanks for the report, I started a PR super-seeded by #303201 fixing this issue. As what I found this issue was already there previously but as most people didn't had the full integration enabled it didn't triggered the issue.

@SebTM SebTM self-assigned this Apr 10, 2024
@devhell
Copy link
Contributor

devhell commented Apr 14, 2024

Is there any progress on this? Solution PRs seem to have been closed?

@SebTM
Copy link
Contributor

SebTM commented Apr 14, 2024

The fix already got merged and will be soon on unstable - otherwise you might cherry-pick/overlay it.

#303381 (comment)

@devhell
Copy link
Contributor

devhell commented Apr 14, 2024

The fix already got merged and will be soon on unstable - otherwise you might cherry-pick/overlay it.

#303381 (comment)

Cool, so we can close this presumably?

@tmuehlbacher
Copy link
Contributor Author

tmuehlbacher commented Apr 14, 2024

I looked at this in master and now we're basically back to how the fzf module was previously, right? So then it should still be an issue when enabling programs.fzf.fuzzyCompletion = true;.

As what I found this issue was already there previously but as most people didn't had the full integration enabled it didn't triggered the issue.

@tmuehlbacher
Copy link
Contributor Author

Alright, so now I'm just gonna try my luck with a PR. It definitely works for me and makes a difference.

tmuehlbacher added a commit to tmuehlbacher/nixpkgs that referenced this issue Apr 21, 2024
put all of fzf initialization after the bash-completions initialization
in bashrc, as the upstream project suggests in
junegunn/fzf#72

Fixes: NixOS#303195
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment