Last active
November 16, 2022 13:13
-
-
Save jstavanja/ed31f190338abe0d66b1fcae25660c94 to your computer and use it in GitHub Desktop.
π Jaka's prompt zsh theme (with abbreviated folder names in the prompt)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# The original theme this theme is extended from | |
# is the gallifrey.zsh-theme from oh-my-zsh. | |
# To use this theme, make a new file called jakas-prompt.zsh-theme | |
# in the directory ~/.oh-my-zsh/themes, and change the THEME variabl | |
# in your ~/.zshrc to jakas-prompt. | |
return_code="%(?..%{$fg[red]%}%? β΅%{$reset_color%})" | |
function dirprompt { | |
# Function for abbreviating folder names instead of listing | |
# the pwd output. | |
# | |
# Turns /Users/jaka/some/folder into j/s/folder for a shorter | |
# input in the terminal prompt. | |
# | |
# Takes in the current directory, | |
# gets all of the strings ending with a / character, | |
# e.g., from /Users/jaka/test it gets Users/ and jaka/. | |
# | |
# Then, it extracts the match group 1 from the matches, | |
# where it matches only the first character in each match, | |
# e.g., from /Users it gets U and from jaka/ it gets j. | |
# | |
# The match gets replaced in the output with the match group 1, | |
# meaning that each folder name gets substituted with its initial | |
# letter. | |
# | |
# Since the last folder is not matched by the regex, its | |
# full name remains in the output of the prompt. | |
# | |
# To extract only the last few folders, each regex match | |
# gets a newline character at the end of its substitution | |
# so that the tail command can then be used. | |
# | |
# After using the tail command, we join the lines using tr | |
# and remove the weird first new line using another tail. | |
# | |
# After that, we get rid of the weird output for the home directory, | |
# and replace // in e.g. //jaka to /, to get e.g. /jaka in the home directory. | |
pwd | sed -E 's/(.)([^\/]+)\//\1\/\n/g' | tail -3 | tr -d '\n' | tail | tr -s "//" "/" | |
} | |
PROMPT='$(dirprompt)~ $(git_prompt_info)%{$reset_color%}%BΒ»%b ' | |
RPS1="${return_code}" | |
ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg[yellow]%}βΉ" | |
ZSH_THEME_GIT_PROMPT_SUFFIX="βΊ %{$reset_color%}" | |
unset return_code host_color |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment