How do I filter by file type on Sourcegraph?

7k Views Asked by At

I want to do a Sourcegraph search and have it show only results from files with a certain extension.

2

There are 2 best solutions below

0
On BEST ANSWER

You can use the file: token to filter results by filename regex. For example, file:\.go$ would limit results to files ending in ".go".

The full search query syntax is documented here: https://docs.sourcegraph.com/code_search/reference/queries

0
On

I wanted to search drizzle migration commands in bash script that ends in .sh extension so I used:

drizzle file:\.sh$

\ is used to escape the . while $ signifies the end of the string. So .sh is surrounded by \ & $.

Works for other languages as well:

  1. \.js$ - JavaScript
  2. \.ts$ - TypeScript
  3. \.jsx$ or \.tsx - JSX
  4. \.py$ - Python