-
Notifications
You must be signed in to change notification settings - Fork 0
/
sublime
executable file
·116 lines (105 loc) · 2.43 KB
/
sublime
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
#!/bin/bash
# If no arguments, open sublime
if [ $# = 0 ]; then
subl
exit 0
fi
# If installation directory missing
if [ ! -d ~/.template ]; then
mkdir ~/.template
fi
# If create command
if [ $1 = 'create' ]; then
# Check arguments
if [ $# = 3 ]; then
# Make the name and file pair
mkdir ~/.template/$2
cp $3 ~/.template/$2/template
else
# Command format invalid
echo "Format: sublime create < name > < template file >"
exit 0
fi
# If modify command
elif [ $1 = 'modify' ]; then
# Check arguments
if [ $# = 4 ]; then
if [ -d ~/.template/$2 ]; then
# Check modification type
if [ $3 = '-f' ]; then
# Modify the template
cp -f $4 ~/.template/$2/template
elif [ $3 = '-j' ]; then
# Modify the jump in file
echo -n ":$4" > ~/.template/$2/jump
else
# Type unknown
echo "Unknown modification type"
exit 0
fi
else
# Template not found
echo "Invalid template name: $2"
exit 0
fi
else
# Command format invalid
echo "Format: sublime modify < name > < type > < value >"
exit 0
fi
# If delete command
elif [ $1 = 'delete' ]; then
# Check command validity
if [ $# = 2 ]; then
# Check template availability
if [ -d ~/.template/$2 ]; then
# Remove template and notify
rm -rf ~/.template/$2
echo "Removed template: $2"
else
# Notify unavialable template
echo "No such template $2"
echo "Use 'sublime list' to see all templates"
fi
fi
# If show command
elif [ $1 = 'list' ]; then
# Show all template names
ls -l1 ~/.template/ | awk '/^d/ {printf("%s ", $NF)} END{printf "\n"}'
# If executable command
elif [ $1 = '+x' ]; then
# Make all files executable and open them
while [ $# -gt 1 ]; do
touch $2
chmod +x $2
subl $2
shift
done
# If command has a name of template
elif [ "`echo $1 | grep -- --`" != "" ]; then
# Get the template_type
template_type=`echo $1 | sed 's/^..//'`
# Check if the template exists
if [ -d ~/.template/$template_type -a -r ~/.template/$template_type/template ]; then
# Copy the template file and open
while [ $# -gt 1 ]; do
touch $2
cp ~/.template/$template_type/template $2
if [ -r ~/.template/$template_type/jump ]; then
subl $2`cat ~/.template/$template_type/jump`
else
subl $2
fi
shift
done
else
# Invalid template
echo "Invalid template name: $template_type"
exit 0
fi
# None of the above arguments
else
# Open sublime with arguments
exec /opt/sublime_text/sublime_text "$@"
exit 0
fi