summaryrefslogtreecommitdiff
path: root/newscript
diff options
context:
space:
mode:
authorfilip <“filip.rabiega@gmail.com”>2025-09-23 13:55:43 +0200
committerfilip <“filip.rabiega@gmail.com”>2025-09-23 13:55:43 +0200
commit8b23667b4e7435e96a60d99c3f5e5e9583237b18 (patch)
tree1f5f49aecf38948f03de978aac0db49c0b9e7143 /newscript
parente4ea00cfc9fc7340c62dd920b4754787c4499de6 (diff)
downloadchadscripts-8b23667b4e7435e96a60d99c3f5e5e9583237b18.tar.gz
chadscripts-8b23667b4e7435e96a60d99c3f5e5e9583237b18.tar.bz2
chadscripts-8b23667b4e7435e96a60d99c3f5e5e9583237b18.zip
new stuff
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
}