Search Sourcegraph from PowerShell
Pretty formatting is supported for text, file and symbol results (type:file and type:symbol)
Install-Module PSSourcegraphUse Get-Help to see documentation for any command.
- Search
Search-Sourcegraph💡 with query autocompletion
- Code intelligence
💡 all code intelligence cmdlets support search output as pipeline input
Get-SourcegraphHover💡 displayed as rendered markdownGet-SourcegraphDefinitionGet-SourcegraphReference💡 automatically paginated and streamed
- Repositories
Get-SourcegraphRepository
- Users
Get-SourcegraphUserNew-SourcegraphUser
- Utility
Invoke-SourcegraphApiRequest
Missing something? Please file an issue!
By default, all commands are prefixed with Sourcegraph like shown above.
If you prefer a shorter prefix, e.g. Src or Sg, you can import the module under a different prefix in your $PROFILE:
Import-Module PSSourcegraph -Prefix SrcThe commands are then available under that prefix, e.g. Search-Src or Get-SrcHover.
You can use a private instance by passing an instance URL with the -Endpoint parameter and an API token with the -Token parameter to any command.
The token must be a SecureString for security.
To configure a default endpoint and token to use, modify $PSDefaultParameterValues in your $PROFILE:
$PSDefaultParameterValues['*Sourcegraph*:Endpoint'] = 'https://sourcegraph.example.com'
$PSDefaultParameterValues['*Sourcegraph*:Token'] = 'YOUR_ENCRYPTED_TOKEN' | ConvertTo-SecureStringTo get the value for YOUR_ENCRYPTED_TOKEN, run Read-Host -AsSecureString | ConvertFrom-SecureString once
and paste in your token.
macOS and Linux do not have access to the Windows Data Protection API, so they cannot use
ConvertFrom-SecureString to generate an encrypted plaintext version of the token without a custom encryption
key.
If you are not concerned about storing the token in plain text in the profile.ps1, you can set it like this:
$PSDefaultParameterValues['*Sourcegraph*:Endpoint'] = 'https://sourcegraph.example.com'
$PSDefaultParameterValues['*Sourcegraph*:Token'] = 'YOUR_PLAINTEXT_TOKEN' | ConvertTo-SecureString -AsPlainText -ForceAlternatively, you could store the token in a password manager or the Keychain, then retrieve it in your profile and set it the same way.

