Skip to content

Commit

Permalink
added helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
dmalan committed Jan 19, 2024
1 parent 1a38952 commit 501a59d
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 7 deletions.
14 changes: 7 additions & 7 deletions opt/cs50/lib/help50/make
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@ if [[ "$output" =~ $regex ]]; then

fi

regex="No rule to make target '(.*)'"
regex="make: \*\*\* No rule to make target '(.*)'"
if [[ "$output" =~ $regex ]]; then

# If no .c file for target
c="${BASH_REMATCH[1]}.c"
if [[ ! -f "$c" ]]; then
file="${BASH_REMATCH[1]}.c"
if [[ ! -f "$file" ]]; then

# Search recursively for .c file
path=$(_search "$c")
echo -n "There isn't a file called \`${c}\` in your current directory. You are in \`$(basename "$PWD")\`."
if [[ ! -z "$path" ]]; then
echo " Did you mean to \`cd $path\` first?"
dir=$(_search "$file")
echo -n "There isn't a file called \`$file\` in your current directory."
if [[ ! -z "$dir" ]]; then
echo " Did you mean to \`cd $dir\` first?"
else
echo
fi
Expand Down
38 changes: 38 additions & 0 deletions opt/cs50/lib/help50/python
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/bash

output=$(cat)

regex="AttributeError: module 'cs50' has no attribute '(get_(float|int|string)|SQL)'$"
if [[ "$output" =~ $regex ]]; then
if [[ -f cs50.py ]]; then
echo "You have a file called \`cs50.py\` that is \"shadowing\" CS50's own. Best to rename that file with \`mv\`."
exit
fi
fi

regex='^\s*(import string\s*$|from\s+string\s+import\s+)'
if echo "$output" | grep -Pq "$regex"; then
if [[ -f string.py ]]; then
echo "You have a file called \`string.py\` that is \"shadowing\" Python's own. Best to rename that file with \`mv\`."
exit
fi
fi

regex="python: can't open file '(.*\.py)': \[Errno 2\] No such file or directory"
if [[ "$output" =~ $regex ]]; then

# Relative path from $PWD
path=$(realpath --relative-to=. "${BASH_REMATCH[1]}")

# If .py is in $PWD
if [[ -n "$path" && "$path" == $(basename "$path") ]]; then
dir=$(_search "$path")
echo -n "There isn't a file called \`$path\` in your current directory."
if [[ ! -z "$dir" ]]; then
echo " Did you mean to \`cd $dir\` first?"
else
echo
fi
exit
fi
fi

0 comments on commit 501a59d

Please sign in to comment.