-
Notifications
You must be signed in to change notification settings - Fork 0
/
mshx
executable file
·99 lines (82 loc) · 2.85 KB
/
mshx
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
#!/bin/bash
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 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..."
if [[ ! "$extension" == *"https://"* ]] && [[ ! "$extension" == *"http://"* ]]; then
extension="https://github.com/$extension-mshx.git"
fi
# check if the repository exists
if ! git ls-remote "$extension" &> /dev/null; then
echo "Could not find the repository: $extension"
exit 1
fi
msh collection clone "$extension" --q
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"
}
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."