Command Line Style

I have a special need for command line customization. I'm currently using Holmans Dotfiles , and I want to tweak it to create a more readable and understandable tooltip. What I would like is described below, using the image, plz note that they are photoshopped to look like I want them;). This is also a problem with github, with inline images!

Let's say you have this file structure, as in this image:

enter image description here

At the moment, when I am, say, map3, my hint only shows:

image

I want to expand this, but with an alternative style. At the moment, the current map (map3) in which I am located is highlighted in blue. I want to see his parents, but those that do not stand out in one color. Plz see image below:

image

from what I know is that% 3 gives the last 3 dir. However, I don’t know how to stylize each clip individually.

--------------------------- another optional idea ---------------- ---- --------------------

Another idea that I had, but which has a lower value for the problem described above, is to have a relative prompt based on whether dir is a yes or no git repository. (so that dirt is always visible to the root map of the git repository

)

i.e. map0 is the root of the git repository, and I am in map3, then I would like my invitation to be like this:

image

when i am in map5 as follows:

image

Optionally, it would be nice to be able to map the rootgit map, for example:

image

at the moment my invitation is the same as in holmans dotfiles

0
source share
1 answer

Multicolor command line path

directory_name() { PROMPT_PATH="" CURRENT=`dirname ${PWD}` if [[ $CURRENT = / ]]; then PROMPT_PATH="" elif [[ $PWD = $HOME ]]; then PROMPT_PATH="" else if [[ -d $(git rev-parse --show-toplevel 2>/dev/null) ]]; then # We're in a git repo. BASE=$(basename $(git rev-parse --show-toplevel)) if [[ $PWD = $(git rev-parse --show-toplevel) ]]; then # We're in the root. PROMPT_PATH="" else # We're not in the root. Display the git repo root. GIT_ROOT="%{$fg_bold[magenta]%}${BASE}%{$reset_color%}" PATH_TO_CURRENT="${PWD#$(git rev-parse --show-toplevel)}" PATH_TO_CURRENT="${PATH_TO_CURRENT%/*}" PROMPT_PATH="${GIT_ROOT}${PATH_TO_CURRENT}/" fi else PROMPT_PATH=$(print -P %3~) PROMPT_PATH="${PROMPT_PATH%/*}/" fi fi echo "%{$fg_bold[cyan]%}${PROMPT_PATH}%{$reset_color%}%{$fg[red]%}%1~%{$reset_color%}" } 

This will show the path to the git root (git root in magenta ) if you are not at the root of git, in which case it will show the current directory in red ):

Fixed some issues.

Possible improvements:

  • This shows the root directory of git repo in magenta , if you are not at the root, in which case it is red, like any other directory in which you are located. Always staining a git root (even if it's the current directory) can be nice (can it be confusing at the moment?).

  • I show the path relative to the root of the git repository, if one exists. Another option might be to display the full path by coloring the root of the git repository, as shown below:

     ~/repositories/config-files/zshrc.d ^-------------^ White ^-----------^ Magenta ^------^ Red 
  • Submodule coloring: pay attention to the screenshot that the root of the path gets reset to the deepest git repository (therefore, when in the submodule we do not see config-files/oh-my-zsh , but only oh-my-zsh )), I'm not sure how to detect submodules, but this could be a further improvement.

Additional Information:

There is a fairly deep look [my notes] about how I did all this here . It doesn't have a last touch yet (the path between git root and PWD), but there is everything else. This can be useful if you are trying to change this and want to better understand.

+3
source

Source: https://habr.com/ru/post/1492425/


All Articles