geometry-zsh / geometry

geometry is a minimal, fully customizable and composable zsh prompt theme
ISC License
921 stars 94 forks source link

An error under zsh 5.0.0: "geometry::info:local:2: not valid in this context: ..." #246

Closed psprint closed 4 years ago

psprint commented 5 years ago

The error message appearing when running under zsh-5.0.0:

geometry::info:local:2: not valid in this context: %F{blue}%(1j.\u2699
jedahan commented 5 years ago

I removed the local from that function, and quotes some things. Care to test again? Also I'm going to have to figure out how to test on different zsh versions.

jedahan commented 5 years ago

I added a Dockerfile to test zsh-5.0.0

jedahan commented 5 years ago

are you still getting this issue?

psprint commented 5 years ago

Yes :)

jedahan commented 5 years ago

I made a Dockerfile using zsh-users-5.0.0 but I get a different error

jedahan commented 5 years ago

So I'm having trouble reproducing this issue on the latest mnml branch. I made a Dockerfile that should provide a common environment to test for the issue, but I'm at a loss of how to debug.

jedahan commented 5 years ago

There was a bugfix branch from a few years ago, that changed instances of local _ctx_plugins=() to twoliners, local _ctx_plugins; _ctx_plugins=(). Should investigate those fixes as well.

jedahan commented 4 years ago

Is this still a problem?

jedahan commented 4 years ago

Running in the dockerfile, this seems to be fixed.

psprint commented 4 years ago

I've just checked, both geometry and mnml doesn't yield this error

psprint commented 4 years ago

Too early a success call – I've just got:

mnml::wrap:local:7: not valid in this context: %F{red}3%f$MNML_GIT_SEPARATOR%F{red}\u2b21%f
mnml::wrap:local:7: not valid in this context: %F{red}3%f$MNML_GIT_SEPARATOR%F{red}\u2b21%f
mnml::wrap:local:7: not valid in this context: %F{red}3%f$MNML_GIT_SEPARATOR%F{red}\u2b21%f

and it seems to come from zsh-5.7.1: mnml-error

jedahan commented 4 years ago

Can you get that error using the dockerfile? Because I tried 5.7.1 and it seems to be working...

jedahan commented 4 years ago

Also might have to do with some quoting https://github.com/zsh-users/zsh-autosuggestions/issues/127

psprint commented 4 years ago

So the local var=$( ... ) should be changed to a quoted version local var="$( ... )". I did a quick search and found a few of such cases:

 ▲ .zplugin/plugins/geometry-zsh---geometry ack local.\*'[^"]\$\('     mnml 9d :: ⬡
functions/geometry_hg.zsh
7:  local branch="$(ansi ${GEOMETRY_HG_COLOR_BRANCH:=242} $(hg branch 2> /dev/null))"
10:    && local symbol=$(ansi ${GEOMETRY_HG_COLOR_DIRTY:=red} ${GEOMETRY_HG_SYMBOL_DIRTY:="⬡"}) \
11:    || local symbol=$(ansi ${GEOMETRY_HG_COLOR_CLEAN:=green} ${GEOMETRY_HG_SYMBOL_CLEAN:="⬢"})

functions/geometry_rust_version.zsh
6:      local rust_version=$(rustc --version | \grep --color=never -oE '[0-9]+\.[0-9]+\.[0-9]')

functions/geometry_git.zsh
55:  local_commit=$(git rev-parse "@" 2>/dev/null)

functions/geometry_status.zsh
20:    local sum=0; for c in ${(s::)^HOST}; do ((sum += $(print -f '%d' "'$c"))); done
22:    local index=$(($sum % ${#colors}))

functions/geometry_npm_package_version.zsh
10:     local npm_package_version=$(\grep version package.json | \grep --color=never -oE '[0-9]+\.[0-9]+\.[0-9]')
12:    local symbol=$(ansi $GEOMETRY_NPM_PACKAGE_VERSION_SYMBOL_COLOR $GEOMETRY_NPM_PACKAGE_SYMBOL)
13:    local version=$(ansi $GEOMETRY_NPM_PACKAGE_VERSION_COLOR v$npm_package_version)

Zsh 5.0 is now 7 years old, but maybe it's worth to fix this.

jedahan commented 4 years ago

I'm not sure I can fix line 20 of geometry_status, because of the quotes in quotes. Will zsh understand sum += "$(print -f '%d' "'$c")"?

jedahan commented 4 years ago

Quoted profusely in https://github.com/geometry-zsh/geometry/commit/75b6a1bfbb5339d59bb6f3d317a1a54b195455df

psprint commented 4 years ago

Yes I think that Zsh properly understands such embedded quoting.