Skip to content

Commit

Permalink
Fix 'edit' command to allow new files
Browse files Browse the repository at this point in the history
Previously, when one wanted to create mentorship notes for an exercise
that didn't have one file for, the `xr` function would reject this case.
But editors obviously can create files, so now the function lets one use
the 'edit' sub-command in order to create new notes, but still rejects
doing so when not in a exercise's directory and that no exercise name
has been explicitely given through a second argument.

Signed-off-by: Paul Mabileau <[email protected]>
  • Loading branch information
PaulDance committed Nov 6, 2020
1 parent b1ae85c commit 1e135c7
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions xr.sh
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,17 @@ function xr() {
note="$note/$(_config_get exercise).md"
fi

if [[ -f "$note" ]]; then
if [[ "$1" == "notes" ]]; then
if [[ "$1" == "notes" ]]; then
if [[ -f "$note" ]]; then
cat "$note"
else
$EDITOR "$note"
echo "Unknown exercise or topic note: $note"
return 1
fi
elif [[ "$(basename $note)" != ".md" ]]; then
$EDITOR "$note"
else
echo "Unknown exercise or topic note: $note"
echo "Current directory is not an exercise."
return 1
fi
;;
Expand Down

0 comments on commit 1e135c7

Please sign in to comment.