From 3192a87e5f5cc712b96f35d77362297ccd2cc4ba Mon Sep 17 00:00:00 2001 From: "David J. Malan" Date: Mon, 24 Jun 2024 11:29:48 -0400 Subject: [PATCH] added detection of backslash --- opt/cs50/lib/help50/bash | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/opt/cs50/lib/help50/bash b/opt/cs50/lib/help50/bash index dcc2729..796d8c6 100755 --- a/opt/cs50/lib/help50/bash +++ b/opt/cs50/lib/help50/bash @@ -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