Skip to content

Commit

Permalink
capping size of help50 input
Browse files Browse the repository at this point in the history
  • Loading branch information
dmalan committed Jan 31, 2024
1 parent 383f4a2 commit 72c3d53
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion etc/profile.d/help50.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
# If root
if [ "$(whoami)" == "root" ]; then
return
fi

. /opt/cs50/lib/cli

# Directory with helpers
HELPERS="/opt/cs50/lib/help50"

# Disable yes, lest users type it at prompt
if command -v yes &> /dev/null; then
alias yes=":"
function yes() {
if [[ -t 0 ]]; then
:
else
command yes
fi
}
fi

# Ignore duplicates (but not commands that begin with spaces)
Expand Down Expand Up @@ -55,6 +66,9 @@ function _help50() {
# Remove script's own output (if this is user's first command)
typescript=$(echo "$typescript" | sed '1{/^Script started on .*/d}')

# Cap typescript at MIN(1K lines, 1M bytes), else `read` is slow
typescript=$(echo "$typescript" | head -n 1024 | cut -b 1-1048576)

# Remove any line continuations from command line
local lines=""
while IFS= read -r line || [[ -n "$line" ]]; do
Expand Down

0 comments on commit 72c3d53

Please sign in to comment.