Created
January 4, 2024 23:44
-
-
Save abundis29/ba3052c0480bc479c367371b4b95e37e to your computer and use it in GitHub Desktop.
zshell
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
#!/usr/bin/env zsh | |
# | |
# Custom ZSH Prompt with JIRA Key and Git Status Icons | |
# | |
# Author: Ivan Abundis | |
# License: MIT | |
# Determine the color based on UID | |
if [[ $UID -eq 0 ]]; then | |
NCOLOR="red" | |
else | |
NCOLOR="yellow" | |
fi | |
# Function to extract JIRA key from Git branch | |
extract_jira_key() { | |
local branch_name=$(git symbolic-ref --short HEAD 2>/dev/null) | |
local jira_key="" | |
if [[ $branch_name =~ (JIITEM-[[:alnum:]]+) ]]; then | |
jira_key=$(echo "$branch_name" | grep -o 'CHANGETHIS-[[:alnum:]]*') | |
fi | |
if [[ -n $jira_key ]]; then | |
echo "$jira_key" | |
else | |
echo "$branch_name" | |
fi | |
} | |
# Function to get the Git status icon | |
get_git_status_icon() { | |
local git_status=$(git status --porcelain 2>/dev/null) | |
if [[ -n $git_status ]]; then | |
echo "✗" # Icon for dirty repository | |
else | |
echo "✓" # Icon for clean repository | |
fi | |
} | |
function node_prompt_version { | |
if which node &> /dev/null; then | |
echo "%{$fg_bold[blue]%}(%{$fg[red]%}$(node -v)%{$fg[blue]%})%{$reset_color%}" | |
fi | |
} | |
# Set the prompt and rprompt | |
PROMPT='🛸$(node_prompt_version) %{$fg[$NCOLOR]%}%F{cyan}%c%{$reset_color%} ➤ %{$reset_color%}' | |
RPROMPT='%{$fg[$NCOLOR]%}$(extract_jira_key) $(get_git_status_icon)%{$reset_color%} ' | |
# Customize Git prompt symbols | |
ZSH_THEME_GIT_PROMPT_PREFIX="git:" | |
ZSH_THEME_GIT_PROMPT_SUFFIX="" | |
ZSH_THEME_GIT_PROMPT_DIRTY="*" | |
ZSH_THEME_GIT_PROMPT_CLEAN="" | |
# Set LS_COLORS and LSCOLORS | |
export LSCOLORS="exfxcxdxbxbxbxbxbxbxbx" | |
export LS_COLORS="di=36;40:ln=35;40:so=32;40:pi=33;40:ex=31;40:bd=31;40:cd=31;40:su=31;40:sg=31;40:tw=31;40:ow=31;40:" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment