gerp.ps1
<#PSScriptInfo
.VERSION 1.0 .GUID 12345678-1234-1234-1234-123456789012 .AUTHOR gluk .COMPANYNAME .COPYRIGHT .TAGS fzf,ripgrep,neovim,search,fuzzy-finder,split,tabs,panes .LICENSEURI .PROJECTURI .ICONURI .EXTERNALMODULEDEPENDENCIES .REQUIREDSCRIPTS .EXTERNALSCRIPTDEPENDENCIES .RELEASENOTES Initial version #> <# .DESCRIPTION Interactive fuzzy file search using fzf and ripgrep. Allows searching through files and opening results in neovim or VS Code with support for new tabs, horizontal splits, and vertical splits. .PARAMETER Query Search query terms to pass to ripgrep .PARAMETER Code Switch to open results in VS Code instead of neovim .PARAMETER NewTab Switch to open files in a new neovim tab instead of the current buffer .EXAMPLE .\Search-Files.ps1 "function main" Searches for files containing "function main" .EXAMPLE .\Search-Files.ps1 -Code -Query "TODO" Searches for "TODO" and opens results in VS Code .EXAMPLE .\Search-Files.ps1 -NewTab "class User" Searches for "class User" and opens results in a new neovim tab #> [CmdletBinding()] param( [string[]]$Query = @(), [switch]$Code, [switch]$NewTab ) # Validate mutually exclusive options $openModes = @($NewTab, $HSplit, $VSplit).Where({ $_ }).Count if ($openModes -gt 1) { Write-Error "Only one of -NewTab, -HSplit, or -VSplit can be specified at a time." exit 1 } $RELOAD = 'reload:rg --column --color=always --smart-case {q} || echo ""' # Join query arguments with spaces $QueryString = $Query -join ' ' # Determine the enter action based on parameters $enterAction = "execute:nvim {1} +{2}" if ($env:VIM_LISTEN_ADDRESS) { if ($NewTab) { $enterAction = "execute:nvim --server $env:VIM_LISTEN_ADDRESS --remote-tab {1} +{2}" } else { $enterAction = "execute:nvim --server $env:VIM_LISTEN_ADDRESS --remote {1} +{2}" } } elseif ($Code) { $enterAction = "execute:code --goto {1}:{2}" } elseif ($NewTab) { $enterAction = "execute:nvim -p {1} +{2}" } fzf --disabled --ansi --multi ` --bind "start:$RELOAD" ` --bind "change:$RELOAD" ` --bind "enter:$enterAction" ` --bind "ctrl-o:execute:nvim {1} +{2}" ` --bind "ctrl-q:execute:nvim +cw -q {+f}" ` --bind 'alt-a:select-all,alt-d:deselect-all,ctrl-/:toggle-preview' ` --delimiter ':' ` --preview 'bat --style=full --color=always --highlight-line {2} {1}' ` --preview-window '~4,+{2}+4/3,<80(up)' ` --query "$QueryString" |