several internal improvements:

- add trap_add function by Richard Hansen
- make colorshell a trap instead of embedding it into PROMPT_COMMAND
- make history-sync a trap instead of embedding it into PROMPT_COMMAND
- add . /usr/share/bash-com as printable version (truncated or filled to 25 characters)
- don't log . /usr/share/bash-completion/bash_completion if it's a trap or a 'echo . /usr/share/bash-completion/bash_completion'/'echo 0'
- minor fixups to Equinox prompt
- set minimum terminal height for drawing 'arms' in Equinox to 16
parent f4337aee
......@@ -31,16 +31,40 @@ Overview of changes in v9.1 "Dial T for TNT"
* major restructuring and updating of widgets in all categories
* minor string changes
=== General ===
* add trap_add function. It allows adding multiple commands to a trap one after
another by grabbing the previous trapped functions and re-building the trap
(by Richard Hansen https://stackoverflow.com/a/7287873)
* record executed command and it's exist status. This will be available using
${lastcommand} (full length), ${lastcommandprintable} (truncated to max. 25
characters or filled with spaces to reach 25 characters, for prompts) and
${lastexit} variables. This is not recorded for:
- completion
- trap
- PROMPT_COMMAND
for not overriding the useful info with useless, aswell as for:
- echo ${lastcommand}
- echo ${lastexit}
so users are able to grab the values in all cases.
* make colorshell a trap rather than embedding it in PROMPT_COMMAND
=== Styles ===
* Renamed "Clock Advanced" Prompt to "Equinox" (the name change is handled
internally, the config updated automatically, no user interaction required)
* re-bind RETURN to C-l\C-j when Equinox is the active style. The Style is now
properly re-drawn after command execution (no more overlapping "arms")
* record executed command and it's exist status in Equinox and display as:
* include ${lastexit} and ${lastcommand} as follows in Equinox:
( ✔: some command )─┤ -- for a successfully executed command
( ✘: some command )─┤ -- for a non-successfully executed command
* simplify Equinox code a little bit
* don't draw arms in Equinox if the terminal height is less than 16 lines
=== Bash Settings ===
......
......@@ -150,49 +150,34 @@ fi
dbg_log source ${BSNG_RC_DIR}/settings/options-rc
[[ ! ${PROMPT_COMMAND} ]] && USE_PROMPT_COMMAND=True
# by Richard Hansen https://stackoverflow.com/a/7287873
log () { printf '%s\n' "$*"; }
error () { log "ERROR: $*" >&2; }
fatal () { error "$@"; exit 1; }
trap_add () {
trap_add_cmd=$1; shift || fatal "${FUNCNAME} usage error"
for trap_add_name in "$@"; do
trap -- "$(
extract_trap_cmd() { printf '%s\n' "$3"; }
eval "extract_trap_cmd $(trap -p "${trap_add_name}")"
printf '%s\n' "${trap_add_cmd}"
)" "${trap_add_name}" \
|| fatal "unable to add to trap ${trap_add_name}"
done
}
declare -f -t trap_add
# do trapping stuff
if [[ $(ini_get colorshell) && ${enable_colors} == True ]]; then
USE_COLORSHELL=True
trap_add '_colorshell' DEBUG
fi
if [[ $(ini_get history_sync) == True && ${USE_COLORSHELL} == True ]]; then
if [[ ${USE_PROMPT_COMMAND} ]]; then
PROMPT_COMMAND () {
_colorshell
_sync_history
}
else
PRE_PROMPT_COMMAND () {
_colorshell
_sync_history
}
fi
history () {
_sync_history
builtin history
}
elif [[ ${USE_COLORSHELL} == True ]]; then
if [[ ${USE_PROMPT_COMMAND} ]]; then
PROMPT_COMMAND () {
_colorshell
}
else
PRE_PROMPT_COMMAND () {
_colorshell
}
fi
elif [[ $(ini_get history_sync) == True ]]; then
if [[ ${USE_PROMPT_COMMAND} ]]; then
PROMPT_COMMAND () {
_sync_history
}
else
PRE_PROMPT_COMMAND () {
_sync_history
}
fi
if [[ $(ini_get history_sync) == True ]]; then
trap_add '_synchistory' DEBUG
history () {
_sync_history
......@@ -200,6 +185,29 @@ elif [[ $(ini_get history_sync) == True ]]; then
}
fi
# remember last exit status and command
remember_command () {
[ -n "$COMP_LINE" ] && return
[ "$BASH_COMMAND" = "$PROMPT_COMMAND" ] && return
[ "$BASH_COMMAND" = "trap *" ] && return
[[ "$BASH_COMMAND" == *lastcommand* ]] && return
[[ "$BASH_COMMAND" == *lastexit* ]] && return
lastcommand=${BASH_COMMAND}
lastcommandprintable=${BASH_COMMAND}
if [ ${#lastcommandprintable} -gt 21 ]; then
lastcommandprintable=${lastcommandprintable:0:21}
elif [ ${#lastcommandprintable} -lt 21 ]; then
x=$((21-${#lastcommandprintable}))
while [ ${x} -gt 0 ]; do
lastcommandprintable="${lastcommandprintable} "
x=$((${x}-1))
done
fi
lastexit=$?
}
trap_add 'remember_command' DEBUG
WelcomeMessage=$(ini_get welcome_message)
if [[ ${USER_BIRTHDAY} == $(date +%m-%d) && ! -e ~/.bday ]]; then
......
......@@ -34,7 +34,7 @@ else
export TMOUT=$(ini_get timeout)
fi
_sync_history() {
_synchistory () {
builtin history -a
builtin history -c
builtin history -r
......@@ -86,7 +86,7 @@ dbg_msg $"BashStyle-NG Setting:" $"GLOBIGNORE" "$GLOBIGNORE"
colorshell_revert=$(ini_get colorshell_revert)
_colorshell() {
_colorshell () {
cmd_text_colour='\[`tput setaf $((RANDOM%7))`\]'
shopt -s promptvars
......
......@@ -22,25 +22,6 @@ n=12
# make the prompt properly re-draw when pressing [Return]
bind 'RETURN: "\C-l\C-j"'
# remember last run command
remember_command () {
[ -n "$COMP_LINE" ] && return
[ "$BASH_COMMAND" = "$PROMPT_COMMAND" ] && return
lastcommand=${BASH_COMMAND}
if [ ${#lastcommand} -gt 21 ]; then
lastcommand=${lastcommand:0:21}
elif [ ${#lastcommand} -lt 21 ]; then
x=$((21-${#lastcommand}))
while [ ${x} -gt 0 ]; do
lastcommand="${lastcommand} "
x=$((${x}-1))
done
fi
}
# remember last exit status and command
trap 'lastexit=$?;remember_command' DEBUG
if [[ ${enable_colors} == True ]]; then
esepacolor=$(echo ${sepacolor} | sed -e 's/\\\[//g' -e 's/\\\]//g')
......@@ -89,7 +70,7 @@ echo -en "\033[3;${COLUMNS}H${esepacolor}│"
i=${LINES}
[[ ${i} -ge 22 ]] && while [ ${i} -ge 4 ]
[[ ${i} -ge 16 ]] && while [ ${i} -ge 4 ]
do
case ${i} in
${j} )
......@@ -111,9 +92,9 @@ do
${n} )
echo -en "\033[${n};$((${COLUMNS}-29))H"
if [ ${lastexit} -eq 0 ]; then
echo -en "${esepacolor}( ${egreen}✔: ${lastcommand} ${esepacolor})─┤"
echo -en "${esepacolor}( ${egreen}✔: ${lastcommandprintable} ${esepacolor})─┤"
else
echo -en "${esepacolor}( ${ered}✘: ${lastcommand} ${esepacolor})─┤"
echo -en "${esepacolor}( ${ered}✘: ${lastcommandprintable} ${esepacolor})─┤"
fi
;;
* )
......@@ -154,6 +135,7 @@ do
fill="${fill}─"
let fillsize=${fillsize}-1
done
if [ "${fillsize}" -lt "0" ]
then
let cutt=${trunc_length}-${fillsize}
......@@ -173,7 +155,7 @@ echo -en "\033[2;$((${COLUMNS}-29))H"
echo -en "( $(date +%H:%M) : $(date '+%a, %d %b %y') )────┐"
echo -en "\033[3;${COLUMNS}H│"
while [ ${i} -ge 4 ]
[[ ${i} -ge 16 ]] && while [ ${i} -ge 4 ]
do
case ${i} in
${j} )
......@@ -195,9 +177,9 @@ do
${n} )
echo -en "\033[${n};$((${COLUMNS}-29))H"
if [ ${lastexit} -eq 0 ]; then
echo -en "( ✔: ${lastcommand} )─┤"
echo -en "( ✔: ${lastcommandprintable} )─┤"
else
echo -en "( ✘: ${lastcommand} )─┤"
echo -en "( ✘: ${lastcommandprintable} )─┤"
fi
;;
* )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment