forked from Chrysostomus/manjaro-zsh-config
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dd0b5f7
commit f12dc35
Showing
1 changed file
with
107 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
# enable substitution for prompt | ||
setopt prompt_subst | ||
|
||
# Prompt (on left side) similar to default bash prompt, or redhat zsh prompt with colors | ||
#PROMPT="%(!.%{$fg[red]%}[%n@%m %1~]%{$reset_color%}# .%{$fg[green]%}[%n@%m %1~]%{$reset_color%}$ " | ||
# Maia prompt | ||
PROMPT="%B%{$fg[cyan]%}%(4~|%-1~/.../%2~|%~)%u%b >%{$fg[cyan]%}>%B%(?.%{$fg[cyan]%}.%{$fg[red]%})>%{$reset_color%}%b " # Print some system information when the shell is first started | ||
# Print a greeting message when shell is started | ||
echo $USER@$HOST $(uname -srm) $(lsb_release -rcs) | ||
## Prompt on right side: | ||
# - shows status of git when in git repository (code adapted from https://techanic.net/2012/12/30/my_git_prompt_for_zsh.html) | ||
# - shows exit status of previous command (if previous command finished with an error) | ||
# - is invisible, if neither is the case | ||
|
||
# Modify the colors and symbols in these variables as desired. | ||
GIT_PROMPT_SYMBOL="%{$fg[blue]%}±" # plus/minus - clean repo | ||
GIT_PROMPT_PREFIX="%{$fg[green]%}[%{$reset_color%}" | ||
GIT_PROMPT_SUFFIX="%{$fg[green]%}]%{$reset_color%}" | ||
GIT_PROMPT_AHEAD="%{$fg[red]%}ANUM%{$reset_color%}" # A"NUM" - ahead by "NUM" commits | ||
GIT_PROMPT_BEHIND="%{$fg[cyan]%}BNUM%{$reset_color%}" # B"NUM" - behind by "NUM" commits | ||
GIT_PROMPT_MERGING="%{$fg_bold[magenta]%}⚡︎%{$reset_color%}" # lightning bolt - merge conflict | ||
GIT_PROMPT_UNTRACKED="%{$fg_bold[red]%}●%{$reset_color%}" # red circle - untracked files | ||
GIT_PROMPT_MODIFIED="%{$fg_bold[yellow]%}●%{$reset_color%}" # yellow circle - tracked files modified | ||
GIT_PROMPT_STAGED="%{$fg_bold[green]%}●%{$reset_color%}" # green circle - staged changes present = ready for "git push" | ||
|
||
parse_git_branch() { | ||
# Show Git branch/tag, or name-rev if on detached head | ||
( git symbolic-ref -q HEAD || git name-rev --name-only --no-undefined --always HEAD ) 2> /dev/null | ||
} | ||
|
||
parse_git_state() { | ||
# Show different symbols as appropriate for various Git repository states | ||
# Compose this value via multiple conditional appends. | ||
local GIT_STATE="" | ||
local NUM_AHEAD="$(git log --oneline @{u}.. 2> /dev/null | wc -l | tr -d ' ')" | ||
if [ "$NUM_AHEAD" -gt 0 ]; then | ||
GIT_STATE=$GIT_STATE${GIT_PROMPT_AHEAD//NUM/$NUM_AHEAD} | ||
fi | ||
local NUM_BEHIND="$(git log --oneline ..@{u} 2> /dev/null | wc -l | tr -d ' ')" | ||
if [ "$NUM_BEHIND" -gt 0 ]; then | ||
GIT_STATE=$GIT_STATE${GIT_PROMPT_BEHIND//NUM/$NUM_BEHIND} | ||
fi | ||
local GIT_DIR="$(git rev-parse --git-dir 2> /dev/null)" | ||
if [ -n $GIT_DIR ] && test -r $GIT_DIR/MERGE_HEAD; then | ||
GIT_STATE=$GIT_STATE$GIT_PROMPT_MERGING | ||
fi | ||
if [[ -n $(git ls-files --other --exclude-standard 2> /dev/null) ]]; then | ||
GIT_STATE=$GIT_STATE$GIT_PROMPT_UNTRACKED | ||
fi | ||
if ! git diff --quiet 2> /dev/null; then | ||
GIT_STATE=$GIT_STATE$GIT_PROMPT_MODIFIED | ||
fi | ||
if ! git diff --cached --quiet 2> /dev/null; then | ||
GIT_STATE=$GIT_STATE$GIT_PROMPT_STAGED | ||
fi | ||
if [[ -n $GIT_STATE ]]; then | ||
echo "$GIT_PROMPT_PREFIX$GIT_STATE$GIT_PROMPT_SUFFIX" | ||
fi | ||
} | ||
|
||
git_prompt_string() { | ||
local git_where="$(parse_git_branch)" | ||
|
||
# If inside a Git repository, print its branch and state | ||
[ -n "$git_where" ] && echo "$GIT_PROMPT_SYMBOL$(parse_git_state)$GIT_PROMPT_PREFIX%{$fg[yellow]%}${git_where#(refs/heads/|tags/)}$GIT_PROMPT_SUFFIX" | ||
|
||
# If not inside the Git repo, print exit codes of last command (only if it failed) | ||
[ ! -n "$git_where" ] && echo "%{$fg[red]%} %(?..[%?])" | ||
} | ||
|
||
# Right prompt with exit status of previous command if not successful | ||
#RPROMPT="%{$fg[red]%} %(?..[%?])" | ||
# Right prompt with exit status of previous command marked with ✓ or ✗ | ||
#RPROMPT="%(?.%{$fg[green]%}✓ %{$reset_color%}.%{$fg[red]%}✗ %{$reset_color%})" | ||
|
||
# Apply different settigns for different terminals | ||
case $(basename "$(cat "/proc/$PPID/comm")") in | ||
login) | ||
RPROMPT="%{$fg[red]%} %(?..[%?])" | ||
alias x='startx ~/.xinitrc' # Type name of desired desktop after x, xinitrc is configured for it | ||
;; | ||
# 'tmux: server') | ||
# RPROMPT='$(git_prompt_string)' | ||
# ## Base16 Shell color themes. | ||
# #possible themes: 3024, apathy, ashes, atelierdune, atelierforest, atelierhearth, | ||
# #atelierseaside, bespin, brewer, chalk, codeschool, colors, default, eighties, | ||
# #embers, flat, google, grayscale, greenscreen, harmonic16, isotope, londontube, | ||
# #marrakesh, mocha, monokai, ocean, paraiso, pop (dark only), railscasts, shapesifter, | ||
# #solarized, summerfruit, tomorrow, twilight | ||
# #theme="eighties" | ||
# #Possible variants: dark and light | ||
# #shade="dark" | ||
# #BASE16_SHELL="/usr/share/zsh/scripts/base16-shell/base16-$theme.$shade.sh" | ||
# #[[ -s $BASE16_SHELL ]] && source $BASE16_SHELL | ||
# # Use autosuggestion | ||
# source /usr/share/zsh/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh | ||
# ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE=20 | ||
# ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE='fg=8' | ||
# ;; | ||
*) | ||
RPROMPT='$(git_prompt_string)' | ||
# Use autosuggestion | ||
source /usr/share/zsh/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh | ||
ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE=20 | ||
ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE='fg=8' | ||
;; | ||
esac |