mirror of
https://github.com/lloeki/dotfiles.git
synced 2025-12-06 07:24:39 +01:00
bash prompt with segments (on par with zsh)
This commit is contained in:
parent
edd4797006
commit
c29d55e131
7 changed files with 205 additions and 176 deletions
95
bash/prompt
95
bash/prompt
|
|
@ -1,67 +1,46 @@
|
|||
source "$DOTFILES_SHELL_DIR/prompt_segments"
|
||||
source "$DOTFILES_BASH_DIR/prompt_segments"
|
||||
source "$DOTFILES_SHELL_DIR/prompt_utils"
|
||||
source "$DOTFILES_SHELL_DIR/prompt_vcs"
|
||||
|
||||
# git prompt info
|
||||
source $DOTFILES_SHELL_DIR/git_prompt_info
|
||||
GIT_PS1_SHOWDIRTYSTATE=1
|
||||
GIT_PS1_SHOWSTASHSTATE=1
|
||||
GIT_PS1_SHOWUNTRACKEDFILES=1
|
||||
prompt_host() {
|
||||
local bg='black'
|
||||
local fg='white'
|
||||
|
||||
# dynamic prompt
|
||||
set_prompt() {
|
||||
# save last command exit code (requires set_prompt to be first in PROMPT_COMMAND)
|
||||
local last_exit_code="$?"
|
||||
|
||||
# load color vars
|
||||
source "$DOTFILES_BASH_DIR/ansi_colors"
|
||||
|
||||
# set up git status env vars
|
||||
__git_ps1_vars
|
||||
|
||||
# build prompt
|
||||
PS1=""
|
||||
|
||||
# opening + user@host
|
||||
PS1+="${B}[${UC}\u@\h"
|
||||
|
||||
# git?
|
||||
if [[ -n "${GIT_PS1_NAME-}" ]]; then
|
||||
# basic info
|
||||
PS1+=" ${Y}${GIT_PS1_NAME}"
|
||||
[[ "$GIT_PS1_STATUS" == *b* ]] && PS1+="${NONE}›"
|
||||
PS1+="${NONE}›${B}${GIT_PS1_BRANCH}"
|
||||
[[ "$GIT_PS1_STATUS" == *g* ]] && PS1+="${NONE}›"
|
||||
PS1+="${NONE}›${G}${GIT_PS1_PREFIX}"
|
||||
|
||||
# status symbols
|
||||
local status=""
|
||||
[[ "$GIT_PS1_STATUS" == *h* ]] && status+="${NONE}↰"
|
||||
[[ "$GIT_PS1_STATUS" == *t* ]] && status+="${R}!"
|
||||
[[ "$GIT_PS1_STATUS" == *u* ]] && status+="${Y}≠"
|
||||
[[ "$GIT_PS1_STATUS" == *s* ]] && status+="${R}±"
|
||||
[[ "$GIT_PS1_STATUS" == *n* ]] && status+="${BB}∅"
|
||||
[[ -n "$status" ]] && PS1+=" ${status}"
|
||||
|
||||
# action info
|
||||
local action=""
|
||||
[[ "$GIT_PS1_STATUS" == *R* ]] && action+=" rebase"
|
||||
[[ "$GIT_PS1_STATUS" == *i* ]] && action+="-i"
|
||||
[[ "$GIT_PS1_STATUS" == *A* ]] && action+=" apply"
|
||||
[[ "$GIT_PS1_STATUS" == *M* ]] && action+=" merge"
|
||||
[[ "$GIT_PS1_STATUS" == *B* ]] && action+=" bisect"
|
||||
[[ -n "$action" ]] && PS1+="${R}${action}"
|
||||
else
|
||||
# no git => just a smartly truncated path
|
||||
PS1+=" ${G}$(__tpwd)"
|
||||
if [[ $UID -eq 0 ]]; then
|
||||
bg='red'
|
||||
fi
|
||||
|
||||
# exit code
|
||||
[[ $LAST_CMD_RC -ne 0 ]] && PS1+=" ${BW}${LAST_CMD_RC}"
|
||||
if [[ -n $SSH_CLIENT ]]; then
|
||||
fg='yellow'
|
||||
fi
|
||||
|
||||
# closing prompt
|
||||
PS1+="${B}]"
|
||||
PS1+="${UC}\\$ ${NONE}"
|
||||
prompt_segment $bg $fg '\u@\h'
|
||||
}
|
||||
|
||||
# vim: ft=sh
|
||||
prompt_dir() {
|
||||
prompt_segment green white '\w'
|
||||
}
|
||||
|
||||
prompt_build() {
|
||||
prompt_setup_segments
|
||||
CURRENT_BG='NONE'
|
||||
prompt_host
|
||||
if prompt_vcs_repo; then
|
||||
prompt_vcs_status
|
||||
prompt_vcs_action
|
||||
else
|
||||
prompt_dir
|
||||
fi
|
||||
prompt_last_rc
|
||||
prompt_end
|
||||
echo -n ' '
|
||||
}
|
||||
|
||||
prompt_last_rc() {
|
||||
[[ $LAST_CMD_RC -ne 0 ]] && prompt_segment red white "$LAST_CMD_RC"
|
||||
}
|
||||
|
||||
set_prompt() {
|
||||
__git_ps1_vars
|
||||
PS1="$(prompt_build)"
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue