-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd_bash_templates
42 lines (36 loc) · 1.03 KB
/
add_bash_templates
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
#!/bin/bash
########################## - add bash templates to file - ##############################
# vars
new_file=$1
if [ "$new_file" == "" ]; then
new_file='tmp.sh'
fi
template_file='bash_templates' # <<<<<< ADD PATH HERE
templates=$(echo "$(cat $template_file | grep '_')" | grep '#_' | sed 's/[0-9]//g' | awk '{print $2}' | grep "_")
# loops
for tem in $templates
do
((i++))
printf "%s %s\n" "$i" "$tem"
saved+=($tem)
done
read choice
[ "$choice" == "exit" ] && exit
second_chosen=$(cat $template_file | grep "#_ " | grep ${saved[$choice]})
tw=$((choice-=1))
chosen=$(cat $template_file | grep "#_ " | grep ${saved[$tw]})
while read line; do
((num_lines+=1))
if [ "$line" == "$chosen" ]; then
top_lines=$num_lines
fi
if [ "$line" == "$second_chosen" ]; then
bottom_lines=$num_lines
fi
done < $template_file
while read line; do
((count+=1))
if [[ $top_lines -le $count ]] && [[ $bottom_lines -gt $count ]]; then
echo $line >> $new_file
fi
done < $template_file