Created
March 30, 2021 05:07
-
-
Save snsinfu/880f1ee50150a970653d064735e46813 to your computer and use it in GitHub Desktop.
Rainbow zsh prompt
This file contains hidden or 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
zshrc::rainbow() { | |
local i=$1 | |
#local palette=( 197 220 82 49 33 129 ) | |
#local size=${#palette} | |
local palette= | |
set -A palette 197 220 82 49 33 129 | |
local size=${#palette} | |
# Normalize index to a non-negative value by cycling. | |
i=$((i % size + size)) | |
echo ${palette[(i - 1) % size + 1]} | |
} | |
zshrc::rainbow_path() { | |
local path_text= | |
local components= | |
local directory= | |
local color= | |
local i= | |
local decorated_path= | |
path_text=${(%)$(echo "%~")} | |
components=( ${(s:/:)path_text} ) | |
case ${path_text} in | |
/) components=( "" ) | |
;; | |
~*) components=( ${components[2,#components]} ) | |
color=$(zshrc::rainbow $((1 - phase))) | |
decorated_path="%F{${color}}~" | |
;; | |
esac | |
for ((i = 1; i <= ${#components}; i++)); do | |
directory=${components[i]} | |
color=$(zshrc::rainbow $((i - phase))) | |
decorated_path+="%F{59}/" | |
decorated_path+="%F{${color}}${directory}" | |
done | |
echo ${decorated_path} | |
} | |
PS1="%F{red}%m%F{default}:%n \$(zshrc::rainbow_path)%F{yellow}%%%F{default} " |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment