Skip to content

Commit

Permalink
added helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
dmalan committed May 9, 2024
1 parent 3eae3bd commit e43789b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
8 changes: 8 additions & 0 deletions opt/cs50/lib/help50/bash
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ if [[ "$output" =~ $regex ]]; then
exit
fi

# touch foo && cd foo
regex="bash: cd: (.*): Not a directory"
if [[ "$output" =~ $regex ]]; then
file="${BASH_REMATCH[1]}"
echo "Looks like you're trying to change directories, but \`$file\` isn't a directory."
exit
fi

# touch foo.c && ./foo.c
regex="bash: \./(([^:]*)\.c): Permission denied"
if [[ "$output" =~ $regex ]]; then
Expand Down
7 changes: 7 additions & 0 deletions opt/cs50/lib/help50/cd
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,10 @@ if [[ "$output" =~ $regex ]]; then
echo
fi
fi

# cd.. || cd.
regex="bash: cd\.\.?: command not found"
if [[ "$output" =~ $regex ]]; then
echo "Did you mean to run \`cd ..\` instead?"
exit
fi
7 changes: 4 additions & 3 deletions opt/cs50/lib/help50/make
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ if [[ "$output" =~ $regex ]]; then

# If target is a directory
if [[ -d "${BASH_REMATCH[1]}" ]]; then
echo "Cannot run \`make\` on a directory. Did you mean to run \`cd ${BASH_REMATCH[1]}\`?"
echo "Cannot run \`make\` on a directory. Did you mean to run \`cd ${BASH_REMATCH[1]}\` instead?"
exit
fi

# If target ends with .c
if [[ "${BASH_REMATCH[1]}" == *?.c ]]; then
base="${BASH_REMATCH[1]%.c}"
if [[ -n "$base" && ! -d "$base" ]]; then
echo "Did you mean to run \`make ${base}\`?"
echo "Did you mean to run \`make ${base}\` instead?"
exit
fi
fi
Expand All @@ -28,7 +28,8 @@ regex="make: \*\*\* No rule to make target '(.*)'"
if [[ "$output" =~ $regex ]]; then

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

# Search recursively for .c file
Expand Down

0 comments on commit e43789b

Please sign in to comment.