-
Notifications
You must be signed in to change notification settings - Fork 71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Motd updates #8
Motd updates #8
Conversation
Thank you for taking the time to help out with this. My version is using I'll leave comments at the appropriate places as I'm reviewing these changes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
# Setup TERMUX_APP_PACKAGE_MANAGER | ||
source "@TERMUX_PREFIX@/bin/termux-setup-package-manager" || exit 1 | ||
|
||
terminal_width="$(stty size | cut -d" " -f2)" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Terminal width can be determined by simply reading the value of $COLUMNS
.
Unless that environment variable is unavailable for some reason in this context, in which case please inform me so I can fix this in my own version.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$COLUMS
is not set if bash shell is not interactive, like when motd
is executed, unless -i
is passed, which creates other problems. It can still be set if checkwinsize
is set, but requires starting a sub shell. stty
is posix and should be fine to use.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah that makes sense, I did have checkwinsize
set, but it's probably better to use stty
in this context.
source "@TERMUX_PREFIX@/bin/termux-setup-package-manager" || exit 1 | ||
|
||
terminal_width="$(stty size | cut -d" " -f2)" | ||
if [[ "$terminal_width" =~ ^[0-9]+$ ]] && [ "$terminal_width" -gt 60 ]; then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of using a fixed range for the maximum column width of a line on the motd we can evaluate the maximal line length dynamically using something like this.
len_motd=$(echo "$motd_logo" | sed -E "s/\\\e\[[0-9;]+m//g" | wc -L)
if (($COLUMNS > $len_motd))
then echo -ne "$motd_logo"
We read in the motd, strip out any escape sequences, and pass it to wc -L
which returns the column count of the longest line.
With $motd_logo
being a Heredoc
/variable containing the part of the motd liable to being distorted by wrapping
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am aware of that, but no need to do such processing and calling additional external binaries like sed
and wc
. If motd
is updated, the commiter can adjust size. Moreover, 60
is a good default for column width for motd anyways.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah that's a reasonable concern.
terminal_width="$(stty size | cut -d" " -f2)" | ||
if [[ "$terminal_width" =~ ^[0-9]+$ ]] && [ "$terminal_width" -gt 60 ]; then | ||
|
||
motd=" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As mentioned above utilizing a Heredoc
may be desirable in the interest of cleanliness and maintainability.
# Store $IFS for safekeeping
OLD_IFS=$IFS
# Logo portion of the MOTD.
IFS='' read -rd '' motd_logo << LOGO_EOF
\e[47m \e[0m \e[1mWelcome to Termux!\e[0m
\e[47m \e[0m \e[47m\e[47m \e[0m
\e[47m \e[0m \e[47m \e[0m \e[47m \e[0m \e[1mDocs:\e[0m \e[4mtermux.dev/docs\e[0m
\e[47m \e[0m \e[47m \e[0m \e[47m \e[0m \e[1mGitter:\e[0m \e[4mgitter.im/termux/termux\e[0m
\e[47m \e[0m \e[47m \e[0m \e[1mCommunity:\e[0m \e[4mtermux.dev/community\e[0m
\e[47m \e[0m \e[47m\e[47m \e[0m
\e[47m \e[0m \e[1mTermux version:\e[0m ${TERMUX_VERSION-Unknown}
LOGO_EOF
Storing the initial $IFS
may be necessary if a user has set a custom Input Field Separator.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for heredoc, since it is slower since it requires creation of temp file and also additional utils like read
or cat
. We are also appending motd
variable, so current way is better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm didn't think of that.
\e[47m \e[0m \e[1mTermux version:\e[0m ${TERMUX_VERSION-Unknown} | ||
" | ||
|
||
motd_indent=" " |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Storing the indent of the motd as a separate variable is a great idea and I will be adopting it into my version as it simplifies handling the indentation significantly.
|
||
else | ||
|
||
motd=" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same rationale as above regarding Heredocs
for cleanliness and maintainability applies here, and to subsequent motd parts.
scripts/login.in
Outdated
elif [ -f @TERMUX_PREFIX@/etc/motd ]; then | ||
cat @TERMUX_PREFIX@/etc/motd | ||
# Use user defined dynamic motd file if it exists | ||
if [ -f ~/.termux/motd.sh ] && [ -f @TERMUX_PREFIX@/bin/bash ] && [ -x @TERMUX_PREFIX@/bin/bash ]; then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if [ -f ~/.termux/motd.sh ] && [ -f @TERMUX_PREFIX@/bin/bash ] && [ -x @TERMUX_PREFIX@/bin/bash ]; then | |
if [ -f ~/.termux/motd.sh ] && [ -x @TERMUX_PREFIX@/bin/bash ]; then |
Testing for just executability is sufficient as the file needs to exist to be executable,
thus [ -x @TERMUX_PREFIX@/bin/bash ]
should be sufficient to test for both existence and executability.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-f
checks if bash
is a regular file and not a directory. -x
won't check that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh right.
I suppose there could be a @TERMUX_PREFIX@/bin/bash/
directory.
motd_indent="" | ||
fi | ||
|
||
motd+=" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Concatenating the motd variable with applicable sections is a significantly more elegant approach than my current solution, I will will be adopting it.
Also forgot to mention that environmental variable way for custom motd file path and disabling showing icon is not gonna work. Idiot me didn't consider that they won't be set in Also need to merge that |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that motd can only be determined when logging in
What? |
If the motd is printed when logging in, maybe it can not be changed by zooming : ( |
Motd icon will break on zooming in after its been drawn, already mentioned in commit message, that's why default is back to static. And not sure why motd icon is too big a deal to be kept, considering its issues. If people are gonna actually run any commands in the terminal (instead of it just being riced up for a photo op for instagram/reddit ;)), it's gonna disappear in scrollback history anyways. |
As of right now, that is correct. Edit: That being said... Let me see if Edit 2: |
- The logo added in new dynamic motd would break due to word wrap if terminal columns were less than max line length. This fixes the issue by not drawing a logo if terminal columns are too few at draw time. Note that logo will still break if terminal size is changed after drawing. - Use TERMUX_APP_PACKAGE_MANAGER instead of TERMUX_MAIN_PACKAGE_FORMAT - Add donate link instead of gitter which should already exist in community link, including matrix rooms link. Related pull requests termux/termux-packages#11250 and termux/termux-packages#11294
…motd and add support for custom motd The dynamic motd has issues with logo word wrap as discussed in 5956876 and so can't be used as default. Users who want to use it or a custom one can create a motd file/symlink at `~/.termux/motd.sh` to load a custom motd. To use the dynamic motd provided by termux-tools package, run `ln -sf $PREFIX/etc/motd.sh ~/.termux/motd.sh` Also directly execute motd.sd and rely on interpreter instead of executing with bash in case its not available or user does not want a bash script as motd.sh
0fb528e
to
6a0f5cc
Compare
Made a change to directly execute Merging since no issues reported till now (that need fixing). |
Fixes the word wrap issues of dynamic motd and other additions. Check commits.
The
aarch64
build is attached, install withdpkg -i --force-confask --force-confnew /sdcard/Download/termux-tools_1.26.0-1_all.deb
Related pull requests termux/termux-packages#11250 and termux/termux-packages#11294
cc: @TomJo2000 @HardcodedCat
termux-tools_1.26.0-1_all.zip