@@ -15,6 +15,12 @@ set -e
1515
1616VITE_PLUS_VERSION=" ${VITE_PLUS_VERSION:- latest} "
1717INSTALL_DIR=" ${VITE_PLUS_HOME:- $HOME / .vite-plus} "
18+ # Use $HOME-relative path for shell config references (portable across sessions)
19+ if case " $INSTALL_DIR " in " $HOME " /* ) true ;; * ) false ;; esac ; then
20+ INSTALL_DIR_REF=" \$ HOME${INSTALL_DIR# " $HOME " } "
21+ else
22+ INSTALL_DIR_REF=" $INSTALL_DIR "
23+ fi
1824# npm registry URL (strip trailing slash if present)
1925NPM_REGISTRY=" ${NPM_CONFIG_REGISTRY:- https:// registry.npmjs.org} "
2026NPM_REGISTRY=" ${NPM_REGISTRY%/ } "
@@ -307,13 +313,15 @@ download_and_extract() {
307313# Returns: 0 = path added, 1 = file not found, 2 = path already exists
308314add_bin_to_path () {
309315 local shell_config=" $1 "
310- local env_file=" $INSTALL_DIR /env"
311- # Escape INSTALL_DIR for grep (special regex chars become literal)
312- local install_dir_pattern
313- install_dir_pattern=$( printf ' %s' " $INSTALL_DIR " | sed ' s/[.[\*^$()+?{|]/\\&/g' )
316+ local env_file=" $INSTALL_DIR_REF /env"
317+ # Escape both absolute and $HOME-relative forms for grep (backward compat)
318+ local abs_pattern ref_pattern
319+ abs_pattern=$( printf ' %s' " $INSTALL_DIR " | sed ' s/[.[\*^$()+?{|]/\\&/g' )
320+ ref_pattern=$( printf ' %s' " $INSTALL_DIR_REF " | sed ' s/[.[\*^$()+?{|]/\\&/g' )
314321
315322 if [ -f " $shell_config " ]; then
316- if grep -q " ${install_dir_pattern} /env" " $shell_config " 2> /dev/null; then
323+ if grep -q " ${abs_pattern} /env" " $shell_config " 2> /dev/null || \
324+ grep -q " ${ref_pattern} /env" " $shell_config " 2> /dev/null; then
317325 return 2
318326 fi
319327 echo " " >> " $shell_config "
@@ -377,16 +385,18 @@ configure_shell_path() {
377385 ;;
378386 * /fish)
379387 local fish_config=" $HOME /.config/fish/config.fish"
380- # Escape INSTALL_DIR for grep (special regex chars become literal)
381- local fish_install_dir_pattern
382- fish_install_dir_pattern=$( printf ' %s' " $INSTALL_DIR " | sed ' s/[.[\*^$()+?{|]/\\&/g' )
388+ # Escape both absolute and $HOME-relative forms for grep (backward compat)
389+ local fish_abs_pattern fish_ref_pattern
390+ fish_abs_pattern=$( printf ' %s' " $INSTALL_DIR " | sed ' s/[.[\*^$()+?{|]/\\&/g' )
391+ fish_ref_pattern=$( printf ' %s' " $INSTALL_DIR_REF " | sed ' s/[.[\*^$()+?{|]/\\&/g' )
383392 if [ -f " $fish_config " ]; then
384- if grep -q " ${fish_install_dir_pattern} /env" " $fish_config " 2> /dev/null; then
393+ if grep -q " ${fish_abs_pattern} /env" " $fish_config " 2> /dev/null || \
394+ grep -q " ${fish_ref_pattern} /env" " $fish_config " 2> /dev/null; then
385395 result=2
386396 else
387397 echo " " >> " $fish_config "
388398 echo " # Vite+ bin (https://viteplus.dev)" >> " $fish_config "
389- echo " source \" $INSTALL_DIR /env.fish\" " >> " $fish_config "
399+ echo " source \" $INSTALL_DIR_REF /env.fish\" " >> " $fish_config "
390400 result=0
391401 SHELL_CONFIG_UPDATED=" config.fish"
392402 fi
@@ -690,12 +700,12 @@ main() {
690700 echo " "
691701 echo " To use vp, add this line to your shell config file:"
692702 echo " "
693- echo " . \" $INSTALL_DIR /env\" "
703+ echo " . \" $INSTALL_DIR_REF /env\" "
694704 echo " "
695705 echo " Common config files:"
696706 echo " - Bash: ~/.bashrc or ~/.bash_profile"
697707 echo " - Zsh: ~/.zshrc"
698- echo " - Fish: source \" $INSTALL_DIR /env.fish\" in ~/.config/fish/config.fish"
708+ echo " - Fish: source \" $INSTALL_DIR_REF /env.fish\" in ~/.config/fish/config.fish"
699709 fi
700710
701711 echo " "
0 commit comments