-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(release): Bump to version 0.5.1 (#6057)
- Loading branch information
Showing
10 changed files
with
180 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,117 +1,68 @@ | ||
# Usage: scoop alias add|list|rm [<args>] | ||
# Usage: scoop alias <subcommand> [options] [<args>] | ||
# Summary: Manage scoop aliases | ||
# Help: Add, remove or list Scoop aliases | ||
# Help: Available subcommands: add, rm, list. | ||
# | ||
# Aliases are custom Scoop subcommands that can be created to make common tasks | ||
# easier. | ||
# Aliases are custom Scoop subcommands that can be created to make common tasks easier. | ||
# | ||
# To add an Alias: | ||
# scoop alias add <name> <command> <description> | ||
# To add an alias: | ||
# | ||
# e.g.: | ||
# scoop alias add rm 'scoop uninstall $args[0]' 'Uninstalls an app' | ||
# scoop alias add upgrade 'scoop update *' 'Updates all apps, just like brew or apt' | ||
# scoop alias add <name> <command> [<description>] | ||
# | ||
# e.g., | ||
# | ||
# scoop alias add rm 'scoop uninstall $args[0]' 'Uninstall an app' | ||
# scoop alias add upgrade 'scoop update *' 'Update all apps, just like "brew" or "apt"' | ||
# | ||
# To remove an alias: | ||
# | ||
# scoop alias rm <name> | ||
# | ||
# To list all aliases: | ||
# | ||
# scoop alias list [-v|--verbose] | ||
# | ||
# Options: | ||
# -v, --verbose Show alias description and table headers (works only for 'list') | ||
# -v, --verbose Show alias description and table headers (works only for "list") | ||
|
||
param( | ||
[String]$opt, | ||
[String]$name, | ||
[String]$command, | ||
[String]$description, | ||
[Switch]$verbose = $false | ||
) | ||
param($SubCommand) | ||
|
||
. "$PSScriptRoot\..\lib\install.ps1" # shim related | ||
. "$PSScriptRoot\..\lib\getopt.ps1" | ||
|
||
$script:config_alias = 'alias' | ||
|
||
function init_alias_config { | ||
$aliases = get_config $script:config_alias | ||
if ($aliases) { | ||
$aliases | ||
$SubCommands = @('add', 'rm', 'list') | ||
if ($SubCommand -notin $SubCommands) { | ||
if (!$SubCommand) { | ||
error '<subcommand> missing' | ||
} else { | ||
New-Object -TypeName PSObject | ||
error "'$SubCommand' is not one of available subcommands: $($SubCommands -join ', ')" | ||
} | ||
my_usage | ||
exit 1 | ||
} | ||
|
||
function add_alias($name, $command) { | ||
if (!$command) { | ||
abort "Can't create an empty alias." | ||
} | ||
$opt, $other, $err = getopt $Args 'v' , 'verbose' | ||
if ($err) { "scoop alias: $err"; exit 1 } | ||
|
||
# get current aliases from config | ||
$aliases = init_alias_config | ||
if ($aliases.$name) { | ||
abort "Alias '$name' already exists." | ||
} | ||
|
||
$alias_file = "scoop-$name" | ||
$name, $command, $description = $other | ||
$verbose = $opt.v -or $opt.verbose | ||
|
||
# generate script | ||
$shimdir = shimdir $false | ||
if (Test-Path "$shimdir\$alias_file.ps1") { | ||
abort "File '$alias_file.ps1' already exists in shims directory." | ||
switch ($SubCommand) { | ||
'add' { | ||
if (!$name -or !$command) { | ||
error "<name> and <command> must be specified for subcommand 'add'" | ||
exit 1 | ||
} | ||
add_alias $name $command $description | ||
} | ||
$script = | ||
@( | ||
"# Summary: $description", | ||
"$command" | ||
) -join "`r`n" | ||
$script | Out-UTF8File "$shimdir\$alias_file.ps1" | ||
|
||
# add alias to config | ||
$aliases | Add-Member -MemberType NoteProperty -Name $name -Value $alias_file | ||
|
||
set_config $script:config_alias $aliases | Out-Null | ||
} | ||
|
||
function rm_alias($name) { | ||
$aliases = init_alias_config | ||
if (!$name) { | ||
abort 'Alias to be removed has not been specified!' | ||
'rm' { | ||
if (!$name) { | ||
error "<name> must be specified for subcommand 'rm'" | ||
exit 1 | ||
} | ||
rm_alias $name | ||
} | ||
|
||
if ($aliases.$name) { | ||
info "Removing alias '$name'..." | ||
|
||
rm_shim $aliases.$name (shimdir $false) | ||
|
||
$aliases.PSObject.Properties.Remove($name) | ||
set_config $script:config_alias $aliases | Out-Null | ||
} else { | ||
abort "Alias '$name' doesn't exist." | ||
} | ||
} | ||
|
||
function list_aliases { | ||
$aliases = @() | ||
|
||
(init_alias_config).PSObject.Properties.GetEnumerator() | ForEach-Object { | ||
$content = Get-Content (command_path $_.Name) | ||
$command = ($content | Select-Object -Skip 1).Trim() | ||
$summary = (summary $content).Trim() | ||
|
||
$aliases += New-Object psobject -Property @{Name = $_.name; Summary = $summary; Command = $command } | ||
} | ||
|
||
if (!$aliases.count) { | ||
info "No alias found." | ||
'list' { | ||
list_aliases $verbose | ||
} | ||
$aliases = $aliases.GetEnumerator() | Sort-Object Name | ||
if ($verbose) { | ||
return $aliases | Select-Object Name, Command, Summary | ||
} else { | ||
return $aliases | Select-Object Name, Command | ||
} | ||
} | ||
|
||
switch ($opt) { | ||
'add' { add_alias $name $command } | ||
'rm' { rm_alias $name } | ||
'list' { list_aliases } | ||
default { my_usage; exit 1 } | ||
} | ||
|
||
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.