1
1
#! /bin/bash
2
2
3
- # Function to print colored messages
4
3
RED=' \033[0;31m'
5
4
GREEN=' \033[0;32m'
6
5
YELLOW=' \033[0;33m'
7
6
BLUE=' \033[0;34m'
8
- NC=' \033[0m' # No Color
7
+ NC=' \033[0m'
9
8
10
9
print_error () {
11
10
echo -e " ${RED} Error: $1 ${NC} "
@@ -23,14 +22,11 @@ print_info() {
23
22
echo -e " ${BLUE} $1 ${NC} "
24
23
}
25
24
26
- # Install PHPV script and update PATH
27
25
install_phpv () {
28
- # Create required directories if they don't exist
29
26
print_info " Crafting directories like a master builder..."
30
27
mkdir -p " $HOME /src"
31
28
mkdir -p " $HOME /bin"
32
29
33
- # Check if phpv script exists locally, otherwise download from GitHub
34
30
if [ -f " phpv" ]; then
35
31
print_info " Found a local copy of phpv, because we believe in magic!"
36
32
else
@@ -41,15 +37,12 @@ install_phpv() {
41
37
fi
42
38
fi
43
39
44
- # Install main script
45
40
print_info " Enchanting the main script into $HOME /bin/phpv..."
46
41
cp phpv " $HOME /bin/phpv"
47
42
chmod +x " $HOME /bin/phpv"
48
43
49
- # Update PATH environment variable
50
44
print_info " Updating the enchanted PATH environment..."
51
45
52
- # Check various shell configuration files and update PATH
53
46
update_shell_config () {
54
47
local config_file=" $1 "
55
48
local shell_name=" $2 "
@@ -61,31 +54,30 @@ install_phpv() {
61
54
print_warning " PATH was already enchanted in $shell_name , no extra magic needed."
62
55
fi
63
56
else
64
- print_error " Could not find $config_file to enchant with PATH magic ."
57
+ print_warning " $config_file not found. Checking for the next shell configuration file ."
65
58
fi
66
59
}
67
60
68
- update_shell_config " $HOME /.bashrc" " bash"
69
61
update_shell_config " $HOME /.bash_profile" " bash profile"
62
+ update_shell_config " $HOME /.bashrc" " bash"
70
63
update_shell_config " $HOME /.zshrc" " zsh"
71
64
update_shell_config " $HOME /.profile" " profile"
72
65
73
- # Refresh shell configuration
74
66
print_info " Casting spells to refresh your magical settings..."
75
- source " $HOME /.bashrc" 2> /dev/null || source " $HOME /.bash_profile" 2> /dev/null || source " $HOME /.zshrc" 2> /dev/null || true
67
+ source " $HOME /.bash_profile" 2> /dev/null || \
68
+ source " $HOME /.bashrc" 2> /dev/null || \
69
+ source " $HOME /.zshrc" 2> /dev/null || \
70
+ source " $HOME /.profile" 2> /dev/null || true
76
71
77
- # Final verification
78
72
if command -v phpv > /dev/null; then
79
73
print_success " Installation complete! Your PHPV wand is now ready to wield."
80
74
else
81
75
print_error " Oops! The installation ritual failed. Time to consult the ancient scrolls of PATH configuration."
82
76
fi
83
77
84
- # Enlighten the user with PHPV incantations
85
78
print_info " To summon the powers of PHPV:"
86
79
print_info " For installation or update: phpv -i <version>"
87
80
print_info " For switching PHP versions: phpv <version>"
88
81
}
89
82
90
- # Begin the installation journey
91
83
install_phpv
0 commit comments