From 017cdf751de357e122129168ddde85a61404909c Mon Sep 17 00:00:00 2001 From: Jason Wessel Date: Mon, 2 Nov 2020 14:28:51 -0800 Subject: base-files/profile: Add universal resize function Using an editor or any kind of command line that wraps beyond the column width of the session on a serial port is quite problematic unless you are using an 80x24 session. The original /etc/profile tried to use the resize binary if it was available. The problem is that you only get the resize binary if xterm, or busybox is installed. This updated /etc/profile will add a resize function available to the shell when no xterm or busybox resize binary is found. More care is taken in this new version to test that terminal is interactive. The EDITOR and SHLVL environment variables are checked to prevent resize from running necessarily. The function definitions are not indented intentionally to keep them to the 80 column width. (From OE-Core rev: 3743892996172c8595a1cbe884c4a0e6ef50dcda) Signed-off-by: Jason Wessel Signed-off-by: Richard Purdie --- meta/recipes-core/base-files/base-files/profile | 48 +++++++++++++++++++++---- 1 file changed, 41 insertions(+), 7 deletions(-) diff --git a/meta/recipes-core/base-files/base-files/profile b/meta/recipes-core/base-files/base-files/profile index 9e4283e0c7..cc37e1ba77 100644 --- a/meta/recipes-core/base-files/base-files/profile +++ b/meta/recipes-core/base-files/base-files/profile @@ -2,7 +2,6 @@ # and Bourne compatible shells (bash(1), ksh(1), ash(1), ...). PATH="/usr/local/bin:/usr/bin:/bin" -EDITOR="vi" # needed for packages like cron, git-commit [ "$TERM" ] || TERM="vt100" # Basic terminal capab. For screen etc. # Add /sbin & co to $PATH for the root user @@ -20,13 +19,48 @@ if [ -d /etc/profile.d ]; then unset i fi -# Make sure we are on a serial console (i.e. the device used starts with -# /dev/tty[A-z]), otherwise we confuse e.g. the eclipse launcher which tries do -# use ssh -case $(tty 2>/dev/null) in - /dev/tty[A-z]*) [ -x @BINDIR@/resize ] && @BINDIR@/resize >/dev/null;; -esac +if [ -t 0 -a $# -eq 0 ]; then + if [ ! -x @BINDIR@/resize ] ; then + if [ -n "$BASH_VERSION" ] ; then +# Optimized resize funciton for bash +resize() { + local x y + IFS='[;' read -t 2 -p $(printf '\e7\e[r\e[999;999H\e[6n\e8') -sd R _ y x _ + [ -n "$y" ] && \ + echo -e "COLUMNS=$x;\nLINES=$y;\nexport COLUMNS LINES;" && \ + stty cols $x rows $y +} + else +# Portable resize function for ash/bash/dash/ksh +# with subshell to avoid local variables +resize() { + (o=$(stty -g) + stty -echo raw min 0 time 2 + printf '\0337\033[r\033[999;999H\033[6n\0338' + if echo R | read -d R x 2> /dev/null; then + IFS='[;R' read -t 2 -d R -r z y x _ + else + IFS='[;R' read -r _ y x _ + fi + stty "$o" + [ -z "$y" ] && y=${z##*[}&&x=${y##*;}&&y=${y%%;*} + [ -n "$y" ] && \ + echo "COLUMNS=$x;"&&echo "LINES=$y;"&&echo "export COLUMNS LINES;"&& \ + stty cols $x rows $y) +} + fi + fi + # Use the EDITOR not being set as a trigger to call resize + # and only do this for /dev/tty[A-z] which are typically + # serial ports + if [ -z "$EDITOR" -a "$SHLVL" = 1 ] ; then + case $(tty 2>/dev/null) in + /dev/tty[A-z]*) resize >/dev/null;; + esac + fi +fi +EDITOR="vi" # needed for packages like cron, git-commit export PATH PS1 OPIEDIR QPEDIR QTDIR EDITOR TERM umask 022 -- cgit v1.2.3-54-g00ecf