mirror of
https://github.com/gunchev/home_bin.git
synced 2025-11-20 12:15:46 +00:00
Use ellipsis '…' instead of 3 dots '...', …
also rearange some code and enable the COLUMNS workaround (if needed only)
This commit is contained in:
parent
9e91389b54
commit
b605c29b95
1 changed files with 5 additions and 11 deletions
|
|
@ -58,13 +58,10 @@ function prompt_command() {
|
||||||
# Save the error code, running any external command resets it!
|
# Save the error code, running any external command resets it!
|
||||||
local E=$?
|
local E=$?
|
||||||
|
|
||||||
# Date, my format
|
# Manage the history
|
||||||
my_D="$(date '+%Y-%m-%d %H:%M:%S')"
|
|
||||||
|
|
||||||
local HistFile="$HOME/bash_history/$(date '+%Y-%m/%Y-%m-%d')"
|
local HistFile="$HOME/bash_history/$(date '+%Y-%m/%Y-%m-%d')"
|
||||||
mkdir -p "${HistFile%/*}"
|
mkdir -p "${HistFile%/*}"
|
||||||
|
|
||||||
# Manage the history
|
|
||||||
if [ -z "$my_LoginTime" ]; then
|
if [ -z "$my_LoginTime" ]; then
|
||||||
my_LoginTime=$(date --rfc-3339=ns)
|
my_LoginTime=$(date --rfc-3339=ns)
|
||||||
echo -e "# Login,$USER@${HOSTNAME}:$PWD,$(tty),${SSH_CLIENT:-$(who am i | cut -d ' ' -f 1)@localhost},${my_LoginTime},${my_LoginTime}\n" >> "$HistFile"
|
echo -e "# Login,$USER@${HOSTNAME}:$PWD,$(tty),${SSH_CLIENT:-$(who am i | cut -d ' ' -f 1)@localhost},${my_LoginTime},${my_LoginTime}\n" >> "$HistFile"
|
||||||
|
|
@ -75,15 +72,15 @@ function prompt_command() {
|
||||||
echo -e "# CMD,\$?=$E,$USER@${HOSTNAME}:$PWD,$(tty),${SSH_CLIENT:-$(who am i | cut -d ' ' -f 1)@localhost},${my_LoginTime},$(date --rfc-3339=ns)\n$Cmd" >> "$HistFile"
|
echo -e "# CMD,\$?=$E,$USER@${HOSTNAME}:$PWD,$(tty),${SSH_CLIENT:-$(who am i | cut -d ' ' -f 1)@localhost},${my_LoginTime},$(date --rfc-3339=ns)\n$Cmd" >> "$HistFile"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
# Calculate the width of the prompt:
|
# Calculate the width of the prompt:
|
||||||
my_TTY="$(tty)"
|
my_TTY="$(tty)"
|
||||||
my_TTY="${my_TTY:5}" # cut the '/dev' part -> tty/1, pts/2...
|
my_TTY="${my_TTY:5}" # cut the '/dev' part -> tty/1, pts/2...
|
||||||
|
my_PWD="${PWD}"
|
||||||
# Add all the accessories below ...
|
# Add all the accessories below ...
|
||||||
|
my_D="$(date '+%Y-%m-%d %H:%M:%S')"
|
||||||
local prompt="--($my_D, Err $E, $my_TTY)---($PWD)--"
|
local prompt="--($my_D, Err $E, $my_TTY)---($PWD)--"
|
||||||
|
|
||||||
local fillsize=0
|
local fillsize=0
|
||||||
#if [ -z "${COLUMNS}" ]; then COLUMNS=$(tput cols); fi
|
[ -z "${COLUMNS}" ] && COLUMNS=$(tput cols)
|
||||||
let fillsize=${COLUMNS}-${#prompt}
|
let fillsize=${COLUMNS}-${#prompt}
|
||||||
my_FILL=""
|
my_FILL=""
|
||||||
if [ $fillsize -gt 0 ]; then
|
if [ $fillsize -gt 0 ]; then
|
||||||
|
|
@ -92,13 +89,10 @@ function prompt_command() {
|
||||||
my_FILL="${my_FILL}${my_FILL}${my_FILL}${my_FILL}"
|
my_FILL="${my_FILL}${my_FILL}${my_FILL}${my_FILL}"
|
||||||
done
|
done
|
||||||
my_FILL="${my_FILL::$fillsize}"
|
my_FILL="${my_FILL::$fillsize}"
|
||||||
let fillsize=0
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ $fillsize -lt 0 ]; then
|
if [ $fillsize -lt 0 ]; then
|
||||||
my_PWD="...${PWD:3-$fillsize}"
|
my_PWD="…${my_PWD:1-$fillsize}"
|
||||||
else
|
|
||||||
my_PWD="${PWD}"
|
|
||||||
fi
|
fi
|
||||||
# Let other PROMPT_COMMAND scripts (if any after us) have the error code too.
|
# Let other PROMPT_COMMAND scripts (if any after us) have the error code too.
|
||||||
bash -c "exit $E"
|
bash -c "exit $E"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue