dotfiles/home/.config/sh/theme

83 lines
2.3 KiB
Plaintext
Raw Normal View History

#!/usr/bin/env zsh
2021-03-23 20:18:34 +00:00
# hide EOL sign ('%')
export PROMPT_EOL_MARK=""
2021-04-28 23:05:25 +00:00
# TTY (pure linux) terminal only has 8-bit color support
# (unless you change it in kernel), respect this and downgrade
# the color scheme accordingly (it won't look best, but it's
# still better than no colors)
if [ $TERM = "linux" ]; then
GREEN="%F{002}"
RED="%F{001}"
ORANGE="%F{003}"
BLUE="%F{004}"
LBLUE="%F{006}"
PURPLE="%F{005}"
else
GREEN="%F{047}"
RED="%F{196}"
ORANGE="%F{214}"
BLUE="%F{027}"
LBLUE="%F{075}"
PURPLE="%F{105}"
fi
RESET="%f"
2021-05-03 17:08:00 +00:00
# Once we are too deep in the filestructure, we can usually afford to shorten
# the whole working directory and only print something like ~/.../dir3/dir4/dir5
# instead of ~/dir1/dir2/dir3/dir4/dir5. If this isn't desired, set this to 0
USE_SHORTENED_WORKDIR=1
2021-04-20 06:29:47 +00:00
# Signals git status of CWD repository (if any)
git_prompt() {
2021-01-28 23:39:51 +00:00
ref=$(command git symbolic-ref HEAD 2> /dev/null) || ref=$(command git rev-parse --short HEAD 2> /dev/null) || return 0
2021-01-29 09:38:37 +00:00
echo -n " $ORANGE${ref#refs/heads/}"
if [ ! -z "$(git status --short)" ]; then
2021-01-28 23:39:51 +00:00
echo "$RED+"
fi
}
2021-01-28 23:39:51 +00:00
2021-04-20 06:29:47 +00:00
# Adds @chroot or @ssh
foreign_prompt() {
if [ "$(awk '$5=="/" {print $1}' </proc/1/mountinfo)" != "$(awk '$5=="/" {print $1}' </proc/$$/mountinfo)" ]; then
echo -n "@${ORANGE}chroot"
2021-05-03 17:08:00 +00:00
elif [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ]; then
2021-04-20 06:29:47 +00:00
echo -n "@${ORANGE}ssh"
fi
}
2021-05-03 17:08:00 +00:00
# Prints appropriate working directory
working_directory() {
# By default up to 5 directories will be tolerated before shortening
# After we surpass that, first directory (or ~) will be printed together with last 3
# This feature uses special symbol '…', but this isn't aviable when in TTY. Because
# of this, when we are in TTY, we fall back to longer '...'
if [ $USE_SHORTENED_WORKDIR != 1 ]; then
echo -n " $BLUE$~"
elif [ $TERM = "linux" ]; then
echo -n " $BLUE%(5~|%-1~/.../%3~|%4~)"
else
echo -n " $BLUE%(5~|%-1~/…/%3~|%4~)"
fi
}
2021-03-23 20:18:34 +00:00
setopt promptsubst # enable command substitution in prompt
# Primary Prompt
2021-04-20 06:29:47 +00:00
[ "$EUID" -eq 0 ] && PS1="$RED%n$RESET" || PS1="$GREEN%n$RESET" # user
PS1+="$(foreign_prompt)"
2021-05-03 17:08:00 +00:00
PS1+="$(working_directory)"
2021-05-03 17:10:47 +00:00
PS1+="\$(git_prompt)"
PS1+=" $PURPLE%(!.#.»)$RESET " # Final symbol (# or »)
# Next line prompt
PS2="$RED\ $RESET"
# Right side prompt (on error)
RPS1="%(?..$RED%? ↵$RESET)"
2021-04-19 08:47:00 +00:00
2021-04-20 06:29:47 +00:00