-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbashrc-timestamp-visualonly.txt
More file actions
27 lines (23 loc) · 1.15 KB
/
Copy pathbashrc-timestamp-visualonly.txt
File metadata and controls
27 lines (23 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
shopt -s checkwinsize
# Function to detect the bottom of the screen
function __notbottom() {
local pos
IFS='[;' read -p $'\e[6n' -d R -a pos -rs || echo "failed with error: $? ; ${pos[*]}"
if [ -z $1 ] ; then
## add one to the 0-initiated x-pos (+ no offset), to give an error code at the bottom
CURLN=$((${pos[1]} +1 ))
else
## same but add the parameter as well, for the comparison that follows
CURLN=$((${pos[1]} +1 +$1 ))
fi
if [ "$CURLN" -ge "$LINES" ] ; then return -1 ; fi
}
# Colored multiline prompt with the time the input began
PS1='`RETURN=$?; if [ $RETURN != 0 ]; then \
printf "\e[3m\e[2m\e[31m#!%03d\e[39m\e[49m" $RETURN ; else \
printf "\e[3m\e[2m\e[39m# \e[49m" ; fi ; \
printf "\e[39m\e[12m[\D{%Y-%m-%d_%H:%M:%S}\e7\e[20C]\e[1m (\u@\h:\w)\e[22m\n\[\e[10m\e[3m\e[2m\]#\[\e[0m\] "`'
# To add when the input stopped
PROMPT_COMMAND='__notbottom && export PS0="\e8\r\e[0m\e[39m\e[2m\e[3m\e[5C\e[0m\e[20C\e[12m\e[2m\e[3m\D{,%Y-%m-%d_%H:%M:%S}\e[0m\e[2E" \
|| export PS0="\e8\e[2A\r\e[0m\e[39m\e[2m\e[3m\e[5C\e[0m\e[20C\e[12m\e[2m\e[3m\D{,%Y-%m-%d_%H:%M:%S}\e[0m\e[2E" ; \
printf "⏎%$((COLUMNS-1))s\\r\\033[K"'