diff --git a/Package/ChocoShortcuts.nuspec b/Package/ChocoShortcuts.nuspec index efeaf95..395aa18 100644 --- a/Package/ChocoShortcuts.nuspec +++ b/Package/ChocoShortcuts.nuspec @@ -4,7 +4,7 @@ ChocoShortcuts Chocolatey Shortcuts (unofficial) - 0.3 + 0.4 mica mica https://github.com/mica/ChocoShortcuts @@ -29,8 +29,9 @@ Create shortcuts for packages using "+Add Package Shortcuts". There you'll find Launching package shortcuts will present you with options to install (if not installed), update (if available), or uninstall packages. Update multiple packages at once using "+Check for Package Updates". -- Fixed the bulk update function, which had been giving only a partal list of outdated packages since Chocolatey v0.10.5 -- Added uninstall script for removing the initial two shortcuts if the folder is otherwise empty +- Added options/switches for updates, as set in shortcuts, or entered individually +- Added "visit package webpage" selection +- Fixed bulk update, which was failing when only one update available diff --git a/Package/Tools/ChocoShortcuts.ps1 b/Package/Tools/ChocoShortcuts.ps1 index 8bc2ecc..7b2eab0 100644 --- a/Package/Tools/ChocoShortcuts.ps1 +++ b/Package/Tools/ChocoShortcuts.ps1 @@ -1,4 +1,4 @@ -# Chocolatey Shortcuts v0.3 +# Chocolatey Shortcuts v0.4 # https://github.com/mica/ChocoShortcuts/ param([Parameter(Position = 0)] [string]$App = $App, [string]$Opt) @@ -18,9 +18,10 @@ function w { function Check { Clear-Host; Header if ($App -eq '') { - 'Launch this script via the shortcuts that were created on the desktop at installaion';'' - (w 'Enter ')+(y '1 ')+'to regenerate those shortcuts to a folder of your choice' - (w 'Enter a ')+(y 'package ID ')+'to manage it sans shortcut' + 'Launch this script via the shortcuts created during installation, or:' + '' + (w 'Enter ')+(y '1 ')+'to regenerate the shortcuts to a folder of your choice' + (w 'Enter a ')+(y 'package ID ')+'to manage a package without a shortcut' (w 'Or press ')+(y 'Enter ')+'to exit' $Entry = Read-Host "`n" if ($Entry -eq '') { @@ -29,7 +30,7 @@ function Check { elseif ($Entry -eq '1') { Add-Type -AssemblyName System.Windows.Forms $FolderBrowser = New-Object System.Windows.Forms.FolderBrowserDialog -Property @{ - Description = "Choose an inital location for your shortcuts folder`nYou may move or rename it any time" + Description = "Choose a location for your shortcuts folder`nYou may move or rename it any time" } [void]$FolderBrowser.ShowDialog() $InstallDir = $FolderBrowser.SelectedPath @@ -48,18 +49,8 @@ function Check { $Shortcut.Arguments = "/C PowerShell `"SL -PSPath `'%CD%`'; `$Path = (GL).Path; SL ~; Start PowerShell -Verb RunAs -Args \`"-NoProfile -ExecutionPolicy Unrestricted `"SL -PSPath `'`"`$Path`"`'; & `'`"%ChocolateyInstall%\lib\ChocoShortcuts\Tools\ChocoShortcuts.ps1`"`' 2`"\`"`"" $Shortcut.IconLocation = '%ProgramData%\chocolatey\choco.exe' $Shortcut.Save() - Clear-Host; Header - "Shortcuts have been created in $InstallDir";'' - (w 'Enter ')+(y '1 ')+'to open the folder' - (w 'Or press ')+(y 'Enter ')+'to exit' - $Entry = Read-Host "`n" - if ($Entry -eq '1') { - Invoke-Item $InstallDir - Exit - } - else { - Exit - } + Invoke-Item $InstallDir + Check } } else { @@ -79,7 +70,8 @@ function Check { Clear-Host; Header "$App was not found on Chocolatey.org" ' Either the repository is inaccessible' - ' Or your shortcut''s package ID is invalid';'' + ' Or your shortcut''s package ID is invalid' + '' (w 'Enter ')+(y '1 ')+"to check again for $App on Chocolatey.org" (w 'Enter ')+(y '2 ')+"to delete the $App shortcut and create a new one" (w 'Or press ')+(y 'Enter ')+'to exit' @@ -112,30 +104,38 @@ function Check { } function Install { Clear-Host; Header - "$App is not installed";'' + "$App is not installed" + '' (w 'Enter ')+(y '1 ')+"to install $Avail" (w 'Enter ')+(y '2 ')+'to install with options' + (w 'Enter ')+(y '3 ')+'to visit package webpage' (w 'Or press ')+(y 'Enter ')+'to exit' $Entry = Read-Host "`n" if ($Entry -eq '1') { Clear-Host; Header - Invoke-Expression "choco install $App $Opt -r -y";'' + Invoke-Expression "choco install $App $Opt -r -y" + '' (w 'Press ')+(y 'Enter ')+'to exit'; Read-Host Exit } elseif ($Entry -eq '2') { Clear-Host; Header - "Your shortcut is configured to install using:" - Write-Host " choco install $App -y -r $Opt" -ForegroundColor Cyan;'' + 'Your shortcut is configured to use:' + Write-Host " choco install $App -y -r $Opt" -ForegroundColor Cyan + '' (w 'Enter additional ')+(y 'options')+'' - (w 'Or press ')+(y 'Enter ')+'to cancel' + (w 'Or press ')+(y 'Enter ')+'to go back' $Entry = Read-Host "`n" if ($Entry -eq '') { Install } else { + Clear-Host; Header $ExtOpt = $Entry - (w 'Enter ')+(y '1 ')+"to begin installation with: $ExtOpt" + "$App will install using:" + Write-Host " choco install $App -y -r $Opt $ExtOpt" -ForegroundColor Cyan + '' + (w 'Enter ')+(y '1 ')+'to run' (w 'Or press ')+(y 'Enter ')+'to cancel' $Entry = Read-Host "`n" if ($Entry -eq '') { @@ -143,14 +143,16 @@ function Install { } elseif ($Entry -eq '1') { Clear-Host; Header - Invoke-Expression "choco install $App $Opt $ExtOpt -r -y";'' + Invoke-Expression "choco install $App $Opt $ExtOpt -r -y" + '' (w 'Press ')+(y 'Enter ')+'to exit'; Read-Host Exit } - - } - - + } + } + elseif ($Entry -eq '3') { + Start-Process "https://chocolatey.org/packages/$App" + Install } elseif ($Entry -eq '') { Exit @@ -161,14 +163,22 @@ function Install { } function UpToDate { Clear-Host; Header - "$App $Curr is installed";'' - ' No updates are available';'' + "$App $Curr is installed" + '' + ' No updates are available' + '' + (w 'Enter ')+(y '1 ')+'to visit package webpage' (w 'Enter ')+(y '2 ')+"to uninstall $App" (w 'Or press ')+(y 'Enter ')+'to exit' $Entry = Read-Host "`n" - if ($Entry -eq '2') { + if ($Entry -eq '1') { + Start-Process "https://chocolatey.org/packages/$App" + UpToDate + } + elseif ($Entry -eq '2') { Clear-Host; Header - choco uninstall $App -r -a -x -y;'' + choco uninstall $App -r -a -x -y + '' (w 'Press ')+(y 'Enter ')+'to exit'; Read-Host Exit } @@ -181,21 +191,63 @@ function UpToDate { } function Update { Clear-Host; Header - "$App $Curr is installed";'' - " The $Avail update is available";'' + "$App $Curr is installed" + '' + " The $Avail update is available" + '' (w 'Enter ')+(y '1 ')+'to install the update' - (w 'Enter ')+(y '2 ')+"to uninstall $App" + (w 'Enter ')+(y '2 ')+'to update with options' + (w 'Enter ')+(y '3 ')+'to visit package webpage' + (w 'Enter ')+(y '4 ')+"to uninstall $App" (w 'Or press ')+(y 'Enter ')+'to exit' $Entry = Read-Host "`n" if ($Entry -eq '1') { Clear-Host; Header - choco upgrade $App -r -y;'' + Invoke-Expression "choco upgrade $App $Opt -r -y" + '' (w 'Press ')+(y 'Enter ')+'to exit'; Read-Host Exit } elseif ($Entry -eq '2') { Clear-Host; Header - choco uninstall $App -r -a -x -y;'' + 'Your shortcut is configured to use:' + Write-Host " choco upgrade $App -y -r $Opt" -ForegroundColor Cyan + '' + (w 'Enter additional ')+(y 'options')+'' + (w 'Or press ')+(y 'Enter ')+'to go back' + $Entry = Read-Host "`n" + if ($Entry -eq '') { + Update + } + else { + Clear-Host; Header + $ExtOpt = $Entry + "$App will update using:" + Write-Host " choco upgrade $App -y -r $Opt $ExtOpt" -ForegroundColor Cyan + '' + (w 'Enter ')+(y '1 ')+'to run' + (w 'Or press ')+(y 'Enter ')+'to cancel' + $Entry = Read-Host "`n" + if ($Entry -eq '1') { + Clear-Host; Header + Invoke-Expression "choco upgrade $App $Opt $ExtOpt -r -y" + '' + (w 'Press ')+(y 'Enter ')+'to exit'; Read-Host + Exit + } + else { + Update + } + } + } + elseif ($Entry -eq '3') { + Start-Process "https://chocolatey.org/packages/$App" + Update + } + elseif ($Entry -eq '4') { + Clear-Host; Header + choco uninstall $App -r -a -x -y + '' (w 'Press ')+(y 'Enter ')+'to exit'; Read-Host Exit } @@ -207,18 +259,33 @@ function Update { } } function AddNew { - 'Create new shortcuts for installing, updating, or uninstalling packages';'' - (w 'Enter one or more comma separated ')+(y 'package ID')+(w ', optionally, w/ ')+(y 'options ')+'(excluding -y and -r)' - (w 'Enter ')+(y '1 ')+'to search for package IDs on the Chocolatey.org repository' - (w 'Enter ')+(y '2 ')+'to generate shortcuts for all currently installed packages' + Clear-Host; Header + 'Create new shortcuts for installing, updating, or uninstalling packages' + '' + (w 'Enter one or more comma separated ')+(y 'package ID ')+(w 'with any ')+(y 'options ')+'you''d like to use (see package webpage)' + (w 'Enter ')+(y '1 ')+'to search for package IDs in the repository' + (w 'Enter ')+(y '2 ')+'to generate shortcuts for packages currently installed on the system' (w 'Or press ')+(y 'Enter ')+'to exit' $Entry = Read-Host "`n" if ($Entry -eq '1') { Search } elseif ($Entry -eq '2') { - $Entry = (choco list -l -r | Where-Object {$_ -notmatch '.install'}) -replace '\|.*$' -join ',' - Generate + Clear-Host; Header + '' + 'Shortcuts will be created for all currently installed packages' + 'Existing shortcuts for any installed packages will be overwritten' + '' + (w 'Enter ')+(y '1 ')+'to continue' + (w 'Or press ')+(y 'Enter ')+'to cancel' + $Entry = Read-Host "`n" + if ($Entry -eq '1') { + $Entry = (choco list -l -r | Where-Object {$_ -notmatch '.install' -and $_ -notmatch '.extension'}) -replace '\|.*$' -join ',' + Generate + } + else { + AddNew + } } elseif ($Entry -eq '') { Exit @@ -240,7 +307,8 @@ function Generate { $Shortcut.IconLocation = '%ProgramData%\chocolatey\choco.exe' $Shortcut.Save() } - "Shortcuts have been created in $WDir";'' + "Shortcuts have been created in $WDir" + '' (w 'Enter ')+(y '1 ')+'to open the folder' (w 'Enter ')+(y '2 ')+'to create another shortcut' (w 'Or press ')+(y 'Enter ')+'to exit' @@ -265,7 +333,8 @@ function Generate { function Search { Clear-Host; Header (w 'Enter your ')+(y 'search terms')+'' - (w 'Or press ')+(y 'Enter ')+'to cancel';'' + (w 'Or press ')+(y 'Enter ')+'to cancel' + '' $Search = Read-Host if ($Search -eq '') { Clear-Host; Header @@ -278,57 +347,79 @@ function Search { if ($Results -eq $null) { Clear-Host; Header "No results for ""$Search""" - (w 'Press ')+(y 'Enter ')+'to cancel'; Read-Host + (w 'Press ')+(y 'Enter ')+'to continue'; Read-Host Search } else { Clear-Host; Header - "Search results for ""$Search"":";'' - $Results -replace '\|',' (v' -replace '$',')';'' + "Search results for ""$Search"":" + '' + $Results -replace '\|',' (v' -replace '$',')' + '' AddNew } } } + +function GetOptions ($App) { + if (Test-Path "$WDir\$App.lnk") { + $Lnk = (New-Object -COM WScript.Shell).CreateShortcut("$WDir\$App.lnk").Arguments + if ($Lnk -match '-Opt' -and $Lnk -notmatch "-Opt ''" ) { + $Lnk -replace "^.*Opt '" -replace '.{5}$' + } + } +} + function UpdateCheck { Clear-Host; Header 'Checking Chocolatey.org for updates...' $Outdated = choco outdated -r | Where-Object {$_ -notmatch '.install'} if ($Outdated -eq $null) { Clear-Host; Header - 'No updates are available';'' + 'No updates are available' + '' (w 'Press ')+(y 'Enter ')+'to exit'; Read-Host Exit } - else { - $Updates = ForEach ($Package in $Outdated[0..($Outdated.Length)]) { - $Package -replace '\|(\d*\.)*\d*\|',' v' -replace '\|\D*$' - } - if ($Updates -isnot [system.array]) { + elseif ($Outdated -isnot [system.array]) { + $Updates = $Outdated -replace '\|(\d*\.)*\d*\|',' v' -replace '\|\D*$' + Clear-Host; Header + 'An update is available:' + '' + " $Updates" + '' + (w 'Enter ')+(y '1 ')+'to install the update' + (w 'Or press ')+(y 'Enter ')+'to exit' + $Entry = Read-Host "`n" + if ($Entry -eq '1') { Clear-Host; Header - 'An update is available:';'' - " $Updates";'' - (w 'Enter ')+(y '1 ')+'to install the update' - (w 'Or press ')+(y 'Enter ')+'to exit' - $Entry = Read-Host "`n" - if ($Entry -eq '1') { - Clear-Host; Header - choco upgrade ($Updates -replace ' v.*$') -r -y;'' - (w 'Press ')+(y 'Enter ')+'to exit'; Read-Host - Exit - } - else { - Exit - } + $App = $Updates -replace ' v.*$' + $Opt = GetOptions $App + Invoke-Expression "choco upgrade $App $Opt -r -y" + '' + (w 'Press ')+(y 'Enter ')+'to exit'; Read-Host + Exit + } + elseif ($Entry -eq '') { + Exit } else { - UpdateAll + UpdateCheck } + } + else { + $Updates = ForEach ($Package in $Outdated[0..($Outdated.Length)]) { + $Package -replace '\|(\d*\.)*\d*\|',' v' -replace '\|\D*$' + } + UpdateAll } } function UpdateAll { Clear-Host; Header - 'The following updates are available:';'' - $Updates;'' + 'The following updates are available:' + '' + $Updates + '' (w 'Enter ')+(y '1 ')+'to install all updates' (w 'Enter ')+(y '2 ')+'to select updates to install' (w 'Or press ')+(y 'Enter ')+'to exit' @@ -336,11 +427,16 @@ function UpdateAll { if ($Entry -eq '1') { Clear-Host; Header 'Installing:' - $Updates;'' + $Updates + '' ForEach ($Package in $Updates) { - choco upgrade ($Package -replace ' v.*$') -r -y + $App = $Package -replace ' v.*$' + $Opt = GetOptions $App + Invoke-Expression "choco upgrade $App $Opt -r -y" } - '';'Installation complete';'' + '' + 'Installation complete' + '' (w 'Press ')+(y 'Enter ')+'to exit'; Read-Host Exit } @@ -356,12 +452,14 @@ function UpdateAll { } function UpdateSelect { Clear-Host; Header - 'Enter the comma separated numbers of one or more updates to install:';'' + 'Enter the comma separated numbers of one or more updates to install:' + '' ForEach ($Package in $Updates) { $Selector++ (w ' ')+(y $Selector)+". $Package" } - '';(w 'Or press ')+(y 'Enter ')+'to cancel' + '' + (w 'Or press ')+(y 'Enter ')+'to cancel' $Entry = Read-Host "`n" if ($Entry -eq '') { $Selector = 0 @@ -373,11 +471,16 @@ function UpdateSelect { } Clear-Host; Header 'Installing:' - $Updates[$Number];'' + $Updates[$Number] + '' ForEach ($Package in ($Updates[$Number] -replace ' v\d.*$')) { - choco upgrade $Package -r -y + $App = $Package -replace ' v.*$' + $Opt = GetOptions $App + Invoke-Expression "choco upgrade $App $Opt -r -y" } - '';'Installation complete';'' + '' + 'Installation complete' + '' (w 'Press ')+(y 'Enter ')+'to exit'; Read-Host Exit } diff --git a/Screenshot.png b/Screenshot.png index 51aca60..f9bd280 100644 Binary files a/Screenshot.png and b/Screenshot.png differ