-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.sh
executable file
·133 lines (91 loc) · 2.98 KB
/
test.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/bin/bash
RED='\033[0;31m'
ORG='\033[0;33m'
GRN='\033[1;32m'
LBL='\033[1;34m'
CYN='\033[1;36m'
PRP='\033[1;35m'
CLR='\033[0m'
finish(){
echo -e "${CLR}"
}
trap finish EXIT
echo;
echo -e "
This script performs various actions by default.
First it will create a ${LBL}bin${CLR} directory in your home folder (if one doesn't exist)
and add it to your \$PATH variable (via ${CYN}.bash_profile${CLR} or ${CYN}.bashrc${CLR}).
It will then create a ${LBL}.templates${CLR} directory in your home folder with various
template files for use with ${GRN}new${CLR}.
The ${GRN}new${CLR} command is added to ${LBL}${HOME}/bin${CLR} and is used to create a
new file based on a template within the above mentioned ${LBL}.templates${CLR} directory.
It will then exit into your default editor. If no default editor is defined within your
profile it will exit into vim or nano, whichever is found first (checked in that order).
You have five seconds to exit this script with ^c (CTRL + c)..."
echo
for i in {5..1}; do
echo -en "${RED}${i}${CLR} ";
sleep 1
done
echo
[ -d ${HOME}/bin ] && echo -e "\t ${ORG}${HOME}/bin exists${CLR}" || { mkdir ${HOME}/bin; echo -e "\t ${LBL}${HOME}/bin created${CLR}"; }
[ -d ${HOME}/.templates ] && echo -e "\t ${ORG}${HOME}/.templates exists${CLR}" || { mkdir ${HOME}/.templates; echo -e "\t ${LBL}${HOME}/.templates created${CLR}"; }
[ ! -f ${HOME}/bin/new ] && {
cat << EONF > ${HOME}/bin/new
#!/bin/bash
[ -x \$(which vim) ] && EDITOR=\${EDITOR:-\$(which vim)} || EDITOR=\${EDITOR:-\$(which nano)}
usage() {
echo -e "
USAGE: new [type] [(path/)filename]
Create a new file [filename] from an existing template.
[type] must match an existing template in
your \${HOME}/.templates directory.
Currently available templates:
"
for t in \${HOME}/.templates/*; do
echo " \$(basename \${t})"
done
echo -e "
(path/) is relative to your current directory and any
directories in this path must already exist.
"
exit
}
[ \$# -lt 2 ] && usage
[ ! -f "\${HOME}/.templates/\$1" ] && { echo "\$1 template does not exist"; exit 1; }
cp "\${HOME}/.templates/\$1" "\${2}"
exec \$EDITOR \$2
EONF
chmod +x "${HOME}/bin/new"
echo -e "\t ${GRN}${HOME}/bin/new created${CLR}"
}
[ ! -f ${HOME}/.templates/shell ] && {
cat << EOTSF > ${HOME}/.templates/shell
#!/bin/bash
exit
EOTSF
chmod +x ${HOME}/.templates/shell
echo -e "\t template ${PRP}shell${CLR} added"
}
[ ! -f ${HOME}/.templates/python ] && {
cat << EOTPF > ${HOME}/.templates/python
#!/usr/bin/env python
import os
import sys
def main():
##
if __name__ == '__main__':
main()
EOTPF
chmod +x ${HOME}/.templates/python
echo -e "\t template ${PRP}pythone${CLR} added"
}
[ -f ${HOME}/.bash_profile ] && PROF=${HOME}/.bash_profile
[ -f ${HOME}/.bashrc ] && PROF=${PROF:-${HOME}/.bashrc}
echo "$PATH" | grep -q "${HOME}/bin" || {
echo 'export PATH=${PATH}:${HOME}/bin' >> ${PROF};
}
echo -e "\t added ${HOME}/bin to user \$PATH"
echo
echo -e "Completed. Test now by running ${GRN}new${CLR} ${PRP}shell${CLR} ${LBL}bin/test${CLR}"
exit