Skip to content

Instantly share code, notes, and snippets.

@valterbarros
Last active March 11, 2022 14:02
Show Gist options
  • Select an option

  • Save valterbarros/55df836e6ea5989bc15052a253c874e4 to your computer and use it in GitHub Desktop.

Select an option

Save valterbarros/55df836e6ea5989bc15052a253c874e4 to your computer and use it in GitHub Desktop.
A oh my zsh theme that resume path string
# As that shows in the terminal: ~/../js/BR-OUROV-ITB-VERDE-SFCC <develop-ativos>
# installing
# on linux
# curl https://gist.githubusercontent.com/valterbarros/55df836e6ea5989bc15052a253c874e4/raw/9c9a73560244f3a520d6f85ad0e15c7f73cfa319/robbyrussell-custom.zsh-theme > $ZSH/themes/robbyrussell-custom.zsh-theme
# see instructions to set the theme https://github.com/ohmyzsh/ohmyzsh#selecting-a-theme
# set theme just for the current terminal instance: ZSH_THEME="robbyrussell-custom"
function return_status() {
echo "%(?..πŸ‘Ύ)"
}
function collapse_path() {
elements=(${(s[/])PWD})
size=${#elements[@]}
last_element=${elements[$size]}
last_element_color="%{$reset_color%}%{$fg_bold[cyan]%}$last_element%{$reset_color%}"
first_element=$elements[1]
before_last_element=${elements[$((size - 1))]}
is_home=$(pwd | grep $HOME)
[[ -n "$is_home" ]] && without_last_and_before_last=$((size - 3))
[[ -z "$is_home" ]] && without_last_and_before_last=$((size - 2))
# example / -> /
if [[ $PWD == "/" ]]; then
echo "%{$reset_color%}%{$fg_bold[cyan]%}/%{$reset_color%}"
exit
fi
# example /home/valter -> ~
if [[ $PWD == $HOME ]]; then
echo "%{$reset_color%}%{$fg_bold[cyan]%}~%{$reset_color%}"
exit
fi
# example: /home/valter/projects -> ~/projects
# example: /usr/eclipse -> /usr/eclipse
if [[ $without_last_and_before_last -le 0 ]]; then
echo "%{$FG[008]%}"$PWD | sed "s|$HOME|\~|g" | sed "s|$last_element|$last_element_color|g"
exit
fi
# example: /usr/eclipse/configuration -> /usr/../configuration
if [[ $without_last_and_before_last -le 1 && -z "$is_home" ]]; then
echo "%{$FG[008]%}/"$first_element"/../"$last_element_color | sed "s|$HOME|\~|g"
exit
fi
# example: /home/valter/projects/js -> ~/projects/js
if [[ $without_last_and_before_last -le 1 && -n "$is_home" ]]; then
echo "%{$FG[008]%}"$PWD | sed "s|$HOME|\~|g" | sed "s|$last_element|$last_element_color|g"
exit
fi
iterate_times=$((size - 3))
# example: /home/valter/projects/js/BR-OUROV-ITB-VERDE-SFCC -> ~/../js/BR-OUROV-ITB-VERDE-SFCC
if [[ -n "$is_home" ]]; then
final_path="~/"
iterate_times=$((size - 4))
# example: /usr/eclipse/configuration/org.eclipse.core.runtime -> /usr/../../org.eclipse.core.runtime
else
final_path="/"$elements[1]"/"
before_last_element=".."
fi
for i in {1..$iterate_times}; do
final_path+="../"
done
final_str="%{$FG[008]%}$final_path$before_last_element/$last_element_color"
echo $final_str
}
# PROMPT="%(?:%{$fg_bold[green]%}➜ :%{$fg_bold[red]%}➜ )"
PROMPT="$(return_status)"
PROMPT+='$(collapse_path)$(git_prompt_info)%{$reset_color%} '
# RPROMPT='$(return_status)'
# ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg_bold[blue]%}git:(%{$fg[red]%}"
# ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%} "
# ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[blue]%}) %{$fg[yellow]%}βœ—"
# ZSH_THEME_GIT_PROMPT_CLEAN="%{$fg[blue]%})"
# superjarin theme copied vars
ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg_bold[white]%} <%{$FG[135]%}"
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$fg[white]%}"
# Do nothing if the branch is clean (no changes).
ZSH_THEME_GIT_PROMPT_CLEAN="%{$fg_bold[white]%}>"
# Add a yellow βœ— if the branch is dirty
ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg_bold[white]%}> %{$fg[yellow]%}βœ—"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment