Update the prompt
This commit is contained in:
@@ -2,7 +2,41 @@
|
||||
|
||||
# Enable colors and set prompt
|
||||
autoload -U colors && colors
|
||||
PS1="%B%{$fg[red]%}[%{$fg[yellow]%}%n%{$fg[green]%}@%{$fg[blue]%}%M %{$fg[magenta]%}%~%{$fg[red]%}]%{$reset_color%}$%b "
|
||||
setopt prompt_subst
|
||||
|
||||
function git_prompt_info() {
|
||||
local STATUS
|
||||
# Use the dotfiles git repo if in the home directory
|
||||
if [[ "$PWD" = "$HOME" ]]; then
|
||||
STATUS=$(git --git-dir "$HOME/.config/dotfiles/.git" --work-tree "$HOME" status --porcelain | tail -1)
|
||||
else
|
||||
if ! git rev-parse --git-dir &> /dev/null; then
|
||||
return 0
|
||||
fi
|
||||
STATUS=$(git status --porcelain | tail -1)
|
||||
fi
|
||||
|
||||
if [[ -n $STATUS ]]; then
|
||||
echo "%{$fg[yellow]%} %{$fg[reset_color]%}"
|
||||
fi
|
||||
}
|
||||
|
||||
function git_current_branch {
|
||||
# No need to show the branch for the home directory
|
||||
local ref
|
||||
ref=$(git symbolic-ref --quiet HEAD 2> /dev/null)
|
||||
local ret=$?
|
||||
if [[ $ret != 0 ]]; then
|
||||
[[ $ret == 128 ]] && return # no git repo
|
||||
ref=$(git rev-parse --short HEAD 2> /dev/null) || return
|
||||
fi
|
||||
echo ${ref#refs/heads/}
|
||||
}
|
||||
|
||||
# %B (%b) for bold | %c shows the top directory
|
||||
PS1='%B%(?:%{$fg[green]%} :%{$fg[red]%} )%{$fg[magenta]%}%c $(git_prompt_info)%b'
|
||||
RPS1='%{$fg[blue]%}$(git_current_branch)'
|
||||
|
||||
setopt autocd # Automatically cd into typed directory.
|
||||
stty stop undef # Disable ctrl-s to freeze terminal.
|
||||
setopt interactive_comments
|
||||
|
||||
Reference in New Issue
Block a user