fix parameter handling - notes - a console notes manager using git
DIR Log
DIR Files
DIR Refs
DIR Tags
DIR LICENSE
---
DIR commit 41390477577874b866f2f5a2c2c3b50c71f67237
DIR parent 3e4e0e0592a07ce3c5edbb3bad1dd9e6f50ce52b
HTML Author: Solene Rapenne <solene@perso.pw>
Date: Sat, 14 Jul 2018 12:32:48 +0200
fix parameter handling
Diffstat:
M notes | 29 ++++++++++++++++++-----------
1 file changed, 18 insertions(+), 11 deletions(-)
---
DIR diff --git a/notes b/notes
@@ -1,4 +1,5 @@
#!/bin/sh
+set -x
# tool for taking notes inside a git repository
@@ -64,8 +65,14 @@ edit() {
# show file history using tig program
histo() {
cd "$REPO"
- tig "$1"
- exit 0
+ if [ -f "$1" ]
+ then
+ tig "$1"
+ exit 0
+ else
+ printf 'Aborting: "%s" file does not exist.\n' "$1"
+ exit 5
+ fi
}
# output the content of a file
@@ -138,14 +145,14 @@ then
fi
case "$1" in
- "ls") display ;;
- "i*") initialization ;;
- "la*") last ;;
- "e*") [ -n "$2" ] && edit "$2" ;;
- "hi*") [ -n "$2" ] && histo "$2" ;;
- "r*") [ -n "$2" ] && delete "$2" ;;
- "c*") [ -n "$2" ] && show_file "$2" ;;
- "_files") _completion_list ;;
+ ls) display ;;
+ i*) initialization ;;
+ la*) last ;;
+ e*) [ -n "$2" ] && edit "$2" ;;
+ hi*) [ -n "$2" ] && histo "$2" ;;
+ r*) [ -n "$2" ] && delete "$2" ;;
+ c*) [ -n "$2" ] && show_file "$2" ;;
+ _files) _completion_list ;;
esac
if [ -f "$REPO/$1" ]; then
@@ -153,4 +160,4 @@ if [ -f "$REPO/$1" ]; then
exit 0
fi
-usage && exit 1
+#usage && exit 1