-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmkscript
More file actions
executable file
·104 lines (91 loc) · 2.22 KB
/
mkscript
File metadata and controls
executable file
·104 lines (91 loc) · 2.22 KB
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
#!/usr/bin/env bash
if [ -z "$1" ]; then
echo -e "No command provided, please choose what you would like to do:"
echo -e "\t1.\tcreate"
echo -e "\t2.\tedit"
echo -e "\t3.\list"
read -p "Enter choice [1|2|3]: " cmd_choice
case $cmd_choice in
1)
command="new"
;;
2)
command="edit"
;;
3)
command="list"
;;
*)
echo "Invalid input"
exit 1
;;
esac
else
command="$1"
fi
if [ -z "$2" ]; then
echo -e "No script name provided, please enter a script name to\ncreate/edit/list:"
read -p "Script name: " script_name
else
script_name="$2"
echo -e "Script name:\t$script_name"
fi
jffs_path="/home/kallefornia/coding/bash/"
script_path="${jffs_path}${script_name}"
declare -A script_index
matched_scripts_count="$(ls -FA $jffs_path | grep -i $script_name | grep -c -i -e [\*$])"
list_counter=1
while IFS='\n' read -r name; do
script_index[$list_counter]="$name"
# echo -e "$list_counter: $name"
((list_counter++))
done < <(ls -FA $jffs_path | grep -i $script_name | grep -i -e [\*$] | awk -F'*' '{print $1}')
new_script(){
touch $script_path &&
chmod +x $script_path &&
ln -s ${script_path}/usr/bin/$script_name &&
nano $script_path
}
list_scripts(){
for key in ${!script_index[@]}; do
name="${script_index[$key]}"
echo -e "${key}.\t${name}"
done
}
chose_script(){
echo "Choose script to edit"
read -p "[0-${matched_scripts_count}]: " script_choice
echo "${script_index[${script_choice}]}"
}
edit_script(){
if [[ $matched_scripts_count -gt 1 ]]; then
echo "more than one possible match, please choose script:"
list_scripts
echo "Choose script to edit"
read -p "[0-${matched_scripts_count}]: " script_choice
selected_script="${script_index[${script_choice}]}"
echo "Opening $selected_script"
nano ${jffs_path}${selected_script}
else
script_found=$(ls -FA $jffs_path | grep -i $script_name | grep -i -e [\*$] | awk -F'*' '{print $1}')
nano $script_found
fi
}
case $command in
list)
echo -e "found the following scripts matching \"$script_name\""
list_scripts
exit 0
;;
new)
echo -e "creating new script \"$script_name\" in $jffs_path..."
new_script
exit 0
;;
edit)
echo -e "Looking for scripts to edit matching \"$script_name\""
edit_script
exit 0
;;
esac
exit 0