summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason Wessel <jason.wessel@windriver.com>2020-11-02 14:28:51 -0800
committerRichard Purdie <richard.purdie@linuxfoundation.org>2020-11-08 14:03:20 +0000
commit017cdf751de357e122129168ddde85a61404909c (patch)
treedc9c74f9cb5ee8f33e218b9a328ccc74a71b1ea5
parent3bbe49bc023a3893a65f184d9491bc0e20fccb54 (diff)
downloadpoky-017cdf751de357e122129168ddde85a61404909c.tar.gz
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 <jason.wessel@windriver.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--meta/recipes-core/base-files/base-files/profile48
1 files 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 @@
2# and Bourne compatible shells (bash(1), ksh(1), ash(1), ...). 2# and Bourne compatible shells (bash(1), ksh(1), ash(1), ...).
3 3
4PATH="/usr/local/bin:/usr/bin:/bin" 4PATH="/usr/local/bin:/usr/bin:/bin"
5EDITOR="vi" # needed for packages like cron, git-commit
6[ "$TERM" ] || TERM="vt100" # Basic terminal capab. For screen etc. 5[ "$TERM" ] || TERM="vt100" # Basic terminal capab. For screen etc.
7 6
8# Add /sbin & co to $PATH for the root user 7# Add /sbin & co to $PATH for the root user
@@ -20,13 +19,48 @@ if [ -d /etc/profile.d ]; then
20 unset i 19 unset i
21fi 20fi
22 21
23# Make sure we are on a serial console (i.e. the device used starts with 22if [ -t 0 -a $# -eq 0 ]; then
24# /dev/tty[A-z]), otherwise we confuse e.g. the eclipse launcher which tries do 23 if [ ! -x @BINDIR@/resize ] ; then
25# use ssh 24 if [ -n "$BASH_VERSION" ] ; then
26case $(tty 2>/dev/null) in 25# Optimized resize funciton for bash
27 /dev/tty[A-z]*) [ -x @BINDIR@/resize ] && @BINDIR@/resize >/dev/null;; 26resize() {
28esac 27 local x y
28 IFS='[;' read -t 2 -p $(printf '\e7\e[r\e[999;999H\e[6n\e8') -sd R _ y x _
29 [ -n "$y" ] && \
30 echo -e "COLUMNS=$x;\nLINES=$y;\nexport COLUMNS LINES;" && \
31 stty cols $x rows $y
32}
33 else
34# Portable resize function for ash/bash/dash/ksh
35# with subshell to avoid local variables
36resize() {
37 (o=$(stty -g)
38 stty -echo raw min 0 time 2
39 printf '\0337\033[r\033[999;999H\033[6n\0338'
40 if echo R | read -d R x 2> /dev/null; then
41 IFS='[;R' read -t 2 -d R -r z y x _
42 else
43 IFS='[;R' read -r _ y x _
44 fi
45 stty "$o"
46 [ -z "$y" ] && y=${z##*[}&&x=${y##*;}&&y=${y%%;*}
47 [ -n "$y" ] && \
48 echo "COLUMNS=$x;"&&echo "LINES=$y;"&&echo "export COLUMNS LINES;"&& \
49 stty cols $x rows $y)
50}
51 fi
52 fi
53 # Use the EDITOR not being set as a trigger to call resize
54 # and only do this for /dev/tty[A-z] which are typically
55 # serial ports
56 if [ -z "$EDITOR" -a "$SHLVL" = 1 ] ; then
57 case $(tty 2>/dev/null) in
58 /dev/tty[A-z]*) resize >/dev/null;;
59 esac
60 fi
61fi
29 62
63EDITOR="vi" # needed for packages like cron, git-commit
30export PATH PS1 OPIEDIR QPEDIR QTDIR EDITOR TERM 64export PATH PS1 OPIEDIR QPEDIR QTDIR EDITOR TERM
31 65
32umask 022 66umask 022