mirror of
https://github.com/ScoopInstaller/Scoop.git
synced 2025-10-30 06:07:56 +00:00
* fix (decompress): `Expand-7zipArchive` only delete temp dir / `$extractDir` if it is empty (#6092) Co-authored-by: Hsiao-nan Cheung <niheaven@gmail.com> * refactor(download): Move download-related functions to 'download.ps1' (#6095) * fix(download): Fallback to default downloader when aria2 fails (#4292) * fix(commands): Handling broken aliases (#6141) * fix(shim): properly check `wslpath`/`cygpath` command first (#6114) Co-authored-by: Hsiao-nan Cheung <niheaven@gmail.com> * fix(scoop-bucket): Add missing import for `no_junction` envs (#6181) Signed-off-by: Chawye Hsu <su+git@chawyehsu.com> * docs(chglog): Update to 0.5.3 (#6258) * perf(shim): Update kiennq-shim to v3.1.2 (#6261) * fix(decompress): Replace deprecated 7ZIPEXTRACT_USE_EXTERNAL config (#6327) Co-authored-by: Hsiao-nan Cheung <niheaven@gmail.com> * fix(scoop-uninstall): Fix uninstaller does not gain Global state (#6430) * global arg * changelog * refactor(Get-Manifest): Select actual source for manifest (#6142) * first step * Revert "first step" This reverts commitc5907c3e25. * refactor(Get-Manifest): Select actual source for installed manifest * rework sub-commands, `scoop-depends` is NOT working at this stage * URI manifest * opt * deprecated manifest * source of manifests * source of manifest pt2 - Mark URI(path/URL/UNC/etc.) query as standalone manifest - Drop `installed` and `available update` items for [query] and [installed] are different sources. * remove variable preventing I forget it * scoop-info: fix source of manifest on bucket * fix `scoop-depends` * Fix Standalone and Source detection * fix global install * Fix scoop-cat, scoop-home - Query for remote manifest * scoop-list: info +deprecated * manifest: Fix first selected manifest * gramma.. * Fix61b3259* length * fix(scoop-depends-tests): Mocking `USE_EXTERNAL_7ZIP` as $false (#6431) * fix(scoop-depends-tests): Mocking `USE_EXTERNAL_7ZIP` as $false to avoding error when it is $true * CHANGELOG * feat(autoupdate): GitHub predefined hashes support (#6416) * feat(autoupdate): predefined hash case for GitHub - Remove `sha256:` prefix in `format_hash()` - Add GitHub support in `get_hash_for_app()` Close #6381 * doc(chglog): GitHub auto hash update * fix(autoupdate): remove prefix only * docs(CHANGELOG): Update to 0.5.3 (#6432) * docs(CHANGELOG): Update to 0.5.3 * 6416 --------- Signed-off-by: Chawye Hsu <su+git@chawyehsu.com> Co-authored-by: Olav Rønnestad Birkeland <6450056+o-l-a-v@users.noreply.github.com> Co-authored-by: kiennq <kien.n.quang@gmail.com> Co-authored-by: HUMORCE <humorce@outlook.com> Co-authored-by: Ryan <sitiom@proton.me> Co-authored-by: Chawye Hsu <su+git@chawyehsu.com> Co-authored-by: Bassel Rachid <101208715+basselworkforce@users.noreply.github.com> Co-authored-by: Wordless Echo <wordless@echo.moe>
129 lines
3.4 KiB
PowerShell
129 lines
3.4 KiB
PowerShell
# Description: Functions for managing commands and aliases.
|
|
|
|
## Functions for commands
|
|
|
|
function command_files {
|
|
(Get-ChildItem "$PSScriptRoot\..\libexec") + (Get-ChildItem "$scoopdir\shims") |
|
|
Where-Object 'scoop-.*?\.ps1$' -Property Name -Match
|
|
}
|
|
|
|
function commands {
|
|
command_files | ForEach-Object { command_name $_ }
|
|
}
|
|
|
|
function command_name($filename) {
|
|
$filename.name | Select-String 'scoop-(.*?)\.ps1$' | ForEach-Object { $_.matches[0].groups[1].value }
|
|
}
|
|
|
|
function command_path($cmd) {
|
|
$cmd_path = "$PSScriptRoot\..\libexec\scoop-$cmd.ps1"
|
|
|
|
# built in commands
|
|
if (!(Test-Path $cmd_path)) {
|
|
# get path from shim
|
|
$shim_path = "$scoopdir\shims\scoop-$cmd.ps1"
|
|
$line = ((Get-Content $shim_path) | Where-Object { $_.startswith('$path') })
|
|
if ($line) {
|
|
Invoke-Command ([scriptblock]::Create($line)) -NoNewScope
|
|
$cmd_path = $path
|
|
} else { $cmd_path = $shim_path }
|
|
}
|
|
|
|
$cmd_path
|
|
}
|
|
|
|
function exec($cmd, $arguments) {
|
|
$cmd_path = command_path $cmd
|
|
|
|
& $cmd_path @arguments
|
|
}
|
|
|
|
## Functions for aliases
|
|
|
|
function add_alias {
|
|
param(
|
|
[ValidateNotNullOrEmpty()]
|
|
[string]$name,
|
|
[ValidateNotNullOrEmpty()]
|
|
[string]$command,
|
|
[string]$description
|
|
)
|
|
|
|
$aliases = get_config ALIAS ([PSCustomObject]@{})
|
|
if ($aliases.$name) {
|
|
abort "Alias '$name' already exists."
|
|
}
|
|
|
|
$alias_script_name = "scoop-$name"
|
|
$shimdir = shimdir $false
|
|
if (Test-Path "$shimdir\$alias_script_name.ps1") {
|
|
abort "File '$alias_script_name.ps1' already exists in shims directory."
|
|
}
|
|
$script = @(
|
|
"# Summary: $description",
|
|
"$command"
|
|
) -join "`n"
|
|
try {
|
|
$script | Out-UTF8File "$shimdir\$alias_script_name.ps1"
|
|
} catch {
|
|
abort $_.Exception
|
|
}
|
|
|
|
# Add the new alias to the config.
|
|
$aliases | Add-Member -MemberType NoteProperty -Name $name -Value $alias_script_name
|
|
set_config ALIAS $aliases | Out-Null
|
|
}
|
|
|
|
function rm_alias {
|
|
param(
|
|
[ValidateNotNullOrEmpty()]
|
|
[string]$name
|
|
)
|
|
|
|
$aliases = get_config ALIAS ([PSCustomObject]@{})
|
|
if (!$aliases.$name) {
|
|
abort "Alias '$name' doesn't exist."
|
|
}
|
|
|
|
info "Removing alias '$name'..."
|
|
if (Test-Path "$(shimdir $false)\scoop-$name.ps1") {
|
|
Remove-Item "$(shimdir $false)\scoop-$name.ps1"
|
|
}
|
|
$aliases.PSObject.Properties.Remove($name)
|
|
set_config ALIAS $aliases | Out-Null
|
|
}
|
|
|
|
function list_aliases {
|
|
param(
|
|
[bool]$verbose
|
|
)
|
|
|
|
$aliases = get_config ALIAS ([PSCustomObject]@{})
|
|
$alias_info = $aliases.PSObject.Properties.Name | Where-Object { $_ } | ForEach-Object {
|
|
# Mark the alias as <BROKEN>, if the alias script file does NOT exist.
|
|
if (!(Test-Path "$(shimdir $false)\scoop-$_.ps1")) {
|
|
[PSCustomObject]@{
|
|
Name = $_
|
|
Command = '<BROKEN>'
|
|
}
|
|
return
|
|
}
|
|
$content = Get-Content (command_path $_)
|
|
[PSCustomObject]@{
|
|
Name = $_
|
|
Command = ($content | Select-Object -Skip 1).Trim()
|
|
Summary = (summary $content).Trim()
|
|
}
|
|
}
|
|
if (!$alias_info) {
|
|
info 'No alias found.'
|
|
return
|
|
}
|
|
$alias_info = $alias_info | Sort-Object Name
|
|
$properties = @('Name', 'Command')
|
|
if ($verbose) {
|
|
$properties += 'Summary'
|
|
}
|
|
$alias_info | Select-Object $properties
|
|
}
|