Get started and run your first code search from the command line in 10 minutes or less.
In this guide, you'll install the Sourcegraph CLI,
src, connect it to your Sourcegraph instance, and use it to run a code search.
src is shipped as a single, standalone binary. You can get the latest release by following the instructions for your operating system below (check out the GitHub page for additional documentation):
curl -L https://sourcegraph.com/.api/src-cli/src_darwin_amd64 -o /usr/local/bin/src chmod +x /usr/local/bin/src
brew install sourcegraph/src-cli/src-cli
curl -L https://sourcegraph.com/.api/src-cli/src_linux_amd64 -o /usr/local/bin/src chmod +x /usr/local/bin/src
You can install using PowerShell as follows:
New-Item -ItemType Directory 'C:\Program Files\Sourcegraph' Invoke-WebRequest https://sourcegraph.com/.api/src-cli/src_windows_amd64.exe -OutFile 'C:\Program Files\Sourcegraph\src.exe' [Environment]::SetEnvironmentVariable('Path', [Environment]::GetEnvironmentVariable('Path', [EnvironmentVariableTarget]::Machine) + ';C:\Program Files\Sourcegraph', [EnvironmentVariableTarget]::Machine) $env:Path += ';C:\Program Files\Sourcegraph'
For other options, please refer to the Windows specific
Connect to Sourcegraph
src needs to be authenticated against your Sourcegraph instance. The quickest way to do this is to run
src login https://YOUR-SOURCEGRAPH-INSTANCE and follow the instructions:
Once complete, you should have two new environment variables set:
Run a code search
Searching is performed using the
src search command. For example, to search for
ResolveRepositories in the
src repository, you can run:
src search 'r:github.com/sourcegraph/src-cli ResolveRepositories'
This should result in this output:
You've run your first search from the command line! 🎉🎉
To learn what else you can do with
src, see "CLI" in the Sourcegraph documentation.