-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsystem.sh
More file actions
executable file
·248 lines (216 loc) · 8.69 KB
/
Copy pathsystem.sh
File metadata and controls
executable file
·248 lines (216 loc) · 8.69 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
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
#!/bin/bash
alias chipi.version='echo ChipScript 1.1.$(ls -1 "$SCRIPT_PATH/scripts" | wc -l) 🐿️'
function chipi.sync() {
local local_version=$(ls -1 "$SCRIPT_PATH/scripts" | wc -l)
if [[ "$1" == "silence" ]]; then
git -C "$SCRIPT_PATH" pull -q >/dev/null 2>&1
else
git -C "$SCRIPT_PATH" pull
fi
local updated_version=$(ls -1 "$SCRIPT_PATH/scripts" | wc -l)
if [[ "$1" != "silence" ]]; then
if [[ "$local_version" -lt "$updated_version" ]]; then
echo "✅ ChipScript updated! New version: 1.1.$updated_version 🐿️"
else
echo "👌 ChipScript is already up to date. Version: 1.1.$local_version 🐿️"
fi
fi
}
alias chipi.reload="source ~/.bashrc"
alias chipi.list="ls -a $SCRIPT_PATH/scripts"
alias chipi.git="git -C \"$SCRIPT_PATH\""
alias chipi.pull="git -C \"$SCRIPT_PATH\" pull"
alias chipi.push="git -C \"$SCRIPT_PATH\" push"
alias chipi.commit="git -C \"$SCRIPT_PATH\" add . && git -C \"$SCRIPT_PATH\" commit -m"
function chipi.edit() {
if [[ $1 == "--help" || $1 == "-h" ]]; then
echo "Usage: chipi.edit [system|master|directory] [script]"
echo "Description: Opens a script in the text editor (micro)."
echo " - 'system' or 'master' edits the main system scripts."
echo " - Specifying a directory and script name opens that script."
echo "Example:"
echo " chipi.edit myscript main # Edit 'main.sh' in 'myscript'"
return
fi
if [[ $1 == "master" || $1 == "system" ]]; then
micro "$SCRIPT_PATH/${1}.sh"
else
micro "$SCRIPT_PATH/scripts/${1}/${2}.sh"
fi
}
function chipi.code() {
if [[ $1 == "--help" || $1 == "-h" ]]; then
echo "Usage: chipi.code [system|master|directory]"
echo "Description: Opens VS Code in the specified directory or at the root level."
echo " - 'system' or 'master' opens VS Code at the root script directory."
echo " - Specifying a directory opens VS Code in that script folder."
echo "Example:"
echo " chipi.code myscript # Open 'myscript' directory in VS Code"
return
fi
if [[ $1 == "master" || $1 == "system" ]]; then
code "$SCRIPT_PATH/"
else
code "$SCRIPT_PATH/scripts/${1}"
fi
}
function chipi.create() {
if [[ $1 == "--help" || $1 == "-h" ]]; then
echo "Usage: chipi.create [directory]"
echo "Description: Creates a new script directory with default scripts."
echo " - This initializes a new folder with 'main.sh' and 'help.sh'."
echo "Example:"
echo " chipi.create myscript # Creates 'myscript' with default scripts"
return
fi
mkdir -p "$SCRIPT_PATH/scripts/${1}"
echo "" > "$SCRIPT_PATH/scripts/${1}/main.sh"
echo "" > "$SCRIPT_PATH/scripts/${1}/help.sh"
}
function chipi.remove() {
if [[ $1 == "--help" || $1 == "-h" ]]; then
echo "Usage: chipi.remove [directory]"
echo "Description: Deletes a specified script directory or file, with protections against removing critical scripts."
echo " - Files 'master.sh' and 'system.sh' are protected and cannot be removed."
echo "Example:"
echo " chipi.remove myscript # Deletes 'myscript' directory or file if it is not protected"
return
fi
local target_path=$(realpath "$SCRIPT_PATH/scripts/$1")
local base_name=$(basename "$target_path")
if [[ "$base_name" == "master.sh" || "$base_name" == "system.sh" ]]; then
echo -e "\033[0;31mCannot remove protected file '$base_name'.\033[0m"
else
if [[ -e "$target_path" ]]; then
rm -r "$target_path"
echo "Target '$1' removed successfully."
else
echo "Target '$1' does not exist."
fi
fi
}
function chipi.allow() {
if [[ $1 == "--help" || $1 == "-h" ]]; then
echo "Usage: chipi.allow [directory]"
echo "Description: Grants execution permissions to key scripts."
echo " - Makes 'main.sh', 'help.sh', and 'install.sh' executable."
echo "Example:"
echo " chipi.allow myscript # Grants execute permissions in 'myscript'"
return
fi
local script_directory="$SCRIPT_PATH/scripts/$1"
if [[ -d "$script_directory" ]]; then
chmod +x "$script_directory"/*.sh 2>/dev/null || echo "No scripts found in $1."
else
echo "ERROR: Script directory $1 does not exist."
fi
}
function chipi.install() {
if [[ $1 == "--help" || $1 == "-h" ]]; then
echo "Usage: chipi.install [directory]"
echo "Description: Executes 'install.sh' from the specified directory if present."
echo "Example:"
echo " chipi.install myscript # Executes 'install.sh' in 'myscript'"
return
fi
local script_directory="$SCRIPT_PATH/scripts/$1"
if [[ -d "$script_directory" ]]; then
if [[ -f "$script_directory/install.sh" ]]; then
"$script_directory/install.sh"
fi
else
echo "Script directory '$1' does not exist."
fi
}
function chipi.load() {
if [[ $1 == "--help" || $1 == "-h" ]]; then
echo "Usage: chipi.load [script]"
echo "Description: Modifies permissions, installs activation components, and executes the main.sh file from a specified script directory (modular script)."
echo " - Changes permissions using chmod to ensure executability."
echo " - Installs any dependencies or setup required by the script."
echo " - Executes the main.sh file to load the modular script's functionality."
echo "Example:"
echo " chipi.load myscript # Changes permissions, installs, and executes 'main.sh' from 'myscript' directory"
return
fi
if [[ -f "$SCRIPT_PATH/scripts/${1}/main.sh" ]]; then
chipi.allow ${1} # This function should include the chmod operation
chipi.install ${1}
source "$SCRIPT_PATH/scripts/${1}/main.sh"
else
echo "Error: No file main.sh found for ${1}"
fi
}
function chipi.help() {
if [[ $1 == "--help" || $1 == "-h" ]]; then
echo "Usage: chipi.help [script]"
echo "Description: Displays help documentation for a specified script."
echo " - Runs 'help.sh' in the script directory if present."
echo "Example:"
echo " chipi.help myscript # Shows help for 'myscript'"
return
fi
if [[ -d "$SCRIPT_PATH/scripts/${1}" ]]; then
[[ -f "$SCRIPT_PATH/scripts/${1}/help.sh" ]] && bash "$SCRIPT_PATH/scripts/${1}/help.sh" || echo "No documentation available for $1."
[[ ! -f "$SCRIPT_PATH/scripts/${1}/main.sh" ]] && echo "No Script path available at ${1}/main.sh"
else
echo "Script directory ${1} does not exist."
fi
}
function chipi() {
# Displaying general overview of ChipScript commands
echo "Chipi Command Help Overview:"
echo ""
echo "chipi.version - Displays the current version of ChipScript"
echo ""
echo "chipi.reload - Reloads the user's .bashrc file to apply new settings"
echo ""
echo "chipi.list - Lists all scripts within the specified script path"
echo ""
echo "Detailed command help:"
echo ""
# Section for editing scripts
echo "Editing scripts:"
chipi.edit --help
echo ""
# Section for opening scripts in Visual Studio Code
echo "Opening scripts in VS Code:"
chipi.code --help
echo ""
# Section for creating new script directories
echo "Creating new script directories:"
chipi.create --help
echo ""
# Section for removing script directories or files
echo "Removing script directories or files:"
chipi.remove --help
echo ""
# Section for granting execution permissions
echo "Granting execution permissions:"
chipi.allow --help
echo ""
# Section for executing 'install.sh' from a directory
echo "Executing 'install.sh' from a directory:"
chipi.install --help
echo ""
# Section for loading and executing modular scripts
echo "Loading and executing modular scripts:"
chipi.load --help
echo ""
# Section for providing help documentation
echo "Providing help documentation:"
chipi.help --help
echo ""
# Section for Git commands
echo "Git commands for script management:"
echo " chipi.git <command> - Runs Git commands in the ChipScript repo"
echo " chipi.pull - Pulls latest updates"
echo " chipi.push - Pushes committed changes"
echo " chipi.commit \"msg\" - Commits changes with a message"
echo ""
# Section for syncing scripts
echo "Synchronizing scripts:"
echo " chipi.sync - Pulls latest scripts and updates version number"
echo " chipi.sync silence - Pulls updates without any output"
echo ""
}