Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Changes from all commits
d17067d
5956876
6a0f5cc
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
This file was deleted.
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 whenmotd
is executed, unless-i
is passed, which creates other problems. It can still be set ifcheckwinsize
is set, but requires starting a sub shell.stty
is posix and should be fine to use.https://stackoverflow.com/a/563592
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 usestty
in this context.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.
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 aHeredoc
/variable containing the part of the motd liable to being distorted by wrappingThere 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
andwc
. Ifmotd
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.
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.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
orcat
. We are also appendingmotd
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.
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.
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.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.