-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreateScript.sh
53 lines (42 loc) · 914 Bytes
/
createScript.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/bin/bash
# create_script
# This script creates a new bash script, sets permissions and more
# Author: reindert
# Is there an argument?
if [[ ! $1 ]]; then
echo "Missing argument" >&2
exit 1
fi
declare open_editor=""
if [[ $# -eq 1 ]]; then
open_editor="true"
fi
while [[ $1 ]]; do
scriptname="$1"
filename="${scriptname}"
if [[ -e $filename ]]; then
echo "File ${filename} already exists" >&2
shift
continue
fi
if type "$scriptname" > /dev/null 2>&1; then
echo "There is already a command with name ${scriptname}" >&2
shift
continue
fi
# Create a script with a single line
echo '#!/bin/bash' > "$filename"
# Add executable permission
chmod u+x "$filename"
shift
done
# Open with editor
if [[ $open_editor ]]; then
echo opening
if [[ $EDITOR ]]; then
$EDITOR "$filename"
else
echo "Script created; not starting editor because \$EDITOR is not set." >&2
fi
fi
exit 0