Skip to content

Commit 3192a87

Browse files
committed
added detection of backslash
1 parent 2051c45 commit 3192a87

File tree

1 file changed

+13
-5
lines changed
  • opt/cs50/lib/help50

1 file changed

+13
-5
lines changed

opt/cs50/lib/help50/bash

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,28 @@ if [[ "$output" =~ $regex ]]; then
1313
fi
1414
fi
1515

16-
# mkdir foo && bar
16+
# mkdir foo && (foo || 1s || .\foo)
1717
regex="bash: (.*): command not found"
1818
if [[ "$output" =~ $regex ]]; then
1919

20+
# If directory exists
21+
if [[ -d "${BASH_REMATCH[1]}" ]]; then
22+
echo "Did you mean to run \`cd ${BASH_REMATCH[1]}\`?"
23+
exit
24+
fi
25+
2026
# If typo
2127
if [[ "${BASH_REMATCH[1]}" == "1s" ]]; then
2228
echo "Did you mean to run \`ls\` (which starts with a lowercase L)?"
2329
exit
2430
fi
2531

26-
# If directory exists
27-
if [[ -d "${BASH_REMATCH[1]}" ]]; then
28-
echo "Did you mean to run \`cd ${BASH_REMATCH[1]}\`?"
29-
exit
32+
# If backslash instead of forward slash
33+
if [[ "${BASH_REMATCH[1]}" =~ ^\.(.*) ]]; then
34+
if [[ -f "./${BASH_REMATCH[1]}" ]]; then
35+
echo "Did you mean to run \`./${BASH_REMATCH[1]}\`, with a forward slash instead?"
36+
exit
37+
fi
3038
fi
3139
fi
3240

0 commit comments

Comments
 (0)