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

[Q] Why does sourcing fzf-tab.zsh from a script cause syntax errors? #406

Closed
cohml opened this issue Jan 9, 2024 · 1 comment
Closed
Labels
question Further information is requested

Comments

@cohml
Copy link

cohml commented Jan 9, 2024

Describe your question
I maintain a Bash script which sets up my shell configurations, useful when working on a new server for the first time.

I recently added fzf-tab to this script, which I execute like this:

One of the things the script attempts to install is fzf-tab, as per the following excerpt:

ZSH_CUSTOM="/<redacted>/oh-my-zsh/custom"
FZF_TAB="${ZSH_CUSTOM}/plugins/fzf-tab"
if [[ ! -d "${FZF_TAB}" ]]; then
  git clone https://github.com/Aloxaf/fzf-tab "${FZF_TAB}"
  source "${FZF_TAB}/fzf-tab.zsh" && build-fzf-tab-module
fi

However, when the script gets to that block, it shows errors stemming from your module:

Cloning into '/<redacted>/oh-my-zsh/custom/plugins/fzf-tab'...
/<redacted>/oh-my-zsh/custom/plugins/fzf-tab/fzf-tab.zsh: line 2: local: can only be used in a function
/<redacted>/oh-my-zsh/custom/plugins/fzf-tab/fzf-tab.zsh: line 6: builtin: setopt: not a shell builtin
/<redacted>/oh-my-zsh/custom/plugins/fzf-tab/fzf-tab.zsh: line 24: syntax error near unexpected token `)'
/<redacted>/oh-my-zsh/custom/plugins/fzf-tab/fzf-tab.zsh: line 24: `    || ({ -ftb-zstyle -m disabled-on "files" } && [[ -n $isfile ]]); then'

Passing the -x flag into the script and rerunning generates the following slightly more informative output:

Cloning into '/<redacted>/oh-my-zsh/custom/plugins/fzf-tab'...
+ source /<redacted>/oh-my-zsh/custom/plugins/fzf-tab/fzf-tab.zsh
++ builtin local -a _ftb_opts
/<redacted>/oh-my-zsh/custom/plugins/fzf-tab/fzf-tab.zsh: line 2: local: can only be used in a function
++ [[ ! -o aliases ]]
++ [[ ! -o sh_glob ]]
++ [[ ! -o no_brace_expand ]]
++ builtin setopt no_aliases no_sh_glob brace_expand
/<redacted>/oh-my-zsh/custom/plugins/fzf-tab/fzf-tab.zsh: line 6: builtin: setopt: not a shell builtin
/<redacted>/oh-my-zsh/custom/plugins/fzf-tab/fzf-tab.zsh: line 24: syntax error near unexpected token `)'
/<redacted>/oh-my-zsh/custom/plugins/fzf-tab/fzf-tab.zsh: line 24: `    || ({ -ftb-zstyle -m disabled-on "files" } && [[ -n $isfile ]]); then'

Strangely and importantly, when I source that file interactively - so manually, not inside a script - it seems to run just fine.

Any idea what the issue might be?

For context, all code and outputs above were obtained from the master branch, commit c2b4aa5ad2532cca91f23908ac7f00efb7ff09c9.

@cohml cohml added the question Further information is requested label Jan 9, 2024
@Aloxaf
Copy link
Owner

Aloxaf commented Feb 21, 2024

fzf-tab.zsh is a zsh script. You cannot source it with bash.

@Aloxaf Aloxaf closed this as completed Feb 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants