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

docs: update zsh integration instructions #3794

Merged
merged 2 commits into from
May 14, 2024

Conversation

LangLangBart
Copy link
Contributor

Problem

In #3736 the alias expansion was only tested for the old way of sourcing the *.zsh shell files.

export FZF_DEFAULT_OPTS=""
alias cat='bat --color=always --number'
source <path to file>
kill ** <TAB>

However, when attempting to use eval, it doesn't disable alias expansion, leading to the same issue as seen in #3731.

export FZF_DEFAULT_OPTS=""
alias cat='bat --color=always --number'
eval "$(fzf --zsh)"
kill ** <TAB>

Proposal

The eval command affects the setup established in issue #1944. However, the following syntax appears to work effectively:

source <(fzf --zsh)

Alternative Solution

To resolve this, we could prepend command to the commands, such as awk, cat, sed, etc.

--- a/shell/completion.zsh
+++ b/shell/completion.zsh
@@ -201,5 +201,5 @@ _fzf_feed_fifo() (
   command rm -f "$1"
   mkfifo "$1"
-  cat <&0 > "$1" &
+  command cat <&0 > "$1" &
 )

Other Projects

For comparison, consider how kubectl is set up on macOS:

source <(kubectl completion zsh)

Pinging @romkatv for your valuable input: we're trying to understand why eval "$(fzf --zsh)" has issues with alias expansion, while source <(fzf --zsh) seems to work well. Could you help us see if there are any potential problems with using the latter for sourcing the *.zsh files? Your expertise would be incredibly helpful.

@junegunn junegunn merged commit 030428b into junegunn:master May 14, 2024
5 checks passed
@junegunn
Copy link
Owner

Thanks, I can confirm thatsource does fix the issue though I don't understand why.

@romkatv
Copy link
Contributor

romkatv commented May 14, 2024

Aliases are expanded during parsing. When using eval, the whole script is parsed at once, hence aliases are expanded before anything from $script is executed. When using source, commands are parsed one at a time.

Here's a demo:

% eval '
  alias greet="echo hello"
  greet'
(eval):3: command not found: greet

% source <(print '
  alias greet="echo hello"
  greet')
hello

@LangLangBart
Copy link
Contributor Author

Thank you for the explanation.

alias cat='bat --color=always --number'
eval "$(fzf --zsh)"
whence -c _fzf_feed_fifo
_fzf_feed_fifo () {
  (
    command rm -f "$1"
    mkfifo "$1"
    bat --color=always --number <&0 > "$1" &
  )
}
alias cat='bat --color=always --number'
source <(fzf --zsh)
whence -c _fzf_feed_fifo
_fzf_feed_fifo () {
  (
    command rm -f "$1"
    mkfifo "$1"
    cat <&0 > "$1" &
  )
}

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

Successfully merging this pull request may close these issues.

None yet

3 participants