update
This commit is contained in:
parent
7a97c460d8
commit
c3c680ecca
11 changed files with 364 additions and 356 deletions
43
bashrc.d/10-prompt.bash
Normal file
43
bashrc.d/10-prompt.bash
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
# shellcheck shell=bash
|
||||
|
||||
draw_prompt_divider() {
|
||||
local timestamp prefix prefix_length line_length i
|
||||
printf -v timestamp '%(%H:%M:%S)T' -1
|
||||
prefix="$timestamp ├"
|
||||
prefix_length=${#prefix}
|
||||
line_length=$(( ${COLUMNS:-80} - prefix_length ))
|
||||
|
||||
printf '%s' "$prefix"
|
||||
for ((i = 0; i < line_length; i++)); do printf '─'; done
|
||||
echo
|
||||
}
|
||||
|
||||
_CACHED_USER_HOST="$USER@$HOSTNAME"
|
||||
_CACHED_USER_HOST_LENGTH=${#_CACHED_USER_HOST}
|
||||
|
||||
calculate_git_alignment() {
|
||||
[[ -z "$GITSTATUS_PROMPT" ]] && { GIT_ALIGNMENT_PADDING=""; return; }
|
||||
|
||||
local cleaned branch_name needed_padding
|
||||
cleaned=$(echo "$GITSTATUS_PROMPT" | sed -e 's/\x01//g' -e 's/\x02//g' -e 's/\x1b\[[0-9;]*m//g')
|
||||
branch_name="${cleaned%% *}"
|
||||
needed_padding=$((_CACHED_USER_HOST_LENGTH - ${#branch_name}))
|
||||
[[ $needed_padding -lt 8 ]] && needed_padding=8
|
||||
printf -v GIT_ALIGNMENT_PADDING '%*s' "$needed_padding" ''
|
||||
}
|
||||
|
||||
append_new_history() {
|
||||
history -a
|
||||
}
|
||||
|
||||
[ -r "$HOME/.config/bash/gitstatus-custom.sh" ] && . "$HOME/.config/bash/gitstatus-custom.sh"
|
||||
|
||||
PROMPT_COMMAND="append_new_history; draw_prompt_divider; my_gitstatus_prompt_update; calculate_git_alignment"
|
||||
|
||||
command_not_found_handle() {
|
||||
printf '\033[01;31mbash: %s: command not found\033[00m\n' "$1" >&2
|
||||
return 127
|
||||
}
|
||||
|
||||
_error_block='██████'
|
||||
PS1='\[\033[01;32m\]\u@\h\[\033[00m\] \[\033[1;34m\]\w\[\033[00m\]\n${GITSTATUS_PROMPT:+$GIT_ALIGNMENT_PADDING$GITSTATUS_PROMPT\n}$([ "$?" -eq 0 ] && echo "" || echo "\[\033[01;31m\]$_error_block\[\033[00m\] ")\$ \[\e]0;\u@\h: \w\a\]'
|
||||
Loading…
Add table
Add a link
Reference in a new issue