choco icon indicating copy to clipboard operation
choco copied to clipboard

Add PowerShell helper function to manage removing paths from $PATH

Open mrdima opened this issue 9 years ago • 27 comments

There is a useful helper Install-ChocolateyPath which I use to add directories to the PATH variable. I would like to see an Uninstall-ChocolateyPath as well to cleanup those directories from the PATH variable at uninstall time. I guess this would apply to quite a few other helpers which only have an "Install" part.

mrdima avatar Jun 05 '15 05:06 mrdima

Yep, we had something logged somewhere for these.

ferventcoder avatar Jun 05 '15 07:06 ferventcoder

Wanna open it up for grab?

tirolo avatar Nov 25 '15 16:11 tirolo

@tirolo done.

ferventcoder avatar Nov 25 '15 17:11 ferventcoder

Just for an idea, wouldn't it be nice if the auto-uninstaller would be able to take care of this as well? Either snapshot the environment before and after the install (or only PATH environment variable) or have Install-Chocolatey log something for the uninstall

mrdima avatar Nov 25 '15 18:11 mrdima

Sounds nice - keep in mind it should only remove the added values and not restore the previous version (that would be bad).

ferventcoder avatar Nov 25 '15 18:11 ferventcoder

Will start working on this one as soon as I get my read around the docs I have to read before start contributing + learn some github :smile: (shouldn't take long)

tirolo avatar Nov 26 '15 12:11 tirolo

@ferventcoder Should I target master?

tirolo avatar Nov 26 '15 12:11 tirolo

@tirolo master is set for 0.9.11.x, and stable is set for 0.9.10.x. I'd target stable if you can.

ferventcoder avatar Nov 26 '15 13:11 ferventcoder

There was a PR for this in the old chocolatey repo https://github.com/chocolatey/chocolatey/pull/542

sindux avatar Jan 01 '16 08:01 sindux

Moving discussion back over to here, @DarwinJS See - #303

ferventcoder avatar Jan 07 '16 21:01 ferventcoder

Not sure if it's still relevant, but here is a link to the code I put together for this today. The code I did also handles removing duplicates (if the path to remove is in more than once), handles the path whether or not there is a trailing slash versus what is specified on the removal string and it handles removing extra ";' that are found. The code is not generalized to handle both user and machine path. https://github.com/DarwinJS/ChocoPackages/blob/master/ec2clitools/tools/chocolateyuninstall.ps1

DarwinJS avatar Jan 08 '16 02:01 DarwinJS

This is related to https://github.com/chocolatey/choco/issues/303

ferventcoder avatar Jan 29 '16 15:01 ferventcoder

I'll take this one.

DarwinJS avatar Oct 13 '16 17:10 DarwinJS

I am wondering a few things about this code: *) Does it make sense to remove the requested string from both user and computer path? On one hand if I was requesting a removal I would just want it gone no matter what paths it appeared on if the software was just removed. On the other hand it may make uninstalls reach to things that weren't instended.

Hmmm - what if it could take params "user", "machine" and "all" ? Should it default to "All" if unspecified or just always require the param?

DarwinJS avatar Oct 14 '16 22:10 DarwinJS

PR: https://github.com/chocolatey/choco/pull/1019

DarwinJS avatar Oct 19 '16 09:10 DarwinJS

Are there any plans to merge the PR fixing this issue? Seems like this is being pushed to next milestones since Mar 22.

improbablepiotr avatar Sep 07 '17 12:09 improbablepiotr

@improbablepiotr yes, there are plans to merge. We've had a few higher priority things come in during the interim.

ferventcoder avatar Sep 07 '17 15:09 ferventcoder

What's the recommended way to remove a path installed with Install-ChocolateyPath? Not doing so pops a guideline warning when publishing a package.

Thieum avatar Jun 28 '18 20:06 Thieum

Hi guys, do you have an ETA on when you are planing to merge this feature? I'm currently handling it manually but quite a bit of logic has to go in to make it reasonable robust (expand tokens, handle duplicated entries, handle empty paths, handle empty semicolons, etc)

aaccioly avatar Jul 11 '19 16:07 aaccioly

So, 4 years later... still nothing? :)

bazzilic avatar Nov 01 '19 11:11 bazzilic

I have a PR up at https://github.com/chocolatey/choco/pull/1663.

jnm2 avatar Nov 01 '19 12:11 jnm2

which was created over a year ago...

bazzilic avatar Nov 01 '19 12:11 bazzilic

Another bump, this addition would be very helpful for package creation.

patmilano avatar Nov 13 '19 20:11 patmilano

Just in case it may be helpful to anyone, this is how @DarwinJS did it - posting it here since the original repo was moved to GitLab: https://gitlab.com/DarwinJS/ChocoPackages/-/blob/master/ec2clitools/tools/chocolateyuninstall.ps1

I just tested it, works pretty well.

simonewebdesign avatar May 25 '20 08:05 simonewebdesign

Thanks, but would be nice if #1663 can be merged (or at least reviewed). Currently that PR seems to be simply ignored, I assume because it never got priority.

FranklinYu avatar Jun 07 '20 07:06 FranklinYu

Bumping with my vote for this. It's in the homestretch; someone just needs to put on the gloves and give it a little polish.

teknowledgist avatar Aug 16 '22 13:08 teknowledgist

I suggested some changes on #1663 and have been using a modified version for over a year. Hasn't destroyed anyone's PATH as far as I can tell.

jmcker avatar Aug 17 '22 04:08 jmcker

:tada: This issue has been resolved in version 2.3.0 :tada:

The release is available on:

Your GitReleaseManager bot :package: :rocket:

choco-bot avatar Jun 05 '24 13:06 choco-bot