Skip to content

Commit c5a7de0

Browse files
committed
Refactor install.sh to make phpvm binary executable and handle version fetching errors
1 parent 7a2117d commit c5a7de0

File tree

2 files changed

+6
-61
lines changed

2 files changed

+6
-61
lines changed

bin/install.sh

Lines changed: 1 addition & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -84,41 +84,6 @@
8484
phpvm_echo >&2 'Failed to install Node.js dependencies. Please report this!'
8585
exit 1
8686
}
87-
88-
# Make the phpvm binary executable
89-
phpvm_echo "=> Making phpvm binary executable"
90-
chmod +x "$INSTALL_DIR/bin/phpvm" || {
91-
phpvm_echo >&2 'Failed to set execute permissions on phpvm binary. Please report this!'
92-
exit 1
93-
}
94-
}
95-
96-
phpvm_detect_profile() {
97-
if [ "${PROFILE-}" = '/dev/null' ]; then
98-
return
99-
fi
100-
101-
if [ -n "${PROFILE}" ] && [ -f "${PROFILE}" ]; then
102-
phpvm_echo "${PROFILE}"
103-
return
104-
fi
105-
106-
local SHELL_TYPE
107-
SHELL_TYPE="$(basename "$SHELL")"
108-
109-
if [ "$SHELL_TYPE" = "bash" ]; then
110-
if [ -f "$HOME/.bashrc" ]; then
111-
phpvm_echo "$HOME/.bashrc"
112-
elif [ -f "$HOME/.bash_profile" ]; then
113-
phpvm_echo "$HOME/.bash_profile"
114-
fi
115-
elif [ "$SHELL_TYPE" = "zsh" ]; then
116-
if [ -f "$HOME/.zshrc" ]; then
117-
phpvm_echo "$HOME/.zshrc"
118-
elif [ -f "$HOME/.zprofile" ]; then
119-
phpvm_echo "$HOME/.zprofile"
120-
fi
121-
fi
12287
}
12388

12489
inject_phpvm_config() {
@@ -128,37 +93,14 @@
12893
PROFILE_INSTALL_DIR="$(phpvm_install_dir | command sed "s:^$HOME:\$HOME:")"
12994

13095
PHPVM_CONFIG_STR="
131-
132-
# Set up PHPVM environment
133-
export PHPVM_DIR=\"${PROFILE_INSTALL_DIR}\"
134-
135-
# Only source phpvm if it's needed (for auto-switching versions)
136-
phpvm_auto_switch_on_cd() {
137-
local PHPVMRC_FILE=\"\$(phpvm_find_phpvmrc)\"
138-
if [ -n \"\$PHPVMRC_FILE\" ]; then
139-
local PHP_VERSION=\$(cat \"\$PHPVMRC_FILE\")
140-
if [ -n \"\$PHP_VERSION\" ]; then
141-
phpvm use \$PHP_VERSION
142-
else
143-
echo 'No PHP version specified in .phpvmrc'
144-
fi
145-
fi
146-
}
147-
148-
# Update 'cd' command to automatically switch versions based on .phpvmrc
149-
cd() {
150-
builtin cd \"\$@\" || return
151-
phpvm_auto_switch_on_cd
152-
}
153-
15496
# Load PHPVM if necessary (this will allow phpvm to be invoked manually)
15597
if [ -s \"\$PHPVM_DIR/index.js\" ]; then
15698
export PATH=\"\$PHPVM_DIR/bin:\$PATH\"
15799
fi
158100
"
159101

160102
if [ -n "$PHPVM_PROFILE" ]; then
161-
if ! command grep -qc 'phpvm_auto_switch_on_cd' "$PHPVM_PROFILE"; then
103+
if ! command grep -qc '/phpvm/index.js' "$PHPVM_PROFILE"; then
162104
phpvm_echo "=> Injecting phpvm config into $PHPVM_PROFILE"
163105
echo -e "$PHPVM_CONFIG_STR" >>"$PHPVM_PROFILE"
164106
else

lib/utils/phpvmrc.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,24 @@ function findPHPVMRCFile(startDir = process.cwd()) {
2626
* Automatically switch to the PHP version specified in the .phpvmrc file
2727
*
2828
* This function is meant to be called when the shell is started.
29+
* It remains silent if no .phpvmrc file is found.
2930
*/
3031
async function autoSwitchPHPVersion() {
3132
const phpvmrcPath = findPHPVMRCFile();
3233

3334
if (phpvmrcPath) {
3435
const version = fs.readFileSync(phpvmrcPath, 'utf8').trim();
35-
console.log(`Found .phpvmrc file. PHP version specified: ${version}`);
3636

3737
// Switch to the specified version
3838
try {
39-
await usePHPVersion(version); // Use your existing 'use' command logic
39+
await usePHPVersion(version); // Use the existing 'use' command logic
4040
console.log(`Switched to PHP ${version}`);
4141
} catch (error) {
4242
console.error(`Failed to switch to PHP ${version}: ${error.message}`);
4343
}
44+
} else {
45+
// Silent if no .phpvmrc file is found
46+
return;
4447
}
4548
}
4649

0 commit comments

Comments
 (0)