-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
72 lines (63 loc) · 1.94 KB
/
install.sh
File metadata and controls
72 lines (63 loc) · 1.94 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
#!/usr/bin/env bash
# Check if git is installed
if ! command -v git &> /dev/null; then
echo "Error: git is not installed. Please install git first."
exit 1
fi
# Clone xvm repository
if [ -d "$HOME/.xvm" ]; then
echo "Directory ~/.xvm already exists. Please remove it first."
exit 1
fi
git clone https://github.com/duan0120/xvm.git "$HOME/.xvm"
# Detect current shell
current_shell=$(basename "$SHELL")
# Add environment variables to shell config files
add_to_shell_config() {
local config_file="$1"
local shell_name="$2"
if [ -f "$config_file" ]; then
if ! grep -q "export XVM_ROOT" "$config_file"; then
echo "Adding XVM configuration to $config_file for $shell_name..."
echo -e "\n# XVM" >> "$config_file"
echo "export XVM_ROOT=~/.xvm" >> "$config_file"
echo '[ -s "$XVM_ROOT/xvm" ] && . "$XVM_ROOT/xvm"' >> "$config_file"
fi
fi
}
# Configure based on detected shell
case "$current_shell" in
"bash")
add_to_shell_config "$HOME/.bashrc" "bash"
;;
"zsh")
add_to_shell_config "$HOME/.zshrc" "zsh"
;;
*)
echo "Warning: Unsupported shell detected ($current_shell)"
add_to_shell_config "$HOME/.bashrc" "bash"
add_to_shell_config "$HOME/.zshrc" "zsh"
;;
esac
echo -e "\nInstallation Summary:"
echo "------------------------"
echo "✓ XVM repository cloned to: $HOME/.xvm"
echo "✓ Environment variables configured"
echo "✓ Shell integration completed"
echo -e "\nTo activate XVM in current session:"
case "$current_shell" in
"bash")
echo "Run: source ~/.bashrc"
source "$HOME/.bashrc"
;;
"zsh")
echo "Run: source ~/.zshrc"
source "$HOME/.zshrc"
;;
*)
echo "Please run one of the following commands:"
echo " source ~/.bashrc # for bash"
echo " source ~/.zshrc # for zsh"
;;
esac
echo -e "\nXVM is now ready to use!"