Skip to content

Commit 84d7819

Browse files
committed
added Python helper
1 parent bbd4820 commit 84d7819

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

opt/cs50/lib/help50/python

+14-2
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,26 @@ if [[ "$output" =~ $regex ]]; then
3131
fi
3232
fi
3333

34-
# mkdir foo && touch foo/bar.py && python bar.py
34+
# mkdir -p foo/bar && touch foo/bar/baz.py && python baz.py
3535
regex="python: can't open file '(.*\.py)': \[Errno 2\] No such file or directory"
3636
if [[ "$output" =~ $regex ]]; then
3737

3838
# Relative path from $PWD
3939
path=$(realpath --relative-to=. "${BASH_REMATCH[1]}")
4040

41-
# If .py is in $PWD
41+
# If command was `python baz.py` (i.e., without a dirname)
42+
if [[ -n "$path" && "$path" == $(basename "$path") ]]; then
43+
dir=$(_find -type f "$path")
44+
echo -n "There isn't a file called \`$path\` in your current directory."
45+
if [[ ! -z "$dir" ]]; then
46+
echo " Did you mean to \`cd $dir\` first?"
47+
else
48+
echo
49+
fi
50+
exit
51+
fi
52+
53+
# If command was `python bar/baz.py` (i.e., with a dirname)
4254
if [[ -n "$path" && "$path" == $(basename "$path") ]]; then
4355
dir=$(_find -type f "$path")
4456
echo -n "There isn't a file called \`$path\` in your current directory."

0 commit comments

Comments
 (0)