geometry-zsh / geometry

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

Move to a function override approach #226

Closed frm closed 4 years ago

frm commented 5 years ago

Currently we are using variables to override values.

Variables aren't very flexible. This is making the codebase hard to read to read and maintain.

This is a proposal commit to move to a function override based approach. If accepted, I can change other plugins to do the same.

This approach would allow users to better configure their prompts and plugins without having to fork and change the source code. It would also remove the need for variables that represent personal taste, like prompt prefixes and suffixes.

Example:

screen shot 2018-09-21 at 14 04 41

Before reload I simply uncommented the override function. Dotfiles:

geometry_prompt_path_render_override() {
  echo " \n$geometry_colorized_prompt_dir $geometry_colorized_prompt_symbol"
}

GEOMETRY_COLOR_GIT_DIRTY=9
GEOMETRY_COLOR_GIT_BRANCH=6
GEOMETRY_COLOR_EXIT_VALUE=9
GEOMETRY_COLOR_DIR=242
GEOMETRY_COLOR_PROMPT=2
GEOMETRY_SYMBOL_EXIT_VALUE="⇝"
GEOMETRY_SYMBOL_PROMPT="⇝"
GEOMETRY_PROMPT_PATH="%2~"
GEOMETRY_SYMBOL_GIT_DIRTY="●"
GEOMETRY_SYMBOL_GIT_CLEAN="●"
PROMPT_GEOMETRY_GIT_SHOW_STASHES=false
GEOMETRY_PROMPT_PLUGINS_PRIMARY=(path)
GEOMETRY_PROMPT_PLUGINS_SECONDARY=(git)
PROMPT_GEOMETRY_GIT_CONFLICTS=true

GEOMETRY_ENV="development"
source $HOME/Developer/geometry/$GEOMETRY_ENV/geometry.zsh
frm commented 5 years ago

Extended the proof of concept to git to display how easy it is to move things around differently from default geometry.

With git and path overrides:

screen shot 2018-09-21 at 14 39 26

Comparison with default geometry:

screen shot 2018-09-21 at 14 42 32

Personal config that overrides geometry:

geometry_prompt_path_render_override() {
  echo " \n$var_geometry_colorized_prompt_dir $var_geometry_colorized_prompt_symbol"
}

geometry_prompt_git_render_override() {
  local git_prompt="$(prompt_geometry_git_branch) $(prompt_geometry_git_status) $(prompt_geometry_git_symbol)${var_geometry_git_conflicts}"

  echo -e $git_prompt | sed -e 's/^[[:space:]]*//' | sed -e 's/[[:space:]]*$//'
}

GEOMETRY_COLOR_GIT_DIRTY=9
GEOMETRY_COLOR_GIT_BRANCH=6
GEOMETRY_COLOR_EXIT_VALUE=9
GEOMETRY_COLOR_DIR=242
GEOMETRY_COLOR_PROMPT=2
GEOMETRY_SYMBOL_EXIT_VALUE="⇝"
GEOMETRY_SYMBOL_PROMPT="⇝"
GEOMETRY_PROMPT_PATH="%2~"
GEOMETRY_SYMBOL_GIT_DIRTY="⑇"
GEOMETRY_SYMBOL_GIT_CLEAN="⑉"
GEOMETRY_SYMBOL_GIT_CONFLICTS_SOLVED="⑉"
GEOMETRY_SYMBOL_GIT_CONFLICTS_UNSOLVED="⑆"
PROMPT_GEOMETRY_GIT_SHOW_STASHES=false
GEOMETRY_PROMPT_PLUGINS_PRIMARY=(path)
GEOMETRY_PROMPT_PLUGINS_SECONDARY=(git)
PROMPT_GEOMETRY_GIT_CONFLICTS=true

GEOMETRY_ENV="development"
source $HOME/Developer/geometry/$GEOMETRY_ENV/geometry.zsh
jedahan commented 5 years ago

So I like the direction of this, but we are now adding even more names for people to know about/find/remember, and whether they are a variable or function.

I'd love for us to extend this idea even further to something more like MNML style.

frm commented 5 years ago

I like it. I want to achieve something like that and reduce the amount of variables and functions we need to know. Increase maintainability and extensibility. Right now there's an option for everything and it's hard to keep track of it all.

I didn't want to continue to refactor if this wasn't seen as a viable option 😄 I'll update soon.

jedahan commented 5 years ago

@fribmendes I started a test refactor with mnml as a base - https://github.com/geometry-zsh/geometry/tree/mnml take a look at that it seems promising

jedahan commented 5 years ago

@justmendes so I pushed a change to my mnml branch, that documents and exposes geometry_git_{branch,conflicts,rebase,remote,stashes,status,symbol}, and creates geometry::git_wrapper which is just the joiner for the right hand side. So this should allow some easy customization of either side prompt, while removing the three weird GEOMETRY_GIT_SHOW_{TIME,CONFLICTS,STASHES} variables. Lemme know if it breaks things!

frm commented 5 years ago

@jedahan I'd prefer to release a version for users to try out and then dedicate myself to trying this 😄 great work

jedahan commented 4 years ago

superseded by mnml branch