zimfw / git-info

Exposes git repository status information to prompts.
MIT License
6 stars 4 forks source link

Incompatibility with custom config setopt shwordsplit #3

Closed fdelavier closed 2 years ago

fdelavier commented 2 years ago

Hi,

Here is an issue noticed during my move to zimfw (from a basic zsh, without any framework), when importing my existing zsh customizations.

Describe the bug
git-info doesn't work in a git directory, when using "setopt shwordsplit" (typically used in my .zshrc)

Steps to reproduce

  1. Go in a git directory
~
% cd .zim/modules/utility

~/.zim/modules/utility on master
% 
  1. set option shwordsplit
~/.zim/modules/utility on master
% setopt shwordsplit
git-info:zformat:232: invalid argument: %%B%F{magenta}%b%c%s${(e)git_info[status]:+"

~/.zim/modules/utility
%

=> error

  1. unset option shwordsplit
    
    ~/.zim/modules/utility
    % unsetopt shwordsplit

~/.zim/modules/utility on master %

=> no issue anymore

**Current behavior**  
In step 2. we notice the error :
_git-info:zformat:232: invalid argument: %%B%F{magenta}%b%c%s${(e)git_info[status]:+"_

**Expected behavior**  
Ideally, user configurations should not affect the behavior of Zim.

**zimfw info**  

% zimfw info zimfw version: 1.10.0 (built at 2022-09-27 22:44:10 UTC, previous commit is 05b8e0c) OSTYPE: linux-gnu TERM: xterm-256color TERM_PROGRAM: TERM_PROGRAM_VERSION: ZIM_HOME: /tmp/tmp.FjTXshbGLs/.zim ZSH_VERSION: 5.8.1


**Additional context**  
Maybe this plugin (and also others) should use something like "emulate -L zsh" ?

According to man zshoptions :
   LOCAL_OPTIONS <K>
          If this option is set at the point of return from a shell  funcā€
          tion, most options (including this one) which were in force upon
          entry to the function are restored; options  that  are  not  reā€
          stored  are PRIVILEGED and RESTRICTED.  Otherwise, only this opā€
          tion, and the LOCAL_LOOPS, XTRACE and  PRINT_EXIT_VALUE  options
          are  restored.   Hence  if  this  is explicitly unset by a shell
          function the other options in force at the point of return  will
          remain  so.   A shell function can also guarantee itself a known
          shell configuration with a formulation like  `emulate  -L  zsh';
          the -L activates LOCAL_OPTIONS.


Unless there is a way to do this in zimfw/zimfw rather than in each module.

Thanks
ericbn commented 2 years ago

Hi @fdelavier. Good point. The zimfw plugin manager was already updated to use builtin emulate -L zsh, but not the modules. Will start by fixing this one. Thanks!