-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmshx
More file actions
executable file
·139 lines (112 loc) · 3.81 KB
/
Copy pathmshx
File metadata and controls
executable file
·139 lines (112 loc) · 3.81 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
#!/bin/bash
MSH_COMMAND="msh"
MSHX_COMMAND="mshx"
MSH_HOME_DIR="$MSH_HOME"
function help_command(){
echo " __ ____"
echo " ____ ___ __ _______/ /_ ___ / / /"
echo " / __ __ \/ / / / ___/ __ \/ _ \/ / / "
echo " / / / / / / /_/ (__ ) / / / __/ / / "
echo " /_/ /_/ /_/\__, /____/_/ /_/\___/_/_/ "
echo " /____/ msh eXtension"
echo ""
echo "Usage: mshx <command>"
echo ""
echo "<...> = required"
echo "[...] = optional"
echo ""
echo "Commands:"
echo " help|h - Get help for mshx"
echo ""
echo " install|i <extension-name> [collection-name] - Clone a collection from a git repository"
echo " extension-name - The name of the extension to install in the format 'username/repo'"
echo ""
echo " list|ls - List all available extensions"
}
function get_extension_url(){
extension="$1"
if [[ ! "$extension" == *"https://"* ]] && [[ ! "$extension" == *"http://"* ]]; then
extension="https://github.com/$extension-mshx.git"
fi
echo "$extension"
}
function install_command(){
extension="$2"
if [ -z "$extension" ]; then
echo "No extension specified. Type 'mshx help' for help."
exit 1
fi
# exit when extension does not contain a slash
if [[ ! "$extension" == *"/"* ]]; then
echo "Invalid extension name. Type 'mshx help' for help."
exit 1
fi
echo "Installing extension $extension..."
extension=$(get_extension_url "$extension")
# check if the repository exists
if ! git ls-remote "$extension" &> /dev/null; then
echo "Could not find the repository: $extension"
exit 1
fi
coll_path=$($MSH_COMMAND collection clone "$extension" -print-path)
deps_file="$coll_path/dependencies.list"
if [ -f "$deps_file" ]; then
echo "Installing dependencies for $extension..."
all_coll="$($MSH_COMMAND collection list)"
for dep in $(cat "$deps_file"); do
echo ""
echo "Installing dependency $dep..."
dep_url=$(get_extension_url "$dep")
if [[ "$all_coll" == *"$dep_url"* ]]; then
echo "Dependency $dep already installed."
continue
fi
install_command "$dep_url" "$dep_url"
done
echo ""
fi
echo "Extension $extension installed successfully."
}
function list_command(){
echo "Extensions:"
extension_list_url="https://raw.githubusercontent.com/cophilot/msh/refs/heads/main/extensions.list"
extension_list=$(curl -s $extension_list_url)
while IFS= read -r line; do
url="https://github.com/$line-mshx.git"
if ! git ls-remote "$url" &> /dev/null; then
continue
fi
# get the github description
description=$(curl -s "https://api.github.com/repos/$line-mshx" | jq -r '.description')
if [ "$description" == "null" ]; then
description=""
else
description="- $description"
fi
echo " $line $description($url)"
done <<< "$extension_list"
}
if [ "${@: -1}" == "-dev" ]; then
MSH_COMMAND="./out/msh"
MSHX_COMMAND="./mshx"
MSH_HOME_DIR=".myshell"
echo "Running in development mode..."
fi
command="$1"
if [ -z "$command" ]; then
echo "No command specified. Type 'mshx help' for help."
exit 1
fi
if [ "$command" == "help" ] || [ "$command" == "h" ] || [ "$command" == "-help" ] || [ "$command" == "--help" ] || [ "$command" == "-h" ] || [ "$command" == "--h" ]; then
help_command
exit 0
fi
if [ "$command" == "install" ] || [ "$command" == "i" ]; then
install_command $@
exit 0
fi
if [ "$command" == "list" ] || [ "$command" == "ls" ]; then
list_command
exit 0
fi
echo "Command not found. Type 'mshx help' for help."