{"id":13862996,"url":"https://github.com/LangLangBart/gh-find-code","last_synced_at":"2025-07-14T13:33:04.270Z","repository":{"id":180466971,"uuid":"665183462","full_name":"LangLangBart/gh-find-code","owner":"LangLangBart","description":"GitHub code searching with 'fzf'","archived":false,"fork":false,"pushed_at":"2024-11-10T18:16:55.000Z","size":293,"stargazers_count":46,"open_issues_count":0,"forks_count":3,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-11-10T19:25:56.291Z","etag":null,"topics":["gh-extension"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/LangLangBart.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-07-11T16:09:25.000Z","updated_at":"2024-11-10T18:16:58.000Z","dependencies_parsed_at":null,"dependency_job_id":"db9633d2-5ba4-4e67-a4cb-4d1e42b634f2","html_url":"https://github.com/LangLangBart/gh-find-code","commit_stats":null,"previous_names":["langlangbart/gh-find-code"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LangLangBart%2Fgh-find-code","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LangLangBart%2Fgh-find-code/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LangLangBart%2Fgh-find-code/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LangLangBart%2Fgh-find-code/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LangLangBart","download_url":"https://codeload.github.com/LangLangBart/gh-find-code/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225980898,"owners_count":17554919,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["gh-extension"],"created_at":"2024-08-05T06:01:59.324Z","updated_at":"2025-07-14T13:33:04.242Z","avatar_url":"https://github.com/LangLangBart.png","language":"Shell","funding_links":[],"categories":["Shell","🧩 Categories","gh-extension","Search"],"sub_categories":["Search \u0026 Discovery"],"readme":"\u003cdiv align=\"center\"\u003e\n\n# gh find-code\n\nThis extension is a command-line tool that uses the GitHub REST API and `fzf` to\ninteractively search and preview code.\n\n\u003cimg\nsrc=\"https://github.com/LangLangBart/gh-find-code/assets/92653266/144c966d-a5ac-4715-a7b3-7e6684bcf3d0\"\nwidth=\"800\"\u003e\n\n\u003c/div\u003e\n\n---\n\n## 👨‍💻 Usage\n\n```sh\ngh find-code [Flags] [Search query]\n```\n\n- Use valid qualifiers to refine the results of your search.\n  - [GitHub Docs - Searching Code](https://docs.github.com/en/search-github/searching-on-github/searching-code)\n  - [GitHub Docs - Understanding the search syntax](https://docs.github.com/en/search-github/getting-started-with-searching-on-github/understanding-the-search-syntax)\n\n| Qualifier                      | Search query example             | Description                                             |\n| ------------------------------ | -------------------------------- | ------------------------------------------------------- |\n| `in`                           | `'in:path zsh'`                  | matches code where `zsh` appears in the file path       |\n| `user`                         | `'user:ashtom Development'`      | files with the word `Development` only from `@ashtom`   |\n| `org`                          | `'org:cli searcher'`             | searches all code in the `cli` org for `searcher`       |\n| `repo`                         | `'repo:junegunn/fzf FZF_PORT'`   | searches only in the `junegunn/fzf` repo for `FZF_PORT` |\n| `path`                         | `'path:.github shfmt'`           | files with the word `shfmt` in the `.github` path       |\n| `language`                     | `'language:js \"new Proxy\"'`      | search for the string `new Proxy` in JavaScript files   |\n| `size` \u003cbr\u003e (\u003e, \u003e=, \u003c, and \u003c=) | `'size:\u003c100 _gnu_generic'`       | files smaller than 100 bytes with `_gnu_generic`        |\n| `filename`                     | `'filename:.zshrc GOCACHE'`      | search in all filenames `.zshrc` for `GOCACHE`          |\n| `extension`                    | `'extension:rs \"Hello, world!\"'` | find `.rs` files with the string `Hello, world!`        |\n\n\u003e [!IMPORTANT]\n\u003e The search syntax differs between the WebUI and the REST API, with the latter\n\u003e not supporting regex.\n\n---\n\n| Flags | Description                                              |\n| ----- | -------------------------------------------------------- |\n| `-l`  | limit the number of listed results (default 30, max 100) |\n| `-h`  | help                                                     |\n\n| Key Bindings fzf | Purpose                                  | Keybind Environment Variable   |\n| ---------------- | ---------------------------------------- | ------------------------------ |\n| `?`              | toggle help                              |                                |\n| `ctrl-b`         | open the file in the browser             | `GHFC_OPEN_BROWSER_KEY`        |\n| `ctrl-o`         | open the file content in the editor      | `GHFC_OPEN_EDITOR_KEY`         |\n| `ctrl-p`         | prepend \"repo:{owner/name}\" to the query | `GHFC_FILTER_BY_REPO_KEY`      |\n| `ctrl-r`         | reload with up to 100 results            | `GHFC_RELOAD_KEY`              |\n| `ctrl-space`     | toggle command history                   | `GHFC_TOGGLE_HISTORY_KEY`      |\n| `ctrl-t`         | toggle between Code and Fuzzy search     | `GHFC_TOGGLE_FUZZY_SEARCH_KEY` |\n| `ctrl-x`         | open the search query in the browser     | `GHFC_OPEN_BROWSER_QUERY_KEY`  |\n| `enter`          | open the file in the pager               | `GHFC_VIEW_CONTENTS_KEY`       |\n| `tab`            | toggle the file preview                  | `GHFC_TOGGLE_PREVIEW_KEY`      |\n| `esc`            | quit                                     |                                |\n\nTo avoid interfering with a user's typical keybinds, key bindings can be customized by setting the\ncorresponding environment variables. For example, to change the key binding for opening a file in\nthe browser from `ctrl-b` to `ctrl-k`:\n\n```sh\nGHFC_OPEN_BROWSER_KEY=\"ctrl-k\" gh find-code\n```\n\n\u003e [!NOTE]\n\u003e The assigned key must be a valid key listed under `AVAILABLE KEYS` in the `fzf` man page.\n\u003e ```sh\n\u003e man fzf | less --pattern \"AVAILABLE KEYS\"\n\u003e ```\n\n---\n\n## 💻 Requirements and Installation\n- [bat](https://github.com/sharkdp/bat#installation) - preview looks better\n- [curl](https://github.com/curl/curl) - sending updates to `fzf`\n- [Fuzzy Finder (fzf)](https://github.com/junegunn/fzf#installation) - allow for\n  interaction with listed data\n- [GitHub command line tool (gh)](https://github.com/cli/cli#installation) - get\n  the data from Github\n- [Python](https://www.python.org) - used to parse and open custom URLs on\n  different operating systems\n\n```sh\n# install this extension\ngh ext install LangLangBart/gh-find-code\n# upgrade\ngh ext upgrade LangLangBart/gh-find-code\n# uninstall\ngh ext remove LangLangBart/gh-find-code\n```\n\n---\n\n## 🌐 Environment Variables\n\n**Table 1: Environment Variables Utilized**\n\n| Variable    | Purpose                                | Default            |\n| ----------- | -------------------------------------- | ------------------ |\n| `BAT_THEME` | Preview theme for syntax highlighting. | `Monokai Extended` |\n| `EDITOR`    | Editor to open selected files.         | `vim`              |\n| `PAGER`     | Pager for file viewing.                | `less`             |\n\n**Table 2: Environment Variables Defined and Utilized**\n\n| Variable             | Purpose                       | Default                                                          |\n| -------------------- | ----------------------------- | ---------------------------------------------------------------- |\n| `GHFC_DEBUG_MODE`    | Enable debug mode             | `0` (Disabled)                                                   |\n| `GHFC_HISTORY_FILE`  | Custom location               | `${XDG_STATE_HOME:-$HOME/.local/state}/gh-find-code/history.txt` |\n| `GHFC_HISTORY_LIMIT` | Max number of stored commands | `500`                                                            |\n\n---\n\n## 💁 TIPS\n\n### Alias\n- The name `gh find-code` was chosen for its descriptive nature. For frequent\n  use, consider setting up an alias.\n\n```sh\n# ~/.bashrc or ~/.zshrc\nalias ghfc='gh find-code'\n# or add a custom 'BAT_THEME'/ 'EDITOR'\nalias ghfc='BAT_THEME=\"Dracula\" EDITOR=\"vim\" gh find-code'\n```\n\n### Bat\n- Set `BAT_THEME` to change the preview color scheme:\n```sh\n# To view all default themes\nbat --list-themes --color=never\n# Recommended themes: 1337, Dracula, gruvbox-dark, Monokai Extended\n# To launch this extension with the 'Dracula' theme\nBAT_THEME=\"Dracula\" gh find-code\n```\n\n### Editor\n- The extension uses the `EDITOR` environment variable to determine in which\n  editor the selected file will be opened, works with `nano`, `nvim/vi/vim`,\n  and `VSCode` and some of its derivatives (e.g. `VSCodium`).\n- The code from opened files is stored temporarily and is removed when the\n  program ends.\n\n```sh\n# Set the editor to Visual Studio Code\nEDITOR=\"code\" gh find-code\n```\n\n### Fuzzy Finder (fzf)\n- Scroll the preview in larger steps by adding this snippet to your shell setup.\n\n```sh\n# ~/.bashrc or ~/.zshrc\n# scroll the preview in larger steps with ctrl+w/s\nexport FZF_DEFAULT_OPTS=\"\n--bind 'ctrl-w:preview-half-page-up,ctrl-s:preview-half-page-down'\"\n```\n\n- See `man fzf` for `AVAILABLE KEYS` or\n  [junegunn/fzf](https://github.com/junegunn/fzf#environment-variables) for more\n  details.\n- **NOTE:** [How to use ALT commands in a terminal on macOS?](https://superuser.com/questions/496090/how-to-use-alt-commands-in-a-terminal-on-os-x)\n\n### History\n- The history file stores successfully completed unique commands.\n- Customize history file location and limit:\n\n```sh\n# Specify a custom location for the history file\nGHFC_HISTORY_FILE=\"/custom/location/history.txt\" gh find-code\n# Set the maximum number of stored commands to 1000\nGHFC_HISTORY_LIMIT=\"1000\" gh find-code\n```\n\n### Pattern Matching\n- In rare cases, when the API returns patterns with newline characters, `pcre2grep`, `pcregrep`, or\n  `rg` will be used to find line numbers if any of them is installed. Otherwise, `grep` will be used\n  by default, which will not match patterns containing newlines.\n\n---\n\n## 🤔 Pitfall\n\n### Incorrect Line Numbers\n\nThe API may return irrelevant `text` matches, which can lead to incorrect line numbers in the entire\ndocument.\n\nI occasionally encounter this issue in `readme.md` files when the fragment contains Asian characters\nprior to the desired search keyword. For example, when searching for `commander.js` in the\n`nieweidong/fetool` repository, the API may return text matches that are all 12 characters long, but\nthere seems to be a bug in the GitHub code as it does not correctly count when the search keyword\nappears in the fragment. Instead of matching `commander.js`, it returns `er](https://`.\n\n- Ref: [GitHub Docs - Text Match Metadata](https://docs.github.com/en/rest/search/search#text-match-metadata)\n\n```sh\ncommand gh api search/code --method GET --cache 1h --field per_page=1 \\\n  --header 'Accept: application/vnd.github.text-match+json' \\\n  --raw-field 'q=repo:nieweidong/fetool commander.js' \\\n  --jq '.items[].text_matches[].matches | first | {text}'\n```\n```json\n{\n  \"text\": \"er](https://\"\n}\n```\n\nHere is an example of a proper `text` response from the search API:\n```sh\ncommand gh api search/code --method GET --cache 1h --field per_page=1 \\\n  --header 'Accept: application/vnd.github.text-match+json' \\\n  --raw-field 'q=repo:calvinmetcalf/ltcdr commander.js' \\\n  --jq '.items[].text_matches[].matches | first | {text}'\n```\n```json\n{\n  \"text\": \"commander.js\"\n}\n```\n\n---\n\n## 💪 Contributing\n\n\u003e [!NOTE]\n\u003e _Pre-commit is a multi-language package manager for pre-commit hooks. You_\n\u003e _specify a list of hooks you want and pre-commit **manages** the installation_\n\u003e _and **execution** of any hook written in any language before every commit._\n\u003e\n\u003e **Source:** [pre-commit introduction](https://pre-commit.com/#introduction)\n\n```sh\n# install the git hook scripts\npre-commit install --hook-type commit-msg --hook-type pre-commit\n# pre-commit installed at .git/hooks/commit-msg\n# pre-commit installed at .git/hooks/pre-commit\n```\n\n---\n\n## ⭐ Noteworthy Projects\n- [Official GitHub Search](https://github.com/search?type=code)\n- [grep.app | code search](https://grep.app/)\n- [k1LoW/gh-grep](https://github.com/k1LoW/gh-grep)\n- [johnlindquist/ghx](https://github.com/johnlindquist/ghx)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FLangLangBart%2Fgh-find-code","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FLangLangBart%2Fgh-find-code","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FLangLangBart%2Fgh-find-code/lists"}