summaryrefslogtreecommitdiff
path: root/newscript
blob: da2a21a59a5279eb647e21278abc45c2fd8c77e1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/bin/sh
# Add a new script

newscript() {
	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 "$file"
	fi
}

[ "$#" -ne 1 ] && {
	echo "Usage: newscript <script-name>" >&2
	exit 1
}

newscript "$1"
exit 0