Skip to content

Commit

Permalink
added detection of backslash
Browse files Browse the repository at this point in the history
  • Loading branch information
dmalan committed Jun 24, 2024
1 parent 2051c45 commit 3192a87
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions opt/cs50/lib/help50/bash
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,28 @@ if [[ "$output" =~ $regex ]]; then
fi
fi

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

# If directory exists
if [[ -d "${BASH_REMATCH[1]}" ]]; then
echo "Did you mean to run \`cd ${BASH_REMATCH[1]}\`?"
exit
fi

# If typo
if [[ "${BASH_REMATCH[1]}" == "1s" ]]; then
echo "Did you mean to run \`ls\` (which starts with a lowercase L)?"
exit
fi

# If directory exists
if [[ -d "${BASH_REMATCH[1]}" ]]; then
echo "Did you mean to run \`cd ${BASH_REMATCH[1]}\`?"
exit
# If backslash instead of forward slash
if [[ "${BASH_REMATCH[1]}" =~ ^\.(.*) ]]; then
if [[ -f "./${BASH_REMATCH[1]}" ]]; then
echo "Did you mean to run \`./${BASH_REMATCH[1]}\`, with a forward slash instead?"
exit
fi
fi
fi

Expand Down

0 comments on commit 3192a87

Please sign in to comment.