Closed LangLangBart closed 4 months ago
Thanks, I can confirm thatsource
does fix the issue though I don't understand why.
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
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" &
)
}
Problem
In #3736 the
alias
expansion was only tested for the old way of sourcing the*.zsh
shell files.However, when attempting to use
eval
, it doesn't disablealias expansion
, leading to the same issue as seen in #3731.Proposal
The
eval
command affects the setup established in issue #1944. However, the following syntax appears to work effectively:Alternative Solution
To resolve this, we could prepend
command
to the commands, such asawk
,cat
,sed
, etc.Other Projects
For comparison, consider how
kubectl
is set up on macOS:Pinging @romkatv for your valuable input: we're trying to understand why
eval "$(fzf --zsh)"
has issues with alias expansion, whilesource <(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.