Skip to content

Instantly share code, notes, and snippets.

@LinuxIsCool
Last active September 21, 2023 23:51
Show Gist options
  • Select an option

  • Save LinuxIsCool/8180e62d97a9fefbc0a4179b41ba2af1 to your computer and use it in GitHub Desktop.

Select an option

Save LinuxIsCool/8180e62d97a9fefbc0a4179b41ba2af1 to your computer and use it in GitHub Desktop.
Interactively search your systems python files with ripgrep, fzf, and fish shell. Open the result with nvim.
# This is a handy utility function to search your entire systems python files for search terms. Requires fzf ripgreg and fish shell
function search-python-code
set term $argv[1]
set selected_line (rg --glob '*.py' --glob '*.ipynb' $term ~/ -n | fzf --preview 'echo {}' --preview-window=up:3:wrap)
if test -n "$selected_line"
set file (echo $selected_line | cut -d: -f1)
set line (echo $selected_line | cut -d: -f2)
nvim $file +$line
end
end
@LinuxIsCool
Copy link
Author

@LinuxIsCool
Copy link
Author

Usage:

$ search-python-code delete_item

Will allow you to navigate files containing the term 'delete_item'.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment