January 27, 2011
Jacob Carlborg wrote:
> On 2011-01-26 21:04, "Jérôme M. Berger" wrote:
>>     You cannot. You need to modify the environment for the current
>> shell, which is the shell that the user is currently using (no
>> matter what else may or may not be installed on the system). This
>> has two consequences:
>>
>> - You need to have some code that is run when the shell starts (i.e. from .bashrc, .zshrc or .kshrc). That code will define the proper aliases and/or functions (at the time being, this is mostly the "dvm" function in "dvm.sh" (*)). This can be accomplished by having a different version of this file for each shell;
> 
> Is it possible to detect what shell is running and then load the correct version?
> 
	Since each shell sources a different file on startup, you can
source the correct version from the startup file. On installation,
the SHELL environment variable should tell you which shell is used.

>> - You need to generate the contents of $dvm_result_path in a format that the shell will understand. The easiest way to do that is probably to define a few extra functions in "dvm.sh" to enable setting environment variables in a portable way and handle additional requirements (like "builtin hash -r" which is definitely a bash-ism). Then generate the $dvm_result_path using these functions instead of the normal shell syntax.
> 
> The contents of $dvm_result_path will only export one variable.
> 
	Do not you need to call "builtin hash -r" each time you change the
path (I do not know since I am not a bash user)? If not, why do you
need to call it in __dvm_setup_environment?

>>         Jerome
>>
>> (*) BTW, I hope you do not add the full contents of dvm.sh nor a "source dvm.sh" in .bashrc the way it is now. Otherwise, a misconfiguration may prevent the user from starting a shell!
> 
> OK, how else can I do the same thing? BTW this is how RVM (Ruby Version Manager) works, where I got the idea from. The whole RVM is written in shell script and it's sourced in .bashrc.
> 
	Remove the call to exit and wrap the rest of the file in a "if [[ !
-z "$dvm_prefix" ]] ; then ..." So the file will look like:

==============================8<------------------------------ if [[ -z "$dvm_prefix" ]] ; then

        if [[ -n "$HOME" ]] ; then
        dvm_prefix="$HOME/."
        else
        echo "No \$dvm_prefix was provided and "
        echo "$(id | \sed -e's/^[^(]*(//' -e 's/).*//') has no
\$HOME defined."
        fi
fi

if [[ ! -z "$dvm_prefix" ]] ; then
	...
fi
------------------------------>8==============================

		Jerome
-- 
mailto:jeberger@free.fr
http://jeberger.free.fr
Jabber: jeberger@jabber.fr



January 28, 2011
On 2011-01-27 23:34, "Jérôme M. Berger" wrote:
> Jacob Carlborg wrote:
>> On 2011-01-26 21:04, "Jérôme M. Berger" wrote:
>>>      You cannot. You need to modify the environment for the current
>>> shell, which is the shell that the user is currently using (no
>>> matter what else may or may not be installed on the system). This
>>> has two consequences:
>>>
>>> - You need to have some code that is run when the shell starts (i.e.
>>> from .bashrc, .zshrc or .kshrc). That code will define the proper
>>> aliases and/or functions (at the time being, this is mostly the
>>> "dvm" function in "dvm.sh" (*)). This can be accomplished by having
>>> a different version of this file for each shell;
>>
>> Is it possible to detect what shell is running and then load the correct
>> version?
>>
> 	Since each shell sources a different file on startup, you can
> source the correct version from the startup file. On installation,
> the SHELL environment variable should tell you which shell is used.

Ah, right. Didn't think of that.

>>> - You need to generate the contents of $dvm_result_path in a format
>>> that the shell will understand. The easiest way to do that is
>>> probably to define a few extra functions in "dvm.sh" to enable
>>> setting environment variables in a portable way and handle
>>> additional requirements (like "builtin hash -r" which is definitely
>>> a bash-ism). Then generate the $dvm_result_path using these
>>> functions instead of the normal shell syntax.
>>
>> The contents of $dvm_result_path will only export one variable.
>>
> 	Do not you need to call "builtin hash -r" each time you change the
> path (I do not know since I am not a bash user)? If not, why do you
> need to call it in __dvm_setup_environment?

I don't know actually. I'll have to test that.

>>>          Jerome
>>>
>>> (*) BTW, I hope you do not add the full contents of dvm.sh nor a
>>> "source dvm.sh" in .bashrc the way it is now. Otherwise, a
>>> misconfiguration may prevent the user from starting a shell!
>>
>> OK, how else can I do the same thing? BTW this is how RVM (Ruby Version
>> Manager) works, where I got the idea from. The whole RVM is written in
>> shell script and it's sourced in .bashrc.
>>
> 	Remove the call to exit and wrap the rest of the file in a "if [[ !
> -z "$dvm_prefix" ]] ; then ..." So the file will look like:
>
> ==============================8<------------------------------
> if [[ -z "$dvm_prefix" ]] ; then
>
>          if [[ -n "$HOME" ]] ; then
>          dvm_prefix="$HOME/."
>          else
>          echo "No \$dvm_prefix was provided and "
>          echo "$(id | \sed -e's/^[^(]*(//' -e 's/).*//') has no
> \$HOME defined."
>          fi
> fi
>
> if [[ ! -z "$dvm_prefix" ]] ; then
> 	...
> fi
> ------------------------------>8==============================
>
> 		Jerome

Yeah, I kind of notice that. The "exit" didn't work out that well.

-- 
/Jacob Carlborg
1 2 3 4 5
Next ›   Last »