Skip to content

Commit

Permalink
fix: Adopt shovel commands automatically
Browse files Browse the repository at this point in the history
Extraction 3 of #1
  • Loading branch information
Ash258 committed Jan 29, 2022
1 parent 8e3ac8d commit 16d6471
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
.LINK
https://scoop.sh
.LINK
https://github.com/lukesampson/scoop/wiki
https://github.com/ScoopInstaller/Scoop/wiki
#>
param(
[String] $ScoopDir,
Expand Down Expand Up @@ -258,6 +258,7 @@ function Import-ScoopShim {
}

# The scoop shim
# TODO: Switch
$shim = "$SCOOP_SHIMS_DIR\scoop"

# Convert to relative path
Expand All @@ -284,6 +285,10 @@ powershell -noprofile -ex unrestricted `"& '$path' %args%;exit `$lastexitcode`""

# Make scoop accessible from bash or other posix shell
Write-Output "#!/bin/sh`npowershell.exe -ex unrestricted `"$path`" `"$@`"" | Out-File $shim -Encoding 'ascii'

# Adopt shovel commands
Get-ChildItem $SCOOP_SHIMS_DIR -Filter 'scoop.*' |
Copy-Item -Destination { Join-Path $_.Directory.FullName (($_.BaseName -replace 'scoop', 'shovel') + $_.Extension) }
}

function Get-Env {
Expand All @@ -305,7 +310,7 @@ function Add-ShimsDirToPath {
if (!$h.EndsWith('\')) { $h += '\' }

if ($h -ne '\') {
$friendlyPath = "$SCOOP_SHIMS_DIR" -replace ([Regex]::Escape($h)), '~\'
$friendlyPath = $SCOOP_SHIMS_DIR -replace ([Regex]::Escape($h)), '~\'
Write-InstallInfo "Adding $friendlyPath to your path."
} else {
Write-InstallInfo "Adding $SCOOP_SHIMS_DIR to your path."
Expand Down Expand Up @@ -393,7 +398,7 @@ function Add-DefaultConfig {
if ((Test-IsAdministrator) -and $env:SCOOP_CACHE) {
[Environment]::SetEnvironmentVariable('SCOOP_CACHE', $env:SCOOP_CACHE, 'Machine')
} else {
if ($SCOOP_CACHE_DIR -ne "$SCOOP_DIR\cache") {
if ($SCOOP_CACHE_DIR -ne $SCOOP_CACHE_DEFAULT_DIR) {
Add-Config -Name 'cachePath' -Value $SCOOP_CACHE_DIR | Out-Null
}
}
Expand Down Expand Up @@ -471,20 +476,29 @@ if (!$env:USERPROFILE) {
# Prepare variables
$IS_EXECUTED_FROM_IEX = ($null -eq $MyInvocation.MyCommand.Path)

$SCOOP_DEFAULT_DIR = "${env:USERPROFILE}\scoop"
$SCOOP_GLOBAL_DEFAULT_DIR = "${env:ProgramData}\scoop"
$SCOOP_CACHE_DEFAULT_DIR = "${SCOOP_DEFAULT_DIR}\cache"

# TODO: Change and rebrand
# Scoop root directory
$SCOOP_DIR = $ScoopDir, $env:SCOOP, "${env:USERPROFILE}\scoop" | Where-Object { -not [String]::IsNullOrEmpty($_) } | Select-Object -First 1
$SCOOP_DIR = $ScoopDir, $env:SCOOP, $SCOOP_DEFAULT_DIR | Where-Object { -not [String]::IsNullOrEmpty($_) } | Select-Object -First 1
# Scoop global apps directory
$SCOOP_GLOBAL_DIR = $ScoopGlobalDir, $env:SCOOP_GLOBAL, "${env:ProgramData}\scoop" | Where-Object { -not [String]::IsNullOrEmpty($_) } | Select-Object -First 1
$SCOOP_GLOBAL_DIR = $ScoopGlobalDir, $env:SCOOP_GLOBAL, $SCOOP_GLOBAL_DEFAULT_DIR | Where-Object { -not [String]::IsNullOrEmpty($_) } | Select-Object -First 1
# Scoop cache directory
$SCOOP_CACHE_DIR = $ScoopCacheDir, $env:SCOOP_CACHE, "${SCOOP_DIR}\cache" | Where-Object { -not [String]::IsNullOrEmpty($_) } | Select-Object -First 1
$SCOOP_CACHE_DIR = $ScoopCacheDir, $env:SCOOP_CACHE, $SCOOP_CACHE_DEFAULT_DIR | Where-Object { -not [String]::IsNullOrEmpty($_) } | Select-Object -First 1
# Scoop shims directory
$SCOOP_SHIMS_DIR = "${SCOOP_DIR}\shims"
# Scoop global shims directory
$SCOOP_GLOBAL_SHIMS_DIR = "${SCOOP_GLOBAL_DIR}\shims"
# Scoop itself directory
$SCOOP_APP_DIR = "${SCOOP_DIR}\apps\scoop\current"
# Scoop buckets directory
$SCOOP_BUCKETS_DIR = "${SCOOP_DIR}\buckets"
# Scoop main bucket directory
$SCOOP_MAIN_BUCKET_DIR = "${SCOOP_DIR}\buckets\main"
# Scoop config file location
$SCOOP_CONFIG_HOME = $env:XDG_CONFIG_HOME, "${env:USERPROFILE}\.config" | Select-Object -First 1
$SCOOP_CONFIG_HOME = $env:XDG_CONFIG_HOME, "${env:USERPROFILE}\.config" | Where-Object { -not [String]::IsNullOrEmpty($_) } | Select-Object -First 1
$SCOOP_CONFIG_FILE = "${SCOOP_CONFIG_HOME}\scoop\config.json"

# TODO: Use a specific version of Scoop and the main bucket
Expand Down

0 comments on commit 16d6471

Please sign in to comment.