Skip to content

Commit

Permalink
Add new function for Scoop apps (kelleyma49#130)
Browse files Browse the repository at this point in the history
* Add new function for Scoop apps

* missing colon
  • Loading branch information
rashil2000 authored Feb 19, 2022
1 parent 2bd1162 commit 15bcd9b
Show file tree
Hide file tree
Showing 7 changed files with 140 additions and 12 deletions.
3 changes: 3 additions & 0 deletions PSFzf.Base.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ function Set-PsFzfOption{
[switch]
$EnableAliasFuzzySetLocation,
[switch]
$EnableAliasFuzzyScoop,
[switch]
$EnableAliasFuzzySetEverything,
[switch]
$EnableAliasFuzzyZLocation,
Expand Down Expand Up @@ -197,6 +199,7 @@ function Set-PsFzfOption{
if ($EnableAliasFuzzySetLocation) { SetPsFzfAlias "fd" Invoke-FuzzySetLocation }
if ($EnableAliasFuzzyZLocation) { SetPsFzfAlias "fz" Invoke-FuzzyZLocation }
if ($EnableAliasFuzzyGitStatus) { SetPsFzfAlias "fgs" Invoke-FuzzyGitStatus }
if ($EnableAliasFuzzyScoop) { SetPsFzfAlias "fs" Invoke-FuzzyScoop }
if ($EnableAliasFuzzySetEverything) {
if (${function:Set-LocationFuzzyEverything}) {
SetPsFzfAlias "cde" Set-LocationFuzzyEverything
Expand Down
28 changes: 28 additions & 0 deletions PSFzf.Functions.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,33 @@ function Invoke-FuzzyZLocation() {
}


#.ExternalHelp PSFzf.psm1-help.xml
function Invoke-FuzzyScoop() {
param(
[string]$subcommand = "install",
[string]$subcommandflags = ""
)

$result = $null
$scoopexists = Get-Command scoop -ErrorAction Ignore
if ($scoopexists) {
$apps = New-Object System.Collections.ArrayList
Get-ChildItem "$(Split-Path $scoopexists.Path)\..\buckets" | ForEach-Object {
$bucket = $_.Name
Get-ChildItem "$($_.FullName)\bucket" | ForEach-Object {
$apps.Add($bucket + '/' + ($_.Name -replace '.json', '')) > $null
}
}

$result = $apps | Invoke-Fzf -Header "Scoop Applications" -Multi -Preview "scoop info {}" -PreviewWindow wrap
}

if ($null -ne $result) {
Invoke-Expression "scoop $subcommand $($result -join ' ') $subcommandflags"
}
}


#.ExternalHelp PSFzf.psm1-help.xml
function Invoke-FuzzyGitStatus() {
$result = @()
Expand Down Expand Up @@ -228,6 +255,7 @@ function Enable-PsFzfAliases()
SetPsFzfAliasCheck "cde" Set-LocationFuzzyEverything
}
SetPsFzfAliasCheck "fz" Invoke-FuzzyZLocation
SetPsFzfAliasCheck "fs" Invoke-FuzzyScoop
SetPsFzfAliasCheck "fgs" Invoke-FuzzyGitStatus
}
}
1 change: 1 addition & 0 deletions PSFzf.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ FunctionsToExport = @(
'Invoke-FuzzyHistory',
'Invoke-FuzzyKillProcess',
'Invoke-FuzzySetLocation',
'Invoke-FuzzyScoop',
'Set-LocationFuzzyEverything',
'Set-PsFzfOption',
'Invoke-FzfTabCompletion'
Expand Down
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ Get-ChildItem . -Recurse -Attributes !Directory | Invoke-Fzf | % { notepad $_ }
For day-to-day usage, see the [helper functions included with this module](https://github.com/kelleyma49/PSFzf#helper-functions).

## PSReadline Integration
### Select Current Provider Path (default chord: <kbd>Ctrl+t</kbd>)
Press <kbd>Ctrl+t</kbd> to start PSFzf to select provider paths. PSFzf will parse the current token and use that as the starting path to search from. If current token is empty, or the token isn't a valid path, PSFzf will search below the current working directory.
### Select Current Provider Path (default chord: <kbd>Ctrl+t</kbd>)
Press <kbd>Ctrl+t</kbd> to start PSFzf to select provider paths. PSFzf will parse the current token and use that as the starting path to search from. If current token is empty, or the token isn't a valid path, PSFzf will search below the current working directory.

Multiple items can be selected. If more than one is selected by the user, the results are returned as a comma separated list. Results are properly quoted if they contain whitespace.

Expand All @@ -46,7 +46,7 @@ Press <kbd>Alt+c</kbd> to start PSFzf to select a directory. By default, `Set-L

```powershell
# example command - use $Location with a different command:
$commandOverride = [ScriptBlock]{ param($Location) Write-Host $Location }
$commandOverride = [ScriptBlock]{ param($Location) Write-Host $Location }
# pass your override to PSFzf:
Set-PsFzfOption -AltCCommand $commandOverride
```
Expand All @@ -56,7 +56,7 @@ Set-PsFzfOption -AltCCommand $commandOverride
Press <kbd>Alt+a</kbd> to start PSFzf to select command line arguments used in PSReadline history. The picked argument will be inserted in the current line. The line that would result from the selection is shown in the preview window.

## Tab Expansion
PSFzf can replace the standard tab completion:
PSFzf can replace the standard tab completion:
```powershell
Set-PSReadLineKeyHandler -Key Tab -ScriptBlock { Invoke-FzfTabCompletion }
```
Expand Down Expand Up @@ -103,14 +103,15 @@ In addition to its core function [Invoke-Fzf](docs/Invoke-Fzf.md), PSFzf include
| [`Invoke-FuzzyEdit`](docs/Invoke-FuzzyEdit.md) | `fe` | Starts an editor for the selected files in the fuzzy finder.
| [`Invoke-FuzzyFasd`](docs/Invoke-FuzzyFasd.md) | `ff` | Starts fzf with input from the files saved in [fasd ](https://github.com/clvv/fasd)(non-Windows) or [fasdr](https://github.com/kelleyma49/fasdr) (Windows) and sets the current location.
| [`Invoke-FuzzyZLocation`](docs/Invoke-FuzzyZLocation.md) | `fz` | Starts fzf with input from the history of [ZLocation](https://github.com/vors/ZLocation) and sets the current location.
| [`Invoke-FuzzyGitStatus`](docs/Invoke-FuzzyGitStatus.md) | `fgs` | Starts fzf with input from output of the `git status` function.
| [`Invoke-FuzzyGitStatus`](docs/Invoke-FuzzyGitStatus.md) | `fgs` | Starts fzf with input from output of the `git status` function.
| [`Invoke-FuzzyHistory`](docs/Invoke-FuzzyHistory.md) | `fh` | Rerun a previous command from history based on the user's selection in fzf.
| [`Invoke-FuzzyKillProcess`](docs/Invoke-FuzzyKillProcess.md) | `fkill` | Runs `Stop-Process` on processes selected by the user in fzf.
| [`Invoke-FuzzySetLocation`](docs/Invoke-FuzzySetLocation.md) | `fd` | Sets the current location from the user's selection in fzf.
| [`Set-LocationFuzzyEverything`](docs/Set-LocationFuzzyEverything.md) | `cde` | Sets the current location based on the [Everything](https://www.voidtools.com/) database.
| [`Invoke-FuzzyScoop`](docs/Invoke-FuzzyScoop.md) | `fs` | Starts fzf on [Scoop](https://scoop.sh) applications list.

# Prerequisites
Follow the [installation instructions for fzf](https://github.com/junegunn/fzf#installation) before installing PSFzf. PSFzf will run `Get-Command` to find `fzf` in your path.
Follow the [installation instructions for fzf](https://github.com/junegunn/fzf#installation) before installing PSFzf. PSFzf will run `Get-Command` to find `fzf` in your path.

## Windows
The latest version of `fzf` is available via [Chocolatey](https://chocolatey.org/packages/fzf), or you can download the `fzf` binary and place it in your path. Run `Get-Command fzf*.exe` to verify that PowerShell can find the executable.
Expand All @@ -132,4 +133,5 @@ PSFzf is available on the [PowerShell Gallery](https://www.powershellgallery.com
* [`Invoke-FuzzyFasd`](docs/Invoke-FuzzyFasd.md) requires [Fasdr](https://github.com/kelleyma49/fasdr) to be previously installed under Windows. Other platforms require [Fasd](https://github.com/clvv/fasd) to be installed.
* [`Invoke-FuzzyZLocation`](docs/Invoke-FuzzyZLocation.md) requires [ZLocation](https://github.com/vors/ZLocation) and works only under Windows.
* [`Set-LocationFuzzyEverything`](docs/Set-LocationFuzzyEverything.md) works only under Windows and requires [PSEverything](https://www.powershellgallery.com/packages/PSEverything) to be previously installed.
* [`Invoke-FuzzyScoop`](docs/Invoke-FuzzyScoop.md) works only under Windows and requires [Scoop](https://scoop.sh) to be previously installed.
* [`Invoke-FuzzyGitStatus`](docs/Invoke-FuzzyGitStatus.md) requires [git](https://git-scm.com/) to be installed.
79 changes: 79 additions & 0 deletions docs/Invoke-FuzzyScoop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
---
external help file: PSFzf.psm1-help.xml
schema: 2.0.0
---

# Invoke-FuzzyScoop
## SYNOPSIS
Starts fzf on Scoop applications list.
## SYNTAX

```
Invoke-FuzzyScoop [-subcommand <string>] [-subcommandflags <string>]
```

## DESCRIPTION
Allows the user to select (multiple) applications from locally stored Scoop buckets and runs `subcommand` on them. Default value of `subcommand` is `install`.
## EXAMPLES

### Launch Invoke-FuzzyScoop

Launches fzf and selects some applications to install.

```
Invoke-FuzzyScoop
```

### Launch Invoke-FuzzyScoop using `uninstall` subcommand

Launches fzf for selects some applications to uninstall.


```
Invoke-FuzzyScoop -subcommand uninstall
```

## PARAMETERS
### -subcommand
The Scoop command that will be run on the selected applications.

```yaml
Type: String
Parameter Sets: (All)
Aliases:

Required: False
Position: 0
Default value: install
Accept pipeline input: False
Accept wildcard characters: False
```
### -subcommandflags
A set of flags that will be additionally passed to the Scoop subcommand.
```yaml
Type: String
Parameter Sets: (All)
Aliases:

Required: False
Position: 0
Default value:
Accept pipeline input: False
Accept wildcard characters: False
```
### CommonParameters
This cmdlet does not support common parameters.
## INPUTS
### None
This cmdlet does not accept any input.
## OUTPUTS
### None
This cmdlet does not generate any output.
## NOTES
This function will be effective if [Scoop](https://scoop.sh) can be found in PATH.
14 changes: 14 additions & 0 deletions docs/Set-PsFzfOption.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,20 @@ Accept pipeline input: False
Accept wildcard characters: False
```

### -EnableAliasFuzzyScoop
Enables the `fs` aliases for the `Invoke-FuzzyScoop` function
```yaml
Type: SwitchParameter
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -EnableAliasFuzzyZLocation
Enables the `fz` aliases for the `Invoke-FuzzySetZLocation` function
```yaml
Expand Down
13 changes: 7 additions & 6 deletions en-US/about_PSFzf.help.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,22 @@ LONG DESCRIPTION
* Convenience function for invoking previous history (Invoke-FuzzyHistory, or fh)
* Convenience function for killing processes (Invoke-FuzzyKillProcess, or fkill)
* Convenience function for setting the current location (Invoke-FuzzySetLocation, or fd)
* Convenience function for selecting Scoop applications (Invoke-FuzzyScoop, or fs)
* Convenience function for selecting a file or folder from Everything (Set-LocationFuzzyEverything, or cde)

Basic Usage
-----------
Invoke-PSFzf reads input from the pipeline. For example, the following command allows the user to
Invoke-PSFzf reads input from the pipeline. For example, the following command allows the user to
to select a file from the interface and set the current location to that folder:

cd (gci -Recurse | where {$_.PSIsContainer} | Invoke-Fzf)

If Invoke-PSFzf is passed an object, it attempts to find a common property to display, like Name or FullName.
For example, these will display just the name rather than the string representation of the object:

Get-Process | Invoke-Fzf
gci alias: | Invoke-Fzf

POWERSHELL COMPATIBILITY

Compatibility information can be found here: https://github.com/kelleyma49/PSFzf/blob/master/README.md#prerequisites.
Expand Down

0 comments on commit 15bcd9b

Please sign in to comment.