mirror of
https://github.com/lloeki/dotfiles.git
synced 2025-12-06 07:24:39 +01:00
135 lines
3.1 KiB
Bash
135 lines
3.1 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
|
|
}
|
|
|
|
set_prompt() {
|
|
__git_ps1_vars
|
|
|
|
local buffer=""
|
|
|
|
local hostname=""
|
|
if [[ -n $HOST ]]; then
|
|
hostname="${HOST%.local}"
|
|
elif [[ -n $HOSTNAME ]]; then
|
|
hostname="${HOSTNAME}"
|
|
else
|
|
hostname="$(hostname -s)"
|
|
fi
|
|
|
|
if [[ -n $SSH_CLIENT ]]; then
|
|
buffer="${buffer}${hostname} "
|
|
fi
|
|
|
|
if [[ -n $STY ]]; then
|
|
buffer="${buffer}screen "
|
|
fi
|
|
|
|
if [[ -n "$VIRTUAL_ENV" ]]; then
|
|
buffer="${buffer}%F{yellow}${VIRTUAL_ENV##*/} "
|
|
fi
|
|
|
|
local pwd
|
|
if [[ $PWD == $HOME ]]; then
|
|
pwd="~"
|
|
else
|
|
pwd="${PWD##*/}"
|
|
fi
|
|
buffer="${buffer}%F{green}${pwd}"
|
|
|
|
# add git prompt info
|
|
if [[ -n "$GIT_PS1_STATUS" ]]; then
|
|
buffer="${buffer} %F{blue}$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""∅"
|
|
[[ -n "$vcs_status" ]] && buffer="${buffer} %F{red}$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"
|
|
[[ -n "$action" ]] && buffer="${buffer} %F{yellow}$action"
|
|
fi
|
|
|
|
[[ -n "${IN_NIX_SHELL}" ]] && buffer="${buffer} %F{yellow}nix"
|
|
|
|
buffer="${buffer}%f> "
|
|
PROMPT="${buffer}"
|
|
|
|
local rbuffer=""
|
|
|
|
# CMD_DURATION=${CMD_DURATION:-0}
|
|
# local duration="${CMD_DURATION%.*}"
|
|
|
|
# if [[ ${duration:-0} -gt 0 ]]; then
|
|
# printf -v formatted_duration "%.3f" "${CMD_DURATION}"
|
|
|
|
# rbuffer=" %F{yellow}${formatted_duration}s${rbuffer}"
|
|
# fi
|
|
|
|
# [[ ${CMD_RC} -ne 0 ]] && rbuffer=" %F{red}${CMD_RC}${rbuffer}"
|
|
|
|
if [[ -n "${rbuffer}" ]]; then
|
|
RPROMPT="${rbuffer}%f"
|
|
else
|
|
RPROMPT=""
|
|
fi
|
|
}
|
|
|
|
# vim: ft=bash
|