summaryrefslogtreecommitdiff
path: root/newscript
diff options
context:
space:
mode:
Diffstat (limited to 'newscript')
-rwxr-xr-xnewscript11
1 files changed, 6 insertions, 5 deletions
diff --git a/newscript b/newscript
index c251e20..0b47bbd 100755
--- a/newscript
+++ b/newscript
@@ -1,12 +1,13 @@
#!/bin/sh
newscript () {
- path="$HOME/.scripts/$1"
- touch "$path" && printf "#!/bin/sh\n\n" > "$path" && "$EDITOR" +2 "$path"
- if [ "$( wc -l "$path" | awk '{print $1}' )" -lt 3 ]; then
- rm -f "$path"
+ file="$HOME/.scripts/$1"
+ [ -f "$file" ] && { echo "Script with the same name already exists, exiting" >&2; exit 1 ;}
+ touch "$file" && printf "#!/bin/sh\n\n" > "$file" && "$EDITOR" +2 "$file"
+ if [ "$( wc -l "$file" | awk '{print $1}' )" -lt 3 ]; then
+ rm -f "$file"
else
- chmod +x "$path"
+ chmod +x "$file"
fi
}