Spaceship-prompt: declaration of dir variable in dir section causes exapansion of alias

Created on 12 Apr 2018  路  6Comments  路  Source: denysdovhan/spaceship-prompt

Issue

Running the shell with a global alias alias -g dir="dir --color auto" leads to the following error on startup:

spaceship_dir:local:3: not valid in this context: --color                       

Screenshot

image

Environment

Spaceship version: 3.2.0
Zsh version: zsh 5.1.1 (x86_64-ubuntu-linux-gnu)
Zsh framework: none
Zsh plugin manager: none
Terminal emulator: GNOME Terminal
Operating system: Linux

Relevant .zshrc

alias -g dir="dir --color auto"

autoload -U promptinit; promptinit
prompt spaceship
bug has-pr

Most helpful comment

Sorry @gurpreetatwal @nfischer, Missed the global aliasing :man_facepalming:

This also happens on newer versions of Zsh and spaceship-prompt. This is not limited to local dir, Every unassigned local variable initializations are causing problems.

As noted in Zsh aliasing doc we should quote these variables.

screenshot from 2018-04-25 12-24-49

.zshrc

alias -g venv='source ./env/bin/activate'

autoload -Uz promptinit; promptinit
prompt spaceship

All 6 comments

Modifying line 24 of sections/dir.zsh from
https://github.com/denysdovhan/spaceship-prompt/blob/dde0bafb94262be829efe8f926d3f012f9bddcf5/sections/dir.zsh#L24

to

local dir=""

seems to solve the problem.

Thank you for the report and PR @gurpreetatwal.

I'm unable to reproduce this with similar configuration.

420 dir alias unable to reproduce

Hmm, thats odd. You made it a global alias right?

Another (perhaps safer) option is:

local 'foo'

Technically, I believe there is a semantic difference between "empty value" and "no value."


Hmm, thats odd. You made it a global alias right?

Right, this will only repro with a global alias. I suspect @salmanulfarzy did not use a global alias, otherwise alias dir would have expanded to alias dir --color auto (and that command would have then failed instead of producing output).

It shouldn't matter too much in this case since the variable is assigned a value immediately after, but putting it in quotes best mimics the current behavior.

Sorry @gurpreetatwal @nfischer, Missed the global aliasing :man_facepalming:

This also happens on newer versions of Zsh and spaceship-prompt. This is not limited to local dir, Every unassigned local variable initializations are causing problems.

As noted in Zsh aliasing doc we should quote these variables.

screenshot from 2018-04-25 12-24-49

.zshrc

alias -g venv='source ./env/bin/activate'

autoload -Uz promptinit; promptinit
prompt spaceship
Was this page helpful?
0 / 5 - 0 ratings

Related issues

JounQin picture JounQin  路  3Comments

conradwt picture conradwt  路  3Comments

xhaythemx picture xhaythemx  路  3Comments

oldchevy picture oldchevy  路  3Comments

tbekaert picture tbekaert  路  3Comments