rupa / z

z - jump around
Do What The F*ck You Want To Public License
16.17k stars 1.16k forks source link

Fix running in shells with `-u`/`-o nounset` option set #299

Open ntninja opened 3 years ago

rupa commented 3 years ago

interesting

1) can you tell me a bit about use case? this thing's designed to work at top-level, and i've never found much use for it in scripting. it's never occurred to me to run day-to-day shell in hardmode - so just curious if that's what you're doing, or I just don't get the use case.

2) if we support this (in not opposed - although a bit nonplussed) i'd prefer to do it by handling all the pertinent vars toward the top of the script, e.g. FOO=${FOO:-bar}. would like your thoughts on that. maybe you tried that first and didn't like it?

ntninja commented 3 years ago

can you tell me a bit about use case? this thing's designed to work at top-level, and i've never found much use for it in scripting. it's never occurred to me to run day-to-day shell in hardmode - so just curious if that's what you're doing, or I just don't get the use case.

I just like seeing error messages when mistyping variable names. Except for having submit patches to OMZ every now and then, there is nothing “hard mode” at all about this. :stuck_out_tongue:

if we support this (in not opposed - although a bit nonplussed) i'd prefer to do it by handling all the pertinent vars toward the top of the script, e.g. FOO=${FOO:-bar}. would like your thoughts on that. maybe you tried that first and didn't like it?

I tend to avoid writing it that way to reduce namespace pollution a bit, but if you prefer it that way I don't mind updating the PR accordingly.

rupa commented 3 years ago

ah fair, namespace pollution. Let me think about that a bit - I was definitely more concerned with avoiding it when I first wrote this tool, than I am now - but it's still definitely on my mind.

thanks for letting me know the details of your use case - makes sense, just never really occured to me :)

unsignedzero commented 2 years ago

Hello.

I don't know if this is worth adding onto this PR (since I found it from the same issues as above) but 213 is missing a -z flag in the conditional as well as line 217, see below. I have the same issue and opted to use +x over +set which fixes the issue as well. Hopefully this gets merged in soon.

[ -z "${_Z_NO_RESOLVE_SYMLINKS+x}" ] || _Z_RESOLVE_SYMLINKS="-P"

if type compctl >/dev/null 2>&1; then
    # zsh
    [ "-z ${_Z_NO_PROMPT_COMMAND+x}" ] || {

Changes