thoughtbot / dotfiles

A set of vim, zsh, git, and tmux configuration files.
https://thoughtbot.com
Other
7.92k stars 1.87k forks source link

zsh function .zwc parse errors #742

Open bengolder opened 2 months ago

bengolder commented 2 months ago

After installing, I get errors every time I open a new iTerm window:

/Users/bengolder/.zsh/functions/_git_delete_branch.zwc:1: parse error near `)'
/Users/bengolder/.zsh/functions/change-extension.zwc:1: no such file or directory: ^G^F^E^D^A^H^A
/Users/bengolder/.zsh/functions/envup.zwc:1: no such file or directory: ^G^F^E^D^Ax^A
[3] 75334
/Users/bengolder/.zsh/functions/g.zwc:1: no such file or directory: ^G^F^E^D^A
[4] 75335
/Users/bengolder/.zsh/functions/g.zwc:1: no such file or directory:
[4]  + exit 127    ��
[3]  + exit 127    �A
/Users/bengolder/.zsh/functions/g.zwc:1: command not found: A
/Users/bengolder/.zsh/functions/mcd.zwc:1: no such file or directory: ^G^F^E^D^A\M-T
Wed Apr 24 10:42 AM ~ %

It's clear that these are occurring when the zshrc file runs this loop to source all the files in .zsh/functions:

# load custom executable functions
for function in ~/.zsh/functions/*; do
  source $function
done

If I delete the ~/.zsh directory and rerun rcup, the errors are absent until new .zwc files are autogenerated for each file in ~/.zsh/functions:

Wed Apr 24 10:49 AM functions % pwd
/Users/bengolder/.zsh/functions
Wed Apr 24 10:49 AM functions % ls -la
total 40
drwxr-xr-x  12 bengolder  staff  384 Apr 24 10:47 .
drwxr-xr-x   5 bengolder  staff  160 Apr 24 10:46 ..
lrwxr-xr-x   1 bengolder  staff   58 Apr 24 10:46 _git_delete_branch -> /Users/bengolder/dotfiles/zsh/functions/_git_delete_branch
-rw-r-----   1 bengolder  staff  480 Apr 24 10:47 _git_delete_branch.zwc
lrwxr-xr-x   1 bengolder  staff   56 Apr 24 10:46 change-extension -> /Users/bengolder/dotfiles/zsh/functions/change-extension
-rw-r-----   1 bengolder  staff  528 Apr 24 10:47 change-extension.zwc
lrwxr-xr-x   1 bengolder  staff   45 Apr 24 10:46 envup -> /Users/bengolder/dotfiles/zsh/functions/envup
-rw-r-----   1 bengolder  staff  752 Apr 24 10:47 envup.zwc
lrwxr-xr-x   1 bengolder  staff   41 Apr 24 10:46 g -> /Users/bengolder/dotfiles/zsh/functions/g
-rw-r-----   1 bengolder  staff  512 Apr 24 10:47 g.zwc
lrwxr-xr-x   1 bengolder  staff   43 Apr 24 10:46 mcd -> /Users/bengolder/dotfiles/zsh/functions/mcd
-rw-r-----   1 bengolder  staff  424 Apr 24 10:47 mcd.zwc

System details:

Any questions or debugging suggestions welcome!

mikegee commented 2 months ago

I googled the zwc file extension because those look like they shouldn't be there.

https://www.reddit.com/r/zsh/comments/k1yaa1/help_me_understand_errors_in_zwc_files/

Apparently zsh can compile scripts into zwc files. News to me. Sourcing those files breaks things. I wonder why you have those zwc files in there. 🤔

Here's a previous PR in this repo to skip zwc files in another context: https://github.com/thoughtbot/dotfiles/pull/526 Perhaps we should bring the same technique to sourcing the functions directory?

bengolder commented 2 months ago

I don't know what is creating the .zwc files. They seem to be autogenerated after the first time the functions are accessed in zsh. I've taken no intentional steps to compile them, and I assumed they were just part of a default zsh or dotfiles setup. 🤔

It seems that .zwc files are skipped throughout load_settings, so I can add a PR to do that for these additional function files.