Skip to content

Commit e43789b

Browse files
committed
added helpers
1 parent 3eae3bd commit e43789b

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

opt/cs50/lib/help50/bash

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ if [[ "$output" =~ $regex ]]; then
3737
exit
3838
fi
3939

40+
# touch foo && cd foo
41+
regex="bash: cd: (.*): Not a directory"
42+
if [[ "$output" =~ $regex ]]; then
43+
file="${BASH_REMATCH[1]}"
44+
echo "Looks like you're trying to change directories, but \`$file\` isn't a directory."
45+
exit
46+
fi
47+
4048
# touch foo.c && ./foo.c
4149
regex="bash: \./(([^:]*)\.c): Permission denied"
4250
if [[ "$output" =~ $regex ]]; then

opt/cs50/lib/help50/cd

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,10 @@ if [[ "$output" =~ $regex ]]; then
1818
echo
1919
fi
2020
fi
21+
22+
# cd.. || cd.
23+
regex="bash: cd\.\.?: command not found"
24+
if [[ "$output" =~ $regex ]]; then
25+
echo "Did you mean to run \`cd ..\` instead?"
26+
exit
27+
fi

opt/cs50/lib/help50/make

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ if [[ "$output" =~ $regex ]]; then
99

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

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

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

3435
# Search recursively for .c file

0 commit comments

Comments
 (0)