Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it worth adding Directory and Environment plugins? #10

Open
mattmc3 opened this issue Aug 29, 2022 · 3 comments
Open

Is it worth adding Directory and Environment plugins? #10

mattmc3 opened this issue Aug 29, 2022 · 3 comments

Comments

@mattmc3
Copy link
Contributor

mattmc3 commented Aug 29, 2022

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):

  • environment (sets job options, colorizes man pages)
  • directory (sets directory options and some helpful aliases)
  • terminal (sets terminal title - there's other plugins for this already)
  • spectrum (sets some color/effects helpers - seems better as a separate plugin - not core to Zsh)
  • history-substring-search (a submodule of an existing plugin: zsh-users/zsh-history-substring-search)

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
Copy link
Owner

belak commented Sep 8, 2022

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
Copy link
Contributor Author

mattmc3 commented Sep 12, 2022

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
Copy link
Contributor Author

mattmc3 commented Sep 15, 2022

^ 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants