belak / zsh-utils

A minimal, opinionated set of ZSH plugins designed to be small, simple, and focused.
MIT License
160 stars 12 forks source link

Is it worth adding Directory and Environment plugins? #10

Open mattmc3 opened 2 years ago

mattmc3 commented 2 years ago

There are a few default modules in Prezto that aren't included with zsh-utils (https://github.com/sorin-ionescu/prezto/blob/51c4ff6de4e2d1afd30e52ba19b21b1128fd1ed5/runcoms/zpreztorc#L33-L42):

Of course the goal isn't to just be a Prezto knockoff, and most of these are better off as separate plugins (terminal, spectrum, and hist-sub-search). But, the environment and directory plugins seem like they have some value. They are simple enough in functionally that they don't merit their own plugin, and their purpose is closely related to setting/configuring Zsh's behavior.

My question is - is it worth adding variations of these to zsh-utils? Were they purposely excluded?

belak commented 2 years ago

They weren't purposefully excluded, I just ended up porting the minimal amount of stuff I needed.

There's not a lot in either of those plugins, but they do seem useful. I'm more a fan of the settings in environment, but there are a few things in directory which may be useful (MULTIOS and PUSHD_SILENT come to mind). Maybe we could take the best of both and combine them in a single plugin?

mattmc3 commented 2 years ago

I'm more a fan of the settings in environment

LOL, guess I'm opposite since I noticed this because of the missing csh-style directory stack settings - setopt autopushd pushdminus pushdsilent pushdtohome; alias dh='dirs -v' - which are described in the Zsh intro docs: https://zsh.sourceforge.io/Intro/intro_6.html

CDABLE_VARS also lets you do things like cd -2/mysubdir which is kinda clever. I'm less of a fan of setopt AUTO_CD; unsetopt CLOBBER from Prezto though, just because their behavior can be jarring if the user didn't know they were set, so I'd rather let those be user settings.

Maybe we could take the best of both and combine them in a single plugin?

Awesome! A new combined environment plugin would work. I'm happy to submit a PR and see what you think. But, it's worth asking - do we want a new plugin, or are these small enough changes that adding them to utility would work? A separate plugin lets people opt-in, which makes it my preference. But plugin bloat is a real thing that's plagued other frameworks.

mattmc3 commented 2 years ago

^ PR above.

What I didn't do yet was include manpage colorizing:

if zstyle -t ':prezto:environment:termcap' color; then
  export LESS_TERMCAP_mb=$'\E[01;31m'      # Begins blinking.
  export LESS_TERMCAP_md=$'\E[01;31m'      # Begins bold.
  export LESS_TERMCAP_me=$'\E[0m'          # Ends mode.
  export LESS_TERMCAP_se=$'\E[0m'          # Ends standout-mode.
  export LESS_TERMCAP_so=$'\E[00;47;30m'   # Begins standout-mode.
  export LESS_TERMCAP_ue=$'\E[0m'          # Ends underline.
  export LESS_TERMCAP_us=$'\E[01;32m'      # Begins underline.
fi

The reason being that there are alternate (arguably better) ways to do this. The first is setting these variables in the new environment plugin, same as above. That makes them easily overridable by a user if they don't want them, and matches what Prezto did. But, an alternative would be a simple man wrapper like this:

function man {
  # start/end - md/me:bold; us/ue:underline; so/se:standout;
  # colors    - 0:black; 1:red; 2:green; 3:yellow; 4:blue; 5:magenta; 6:cyan; 7:white;
  # tput cmds - setaf:fgcolor; smul:underline; smso:standout; sgr0:clear;
  env \
    LESS_TERMCAP_md=$(tput bold; tput setaf 4) \
    LESS_TERMCAP_me=$(tput sgr0) \
    LESS_TERMCAP_us=$(tput smul; tput setaf 5) \
    LESS_TERMCAP_ue=$(tput sgr0) \
    LESS_TERMCAP_so=$(tput smso) \
    LESS_TERMCAP_se=$(tput rmso) \
    PAGER="${commands[less]:-$PAGER}" \
    command man -- "$@"
}

If we went the first route, it probably goes in the new environment plugin. If we go with a man wrapper, it might fit better with the other colorization overrides (grep, ls, etc) in utility.