mirror of
https://github.com/lloeki/dotfiles.git
synced 2025-12-06 07:24:39 +01:00
111 lines
2.4 KiB
Bash
111 lines
2.4 KiB
Bash
source "$DOTFILES_SHELL_DIR/prompt_segments"
|
|
source "$DOTFILES_BASH_DIR/prompt_segments"
|
|
source "$DOTFILES_SHELL_DIR/prompt_vcs"
|
|
|
|
prompt_host() {
|
|
local host_bg='black'
|
|
local host_fg='white'
|
|
|
|
if [[ $UID -eq 0 ]]; then
|
|
host_bg='red'
|
|
fi
|
|
|
|
if [[ -n $SSH_CLIENT ]]; then
|
|
host_fg='yellow'
|
|
fi
|
|
|
|
prompt_segment $host_bg $host_fg '\u@\h'
|
|
}
|
|
|
|
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"
|
|
}
|
|
|
|
function contains() {
|
|
[[ "$2" == *$1* ]]
|
|
}
|
|
|
|
function prompt_pwd() {
|
|
if [[ $PWD == $HOME ]]; then
|
|
echo -n "~"
|
|
else
|
|
echo -n "${PWD##*/}"
|
|
fi
|
|
}
|
|
|
|
prompt_build_simple() {
|
|
__git_ps1_vars
|
|
|
|
if [[ -n $SSH_CLIENT ]]; then
|
|
echo -n "${HOSTNAME%%.local} "
|
|
fi
|
|
|
|
if [[ -n $STY ]]; then
|
|
buffer="${buffer}screen "
|
|
fi
|
|
|
|
# add venv info
|
|
set_color -p yellow
|
|
if [[ -n "$VIRTUAL_ENV" ]]; then
|
|
echo -n "${VIRTUAL_ENV##*/} "
|
|
fi
|
|
|
|
set_color -p green
|
|
prompt_pwd
|
|
|
|
# add git prompt info
|
|
if [[ -n "$GIT_PS1_STATUS" ]]; then
|
|
set_color -p blue
|
|
echo -n " $GIT_PS1_BRANCH"
|
|
|
|
vcs_status=""
|
|
contains h "$GIT_PS1_STATUS" && vcs_status="$vcs_status""⇱"
|
|
contains t "$GIT_PS1_STATUS" && vcs_status="$vcs_status""!"
|
|
contains u "$GIT_PS1_STATUS" && vcs_status="$vcs_status""≠"
|
|
contains s "$GIT_PS1_STATUS" && vcs_status="$vcs_status""±"
|
|
contains n "$GIT_PS1_STATUS" && vcs_status="$vcs_status""∅"
|
|
set_color -p red
|
|
[[ -n "$vcs_status" ]] && echo -n " $vcs_status"
|
|
|
|
action=""
|
|
contains R "$GIT_PS1_STATUS" && action="$action rebase"
|
|
contains i "$GIT_PS1_STATUS" && action="$action-i"
|
|
contains A "$GIT_PS1_STATUS" && action="$action apply"
|
|
contains M "$GIT_PS1_STATUS" && action="$action merge"
|
|
contains B "$GIT_PS1_STATUS" && action="$action bisect"
|
|
set_color -p yellow
|
|
[[ -n "$action" ]] && echo -n "$action"
|
|
fi
|
|
|
|
set_color -p yellow
|
|
[[ -n "${IN_NIX_SHELL}" ]] && echo -n " nix"
|
|
|
|
# close prompt
|
|
set_color -p none
|
|
echo -n '> '
|
|
}
|
|
|
|
set_prompt() {
|
|
PS1="$(prompt_build_simple)"
|
|
}
|
|
|
|
# vim: ft=sh
|