-
Notifications
You must be signed in to change notification settings - Fork 159
Motd updates #8
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| # Copyright (C) 2022 Termux | ||
|
|
||
| # This file is part of termux-tools. | ||
|
|
||
| # termux-tools is free software: you can redistribute it and/or modify | ||
| # it under the terms of the GNU General Public License as published by | ||
| # the Free Software Foundation, either version 3 of the License, or | ||
| # (at your option) any later version. | ||
|
|
||
| # termux-tools is distributed in the hope that it will be useful, but | ||
| # WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| # General Public License for more details. | ||
|
|
||
| # You should have received a copy of the GNU General Public License | ||
| # along with termux-tools. If not, see | ||
| # <https://www.gnu.org/licenses/>. | ||
|
|
||
|
|
||
| # We have two variants of our motd message loaded by login script: | ||
| # 1. motd.sh: A dynamic motd that is executed with bash and echos a | ||
| # motd message with escape sequences, optionally with a terminal logo. | ||
| # 2. motd: A static motd that is just read as is with cat and displayed. | ||
|
|
||
| # The motd-playstore is an additional motd that will only be displayed | ||
| # if the termux-app version is very old (like the version found on playstore) | ||
| sysconf_DATA = motd.sh motd motd-playstore | ||
|
|
||
| CLEANFILES = motd.sh motd | ||
|
|
||
|
|
||
| do_subst = sed -e "s%[@]TERMUX_PREFIX[@]%$(termux_prefix)%g" | ||
|
|
||
| define process-rule | ||
| $1: $1.in Makefile | ||
| @echo "Creating $1" | ||
| @$$(do_subst) < $(srcdir)/$1.in > $1 | ||
| endef | ||
|
|
||
| $(eval $(call process-rule,motd.sh)) | ||
|
|
||
|
|
||
| motd: | ||
| @echo "Creating motd file" | ||
|
|
||
| @echo "Welcome to Termux!" > motd | ||
| @echo "" >> motd | ||
| @echo "Docs: https://termux.dev/docs" >> motd | ||
| @echo "Donate: https://termux.dev/donate" >> motd | ||
| @echo "Community: https://termux.dev/community" >> motd | ||
|
|
||
| @echo "" >> motd | ||
| @echo "Working with packages:" >> motd | ||
| @echo "" >> motd | ||
| @echo " - Search: pkg search <query>" >> motd | ||
| @echo " - Install: pkg install <package>" >> motd | ||
| @echo " - Upgrade: pkg upgrade" >> motd | ||
|
|
||
| ifeq ($(TERMUX_PACKAGE_MANAGER),apt) | ||
| @echo "" >> motd | ||
| @echo "Subscribing to additional repositories:" >> motd | ||
| @echo "" >> motd | ||
| @echo " - Root: pkg install root-repo" >> motd | ||
| @echo " - X11: pkg install x11-repo" >> motd | ||
| @echo "" >> motd | ||
| @echo "For fixing any repository issues," >> motd | ||
| @echo "try 'termux-change-repo' command." >> motd | ||
| endif | ||
|
|
||
| @echo "" >> motd | ||
| @echo "Report issues at https://termux.dev/issues" >> motd | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| #!@TERMUX_PREFIX@/bin/bash | ||
|
|
||
| # Setup TERMUX_APP_PACKAGE_MANAGER | ||
| source "@TERMUX_PREFIX@/bin/termux-setup-package-manager" || exit 1 | ||
|
|
||
| terminal_width="$(stty size | cut -d" " -f2)" | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Terminal width can be determined by simply reading the value of
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah that makes sense, I did have |
||
| if [[ "$terminal_width" =~ ^[0-9]+$ ]] && [ "$terminal_width" -gt 60 ]; then | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 With
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah that's a reasonable concern. |
||
|
|
||
| motd=" | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As mentioned above utilizing a # 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_EOFStoring the initial
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm didn't think of that. |
||
| \e[47m \e[0m \e[1mWelcome to Termux!\e[0m | ||
| \e[47m \e[0m \e[0;37m\e[47m .\e[0m | ||
| \e[47m \e[0m \e[47m \e[0m \e[47m \e[0m \e[1mDocs:\e[0m \e[4mhttps://termux.dev/docs\e[0m | ||
| \e[47m \e[0m \e[47m \e[0m \e[47m \e[0m \e[1mDonate:\e[0m \e[4mhttps://termux.dev/donate\e[0m | ||
| \e[47m \e[0m \e[47m \e[0m \e[1mCommunity:\e[0m \e[4mhttps://termux.dev/community\e[0m | ||
| \e[47m \e[0m \e[0;37m\e[47m .\e[0m | ||
| \e[47m \e[0m \e[1mTermux version:\e[0m ${TERMUX_VERSION-Unknown} | ||
| " | ||
|
|
||
| motd_indent=" " | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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=" | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same rationale as above regarding |
||
| \e[1mWelcome to Termux!\e[0m | ||
| \e[1mDocs:\e[0m \e[4mhttps://termux.dev/docs\e[0m | ||
| \e[1mDonate:\e[0m \e[4mhttps://termux.dev/donate\e[0m | ||
| \e[1mCommunity:\e[0m \e[4mhttps://termux.dev/community\e[0m | ||
| \e[1mTermux version:\e[0m ${TERMUX_VERSION-Unknown} | ||
| " | ||
|
|
||
| motd_indent="" | ||
| fi | ||
|
|
||
| motd+=" | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| ${motd_indent}\e[1mWorking with packages:\e[0m | ||
| ${motd_indent}\e[1mSearch:\e[0m pkg search <query> | ||
| ${motd_indent}\e[1mInstall:\e[0m pkg install <package> | ||
| ${motd_indent}\e[1mUpgrade:\e[0m pkg upgrade | ||
| " | ||
|
|
||
|
|
||
| if [ "$TERMUX_APP_PACKAGE_MANAGER" = "apt" ]; then | ||
|
|
||
| motd+=" | ||
| ${motd_indent}\e[1mSubscribing to additional repos:\e[0m | ||
| ${motd_indent}\e[1mRoot:\e[0m pkg install root-repo | ||
| ${motd_indent}\e[1mX11:\e[0m pkg install x11-repo | ||
| ${motd_indent}For fixing any repository issues, | ||
| ${motd_indent}try 'termux-change-repo' command. | ||
| " | ||
|
|
||
| fi | ||
|
|
||
| motd+=" | ||
| ${motd_indent}Report issues at \e[4mhttps://termux.dev/issues\e[0m | ||
| " | ||
|
|
||
| echo -e "$motd" | ||
Uh oh!
There was an error while loading. Please reload this page.