forked from Crois-En-Toi/Template-Automater
-
Notifications
You must be signed in to change notification settings - Fork 0
/
autotemp
executable file
·65 lines (56 loc) · 1.87 KB
/
autotemp
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
#!/bin/bash
#This file consist's of the main script to run the tool
# for adding the given template
if [[ $1 == "--add" ]]
then
if [[ -d "$HOME/.config/Autotemp/templates" ]]
then
touch "$HOME/.config/Autotemp/templates/$2.txt"
echo "Enter the contents of template"
cat > "$HOME/.config/Autotemp/templates/$2.txt"
printf "\n"
echo "=================================================="
echo "Template $2 succesfully created the contents are:"
echo "=================================================="
printf "\n"
cat "$HOME/.config/Autotemp/templates/$2.txt"
fi
# list out all existing templates
elif [[ $1 == "-l" ]]
then
ls "$HOME/.config/Autotemp/templates/"
# printf all the content in the given template
elif [[ $1 == "-pf" ]]
then
more "$HOME/.config/Autotemp/templates/$2.txt"
# gives specific path to where the template is to be written over (file must already exist)
elif [[ $1 == "-p" ]]
then
cat "$HOME/.config/Autotemp/templates/$2.txt" >> "$3"
# for editing the template file
elif [[ $1 == "-e" ]]
then
echo "Opening $2 file in vim, do edit as required"
vim "$HOME/.config/Autotemp/templates/$2.txt"
# for removing a template file
elif [[ $1 == "-r" ]]
then
echo "Removing File $2 from the template store"
rm "$HOME/.config/Autotemp/templates/$2.txt"
# help function to tell more about the command usage
elif [[ $1 == "--help" || $1 == "--h" ]]
then
more "$HOME/.config/Autotemp/help.txt"
else
if [[ $# -eq 1 ]]
then
echo "invalid input use autotemp --help for help"
else
if [[ -f "$HOME/.config/Autotemp/templates/$1.txt" ]]
then
cat "$HOME/.config/Autotemp/templates/$1.txt" | tee -a "${@:2}" > "/dev/null"
else
echo "provided template doesnot exist create one using --add "
fi
fi
fi