Created
December 5, 2020 19:35
-
-
Save ignis-sec/43fccdc6316d497e539a45e49b72420e to your computer and use it in GitHub Desktop.
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
flame='\xF0\x9F\x94\xA5' # | |
gear='\xE2\x9A\x99\xEF\xB8\x8F' | |
ignis_color='048' | |
SEGMENT_SEPARATOR=$'\ue0b0' | |
prompt_segment() { | |
local bg fg | |
[[ -n $1 ]] && bg="%K{$1}" || bg="%k" | |
[[ -n $2 ]] && fg="%F{$2}" || fg="%f" | |
if [[ $CURRENT_BG != 'NONE' && $1 != $CURRENT_BG ]]; then | |
SEGMENT+="%{$bg%F{$CURRENT_BG}%}$SEGMENT_SEPARATOR%{$fg%}" | |
else | |
SEGMENT+="%{$bg%}%{$fg%} " | |
fi | |
CURRENT_BG=$1 | |
[[ -n $3 ]] && SEGMENT+=$3 | |
} | |
prompt_segment_transparent_BG() { | |
local bg fg | |
[[ -n $1 ]] && bg="%K{$1}" || bg="%k" | |
[[ -n $2 ]] && fg="%F{$2}" || fg="%f" | |
if [[ $CURRENT_BG != 'NONE' && $1 != $CURRENT_BG ]]; then | |
SEGMENT+="%{$bg%}$SEGMENT_SEPARATOR%{$fg%}" | |
else | |
SEGMENT+="%{$bg%}%{$fg%} " | |
fi | |
CURRENT_BG=$1 | |
[[ -n $3 ]] && SEGMENT+=$3 | |
} | |
prompt_status() { | |
local -a symbols | |
if [[ $RETVAL -ne 0 ]] | |
then | |
symbols+="%{%F{red}%}" | |
else | |
symbols+=$flame | |
fi | |
[[ $UID -eq 0 ]] && symbols+="%{%F{yellow}%}" | |
if [[ $(jobs -l | wc -l) -gt 0 ]] | |
then | |
for i in {1..$NUM_JOBS} | |
symbols+="$gear" | |
fi | |
[[ -n "$symbols" ]] && SEGMENT+="$symbols" | |
} | |
prompt_date(){ | |
local -a DATE_SEGMENT | |
DATE_SEGMENT="[" | |
DATE_SEGMENT+=`date +%H:%M:%S` | |
DATE_SEGMENT+="]" | |
prompt_segment $1 $2 $DATE_SEGMENT | |
SEGMENT+=$reset_color | |
} | |
prompt_user(){ | |
local -a color | |
color=$ignis_color #`shuf -i 0-230 -n 1` | |
#SEGMENT+=%{$FG[$color]%}%n%{$reset_color%} | |
prompt_segment $1 $2 '%n' | |
} | |
prompt_hostname(){ | |
#SEGMENT+='[' | |
#SEGMENT+=%{$FG[033]%}%~%{$reset_color%} | |
#SEGMENT+=']' | |
prompt_segment $1 $2 '%M' | |
} | |
prompt_dir(){ | |
prompt_segment $1 $2 '%c' | |
} | |
prompt_tty(){ | |
prompt_segment $1 $2 '%l' | |
#prompt_segment $1 $2 '%!' | |
} | |
# Git: branch/detached head, dirty status | |
prompt_git() { | |
(( $+commands[git] )) || return | |
if [[ "$(git config --get oh-my-zsh.hide-status 2>/dev/null)" = 1 ]]; then | |
return | |
fi | |
local PL_BRANCH_CHAR | |
() { | |
local LC_ALL="" LC_CTYPE="en_US.UTF-8" | |
PL_BRANCH_CHAR=$'\ue0a0' # | |
} | |
local ref dirty mode repo_path | |
if [[ "$(git rev-parse --is-inside-work-tree 2>/dev/null)" = "true" ]]; then | |
repo_path=$(git rev-parse --git-dir 2>/dev/null) | |
dirty=$(parse_git_dirty) | |
ref=$(git symbolic-ref HEAD 2> /dev/null) || ref=" $(git rev-parse --short HEAD 2> /dev/null)" | |
if [[ -n $dirty ]]; then | |
prompt_segment yellow black | |
else | |
prompt_segment green black | |
fi | |
if [[ -e "${repo_path}/BISECT_LOG" ]]; then | |
mode=" <B>" | |
elif [[ -e "${repo_path}/MERGE_HEAD" ]]; then | |
mode=" >M<" | |
elif [[ -e "${repo_path}/rebase" || -e "${repo_path}/rebase-apply" || -e "${repo_path}/rebase-merge" || -e "${repo_path}/../.dotest" ]]; then | |
mode=" >R>" | |
fi | |
setopt promptsubst | |
autoload -Uz vcs_info | |
zstyle ':vcs_info:*' enable git | |
zstyle ':vcs_info:*' get-revision true | |
zstyle ':vcs_info:*' check-for-changes true | |
zstyle ':vcs_info:*' stagedstr '' | |
zstyle ':vcs_info:*' unstagedstr '' | |
zstyle ':vcs_info:*' formats ' %u%c' | |
zstyle ':vcs_info:*' actionformats ' %u%c' | |
vcs_info | |
SEGMENT+="${ref/refs\/heads\//$PL_BRANCH_CHAR }${vcs_info_msg_0_%% }${mode}" | |
fi | |
} | |
prompt_bzr() { | |
(( $+commands[bzr] )) || return | |
# Test if bzr repository in directory hierarchy | |
local dir="$PWD" | |
while [[ ! -d "$dir/.bzr" ]]; do | |
[[ "$dir" = "/" ]] && return | |
dir="${dir:h}" | |
done | |
local bzr_status status_mod status_all revision | |
if bzr_status=$(bzr status 2>&1); then | |
status_mod=$(echo -n "$bzr_status" | head -n1 | grep "modified" | wc -m) | |
status_all=$(echo -n "$bzr_status" | head -n1 | wc -m) | |
revision=$(bzr log -r-1 --log-format line | cut -d: -f1) | |
if [[ $status_mod -gt 0 ]] ; then | |
prompt_segment yellow black "bzr@$revision " | |
else | |
if [[ $status_all -gt 0 ]] ; then | |
prompt_segment yellow black "bzr@$revision" | |
else | |
prompt_segment green black "bzr@$revision" | |
fi | |
fi | |
fi | |
} | |
prompt_hg() { | |
(( $+commands[hg] )) || return | |
local rev st branch | |
if $(hg id >/dev/null 2>&1); then | |
if $(hg prompt >/dev/null 2>&1); then | |
if [[ $(hg prompt "{status|unknown}") = "?" ]]; then | |
# if files are not added | |
prompt_segment red white | |
st='' | |
elif [[ -n $(hg prompt "{status|modified}") ]]; then | |
# if any modification | |
prompt_segment yellow black | |
st='' | |
else | |
# if working copy is clean | |
prompt_segment green $CURRENT_FG | |
fi | |
echo -n $(hg prompt " {rev}@{branch}") $st | |
else | |
st="" | |
rev=$(hg id -n 2>/dev/null | sed 's/[^-0-9]//g') | |
branch=$(hg id -b 2>/dev/null) | |
if `hg st | grep -q "^\?"`; then | |
prompt_segment red black | |
st='' | |
elif `hg st | grep -q "^[MA]"`; then | |
prompt_segment yellow black | |
st='' | |
else | |
prompt_segment green $CURRENT_FG | |
fi | |
SEGMENT+=" $rev@$branch" $st | |
fi | |
fi | |
} | |
prompt_jobs() { | |
local -a jcount | |
if [[ $NUM_JOBS = '0' ]] | |
then | |
else if [[ $NUM_JOBS = '1' ]] | |
then | |
prompt_segment $1 $2 '%j job' | |
else | |
prompt_segment $1 $2 '%j jobs' | |
fi | |
fi | |
} | |
prompt_error(){ | |
if [[ $RETVAL -ne '0' ]] | |
then | |
prompt_segment $1 $2 "status: $RETVAL" | |
fi | |
} | |
# End the prompt, closing any open segments | |
prompt_end() { | |
if [[ -n $CURRENT_BG ]]; then | |
SEGMENT+=" %{%k%F{$CURRENT_BG}%}$SEGMENT_SEPARATOR" | |
else | |
SEGMENT+="%{%k%}" | |
fi | |
SEGMENT+="%{%f%}" | |
CURRENT_BG='' | |
} | |
buildPrompt(){ | |
RETVAL=$? | |
NUM_JOBS=`jobs -l | wc -l` | |
SEGMENT='' | |
CURRENT_BG='default' | |
if [[ $RETVAL -ne 0 ]] | |
then | |
CURRENT_BG='red' | |
SEGMENT+="%{%F{red}%}" | |
else | |
fi | |
if [[ $NUM_JOBS -ne 0 ]] | |
then | |
CURRENT_BG='cyan' | |
SEGMENT+="%{%F{cyan}%}" | |
else | |
fi | |
SEGMENT+='' | |
#color=`shuf -i 0-230 -n 1` | |
prompt_date 235 231 | |
prompt_user 059 048 | |
prompt_hostname 060 231 | |
prompt_dir 017 231 | |
prompt_tty 097 231 | |
prompt_git | |
prompt_jobs 230 black | |
prompt_error 196 231 | |
prompt_bzr | |
prompt_hg | |
prompt_end | |
prompt_status | |
if [[ $RETVAL -ne 0 ]] | |
then | |
SEGMENT+="%{%F{red}%}" | |
else | |
fi | |
if [[ $NUM_JOBS -ne 0 ]] | |
then | |
SEGMENT+="%{%F{cyan}%}" | |
else | |
fi | |
SEGMENT+=' | |
$' | |
SEGMENT+=$reset_color | |
echo -n $SEGMENT | |
} | |
PROMPT=$'$(buildPrompt) ' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment