DVM - D Version Manager
"Jérôme M. Berger"
jeberger at free.fr
Thu Jan 27 14:34:48 PST 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 at free.fr
http://jeberger.free.fr
Jabber: jeberger at jabber.fr
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: OpenPGP digital signature
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-announce/attachments/20110127/dff8006c/attachment.pgp>
More information about the Digitalmars-d-announce
mailing list