Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Argument to only add Scoop to $PATH for the current session. #5574

Closed
scyilk opened this issue Jul 10, 2023 · 9 comments
Closed

[Feature] Argument to only add Scoop to $PATH for the current session. #5574

scyilk opened this issue Jul 10, 2023 · 9 comments

Comments

@scyilk
Copy link

scyilk commented Jul 10, 2023

Feature Request

Is your feature request related to a problem? Please describe.

I would like to be able to run Scoop on a USB flash drive in a portable manner. Although I haven't tried to do this yet, I predict that there would be a PATH pollution problem. This could happen because Scoop adds itself to the PATH of the machine, not just for the duration of the terminal session, but forever.

Describe the solution you'd like

I would like to be able to run Scoop with an argument such as --add-to-path-temporarily which would silently exit after adding itself to the $PATH environment variable for the duration of the session. In case of an error, it would log it to standard output and to any applicable log files.

Describe alternatives you've considered

Maybe an alternative would be to remove any pollution afterwards with a script or something of the like, though this does add unneeded complexity that could be avoided if this could be prevented in the first place.

@HUMORCE
Copy link
Member

HUMORCE commented Jul 10, 2023

When you put Scoop on portable drive, then:

  1. You might executing Scoop via fullpach. (x:\scoop\apps\scoop\current\scoop.ps1)
  2. You might add shim dir to PATH, then use it normally

Whichever method you use, you can benefit from #5544

For now:

Just set environment via: $env:SCOOP = <SCOOP_ROOT_DIRECTORY>

e.g.:

❯ scoop bucket list

Name     Source                                     Updated               Manifests
----     ------                                     -------               ---------
main     [email protected]:ScoopInstaller/Main.git     7/10/2023 12:30:48 PM      1207
extras   [email protected]:ScoopInstaller/Extras.git   7/10/2023 12:30:37 PM      1881
versions [email protected]:ScoopInstaller/Versions.git 7/10/2023 12:57:14 PM       425
nirsoft  [email protected]:kodybrown/scoop-nirsoft.git 7/7/2023 3:25:27 PM         275
java     [email protected]:ScoopInstaller/Java.git     7/9/2023 4:19:30 PM         253
nuke     [email protected]:HUMORCE/nuke.git            7/10/2023 12:03:15 PM       144

~
❯ $env:SCOOP = "X:\Scoop"
~
❯ scoop bucket list
Get-ChildItem: C:\Users\humorce\scoop\apps\scoop\current\lib\buckets.ps1:61
Line |
  61 |  … eneric.List[String]](Get-ChildItem -Path $bucketsdir -Directory).Name
     |                                                         ~~~~~~~~~~
     | A parameter cannot be found that matches parameter name 'Directory'.

WARN  No bucket found. Please run 'scoop bucket add main' to add the default 'main' bucket.

@scyilk
Copy link
Author

scyilk commented Jul 10, 2023

How can I do this outside of Powershell?

@scyilk
Copy link
Author

scyilk commented Jul 10, 2023

@HUMORCE I mean the environment set-ing, could it be done with SET?

@HUMORCE
Copy link
Member

HUMORCE commented Jul 10, 2023

powershell profile?

Scoop can't get SCOOP_ROOT_DIR from a relative path because #5544 hasn't been merged yet. so we must setup $env:SCOOP for now.

What I would do if I place Scoop on portable drive:

scoop-portable.ps1

# Scoop portable
foreach ($drive in (Get-PSDrive -PSProvider FileSystem)) {
    if (Test-Path "$($drive.Root)scoop") {
        $scoopdir = Resolve-Path "$($drive.Root)scoop"
        $env:SCOOP = $scoopdir
        $env:Path = "$scoopdir\shims;$env:Path"
        break 
    } 
}

Then executing cat X:\scoop-portable.ps1 >> $PROFILE on each PC once.

Or alter: scoop-env.cmd

powershell.exe -NoExit -File "%~dp0\scoop-portable.ps1"

If a drive is mounted with different drive letter each time, I am sure it will have negative effects.

@scyilk
Copy link
Author

scyilk commented Jul 10, 2023

What might those side-effects be? I want to consider this before setting it up, incase switching to a natively portable alternative (I still haven't found one without some gotchyas,) would be a better idea.

@HUMORCE
Copy link
Member

HUMORCE commented Jul 10, 2023

  1. Shim
❯ cat ~\scoop\shims\7z.shim
path = "C:\Users\humorce\scoop\apps\7zip\current\7z.exe"
  1. Junction
❯ Get-Item ~\scoop\apps\7zip\current\

    Directory: C:\Users\humorce\scoop\apps\7zip

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
l-r--            7/2/2023  5:33 PM                current -> C:\Users\humorce\scoop\apps\7zip\23.01

scoop reset * is useful to fixes them, I don't learn more about this.

Suggestion: mount drive as same drive letter on each PC. e.g. W, X, Y, Z

@scyilk
Copy link
Author

scyilk commented Jul 11, 2023

@HUMORCE I mean without Powershell as in with a .bat or .cmd script. Or maybe this powershell script can be run with that to set the env?

@HUMORCE
Copy link
Member

HUMORCE commented Jul 11, 2023

Or maybe this powershell script can be run with that to set the env?

Yes

@scyilk
Copy link
Author

scyilk commented Jul 13, 2023

After successfully installing scoop, installing anything breaks stuff, like a lot of stuff.

@ScoopInstaller ScoopInstaller locked and limited conversation to collaborators Oct 2, 2023
@rashil2000 rashil2000 converted this issue into discussion #5671 Oct 2, 2023

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Projects
None yet
Development

No branches or pull requests

2 participants