add checks - notes - a console notes manager using git
DIR Log
DIR Files
DIR Refs
DIR Tags
DIR LICENSE
---
DIR commit 4f00b96fadedcd98fcecac053feb037cbe908020
DIR parent 4362a1f1162ecf5a7cca0a837af47995b6ec3ba0
HTML Author: Solene Rapenne <solene@perso.pw>
Date: Sat, 14 Jul 2018 12:46:35 +0200
add checks
Diffstat:
M notes | 20 ++++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)
---
DIR diff --git a/notes b/notes
@@ -52,8 +52,11 @@ edit() {
then
mkdir -p "$(dirname "$destdir")"
"$EDITOR" "$1"
- git add "$1"
- git commit -m "editing by $USER" "$1"
+ if [ -f "$1" ]
+ then
+ git add "$1"
+ git commit -m "editing by $USER" "$1"
+ fi
exit 0
else
printf 'Aborting: "%s" is a directory.\n' "$1"
@@ -116,7 +119,7 @@ _completion_list() {
if [ -d "$REPO" ]
then
cd "$REPO"
- find . -name '.git' -prune -o -mindepth 2 -type f -print | sed 's,^\./,,'
+ find . -name '.git' -prune -o -type f -print | sed 's,^\./,,'
exit 0
else
printf 'Aborting: "%s" does not exist.\n' "$REPO"
@@ -144,8 +147,9 @@ then
fi
case "$1" in
+ '') display ;;
ls) display ;;
- i*) initialization ;;
+ i*) initialization ;;
la*) last ;;
e*) [ -n "$2" ] && edit "$2" ;;
hi*) [ -n "$2" ] && histo "$2" ;;
@@ -154,9 +158,5 @@ case "$1" in
_files) _completion_list ;;
esac
-if [ -f "$REPO/$1" ]; then
- edit "$1"
- exit 0
-fi
-
-#usage && exit 1
+# if parameter doesn't match a command, it may be a file
+edit "$1"