I love Scoop.sh! It provides almost all the applications I need.
But updating them isn’t super friendly. Let’s see together how I managed to update all the outdated apps in (almost) one command line.
Scoop update and Scoop status
Before we start, the prerequisite is to make sure Scoop is up itself up-to-date using the update command:
|
|
Then, to know which applications need an update, the following command lists them for us:
|
|
The typical output would be:
|
|
Create the Starting Point
Let’s create a PowerShell file called scoop-auto-update-apps.ps1.
The first lines are:
|
|
What does $statusOutput contain?
|
|
It corresponds to a list of objects of the applications to update. Let’s see one example:
|
|
Extract the Application Name
To extract the application name, we’ll use a regular expression:
|
|
Note: $_ equals to the current object of the list being parsed.
We’re checking the pattern Name=([^;]+) against the entire object string, and the regular expression captures just the value after Name= and before the semicolon, which gives us the app name we want.
Then, the $matches is an automatic variable in PowerShell that gets populated when using the -match operator with regular expression groups (marked by parentheses in the pattern).
When using the pattern Name=([^;]+):
$matchescontains the entire matched string (e.g.,Name=find-java)$matchescontains what was captured in the first group between()(e.g.,find-java)
Here’s an example to illustrate:
|
|
We use $matches because we want just the app name without the Name= prefix.
Checking That We Have No Application To Update
Next, let’s just check the scoop status output a list of applications.
If not, let’s end the execution:
|
|
Print Out the List of Applications to Update
For the sake of giving feedback to the user, let’s print the list:
|
|
Run the Update Command per Application
Now, we’re ready to update the outdated applications. Let’s loop over the $updatableApps and run scoop update $app:
|
|
Adding a --dry-run option
OK, now, I always like to execute any script with a --dry-run to check what will happen before it’s really executed.
Let’s wrap the code so far in a function:
|
|
And add at the bottom of the script a function call that handles the dry run option:
|
|
Next, in the function body, let’s add the dry run check just before the last loop that calls scoop update $app:
|
|
What Isn’t Included
Sometimes, Scoop tells you you need to run a registry command for contextual menus or co. This script doesn’t yet handle that.
You’ll need to copy those commands and run them individually.
Also, the script doesn’t allow skipping an application update if you need to keep the current installed version enabled. I’d say that we’d need a --skip "app1 app2 ..." option for that.
Conclusion
There you have it! You can update your Scoop applications with a single command:
|
|
The full script is available in this GitHub gist. Enjoy!
Follow me
Thanks for reading this article. Make sure to follow me on X, subscribe to my Substack publication and bookmark my blog to read more in the future.
Photo by Yan Krukau.