Skip to content

Commit

Permalink
Add special escape sequences to PS1
Browse files Browse the repository at this point in the history
Color sequences have to be bracketed by \[ and \] to keep Bash from
counting those characters when determining the prompt length. Failure to
account for this results in broken line wrapping for long shell input.
  • Loading branch information
zdykstra committed Apr 17, 2022
1 parent 3d9f57b commit 632b24f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
23 changes: 14 additions & 9 deletions zfsbootmenu/bin/zfs-chroot
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,19 @@ cleanup() {
trap - HUP INT QUIT ABRT EXIT
}

# shellcheck disable=SC1091
source /lib/profiling-lib.sh >/dev/null 2>&1
# shellcheck disable=SC1091
source /etc/zfsbootmenu.conf 2>&1 || exit 1
# shellcheck disable=SC1091
source /lib/kmsg-log-lib.sh >/dev/null 2>&1 || exit 1
# shellcheck disable=SC1091
source /lib/zfsbootmenu-core.sh >/dev/null 2>&1 || exit 1
sources=(
/lib/profiling-lib.sh
/etc/zfsbootmenu.conf
/lib/kmsg-log-lib.sh
/lib/zfsbootmenu-core.sh
)

for src in "${sources[@]}"; do
# shellcheck disable=SC1090
source "${src}" >/dev/null 2>&1 || exit 1
done

unset src sources

selected="${1}"

Expand Down Expand Up @@ -82,6 +87,6 @@ fi
echo -e "$( colorize orange "${selected}") is mounted ${writemode}, /tmp is shared and read/write\n"

# regardless of shell, set PS1
if ! env "PS1=$( colorize orange "${selected}") \w > " chroot "${mountpoint}" "${_SHELL}" "${chroot_extra}" ; then
if ! env "PS1=\[\033[0;33m\]${selected}\[\033[0m\] \w > " chroot "${mountpoint}" "${_SHELL}" "${chroot_extra}" ; then
zdebug "chroot ${selected}:${_SHELL} returned code $?"
fi
2 changes: 1 addition & 1 deletion zfsbootmenu/install-helpers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ create_zbm_profiles() {
[ -f /etc/profile ] && source /etc/profile
[ -f /lib/zfsbootmenu-completions.sh ] && source /lib/zfsbootmenu-completions.sh
export PS1="\033[0;33mzfsbootmenu\033[0m \w > "
export PS1="\[\033[0;33m\]zfsbootmenu\[\033[0m\] \w > "
alias clear="tput clear"
alias reset="tput reset"
Expand Down

0 comments on commit 632b24f

Please sign in to comment.