Quickstart for src
Get started and run your first code search from the command line in 10 minutes or less.
Introduction
In this guide, you'll install the Sourcegraph CLI, src, connect it to your Sourcegraph instance, and use it to run a code search.
Installation
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 repository for additional documentation):
macOS
SHbrew install sourcegraph/src-cli/src-cli
or
SHcurl -L https://sourcegraph.com/.api/src-cli/src_darwin_amd64 -o /usr/local/bin/src chmod +x /usr/local/bin/src
Linux
SHcurl -L https://sourcegraph.com/.api/src-cli/src_linux_amd64 -o /usr/local/bin/src chmod +x /usr/local/bin/src
Windows
You can install using PowerShell as follows:
POWERSHELLNew-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 src documentation.
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: SRC_ENDPOINT and SRC_ACCESS_TOKEN.
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:
SHsrc search 'r:github.com/sourcegraph/src-cli NewArchiveRegistry'
This should result in this output:
Congratulations!
You've run your first search from the command line! ๐๐
You can now explore the range of commands src provides, including the extensive support for batch changes.
To learn what else you can do with src, see "CLI" in the Sourcegraph documentation.
Troubleshooting
If you run into authentication issues, the frontend container is the best place to check for useful logs.
Gzip Error on Apache Proxies
If you are running src login through an apache proxy, you may run into the following error in your frontend logs:
BASH"error":"gzip: invalid header"
Please check your httpd.conf for the following:
SHELL<Location> ... SetInputFilter DEFLATE ... </Location>
If this is present, you will need to delete SetInputFilter DEFLATE. If not, it will result in sending an unexpected response back to src, which will, in turn, be rejected.