View a python function’s history over-time with Git & FZF

I am kinda hooked up on modifying my git terminal workflow and integrate FZF wherever I can, this is such an example script to see changes in a python function overtime in your git history. And yes, its interesting (& stupid)

#!/usr/bin/env bash…

I am kinda hooked up on modifying my git terminal workflow and integrate FZF wherever I can, this is such an example script to see changes in a python function overtime in your git history. And yes, its interesting (& stupid)

#!/usr/bin/env bash

# FZF Wrapper over git to interactively search code changes inside functions

readarray -t choices < <(git ls-files | fzf \
  --prompt="Choose File: " \
  --height 40% --reverse \
)

printf "%s\n" "$(grep -o -P '(?<=def ).*?(?=\()' $choices)" | fzf \
--ansi --preview "echo {} | xargs -I{} git log --color -L :{}:$choices" \
--prompt="Choose function/method: " \
--bind 'j:down,k:up,ctrl-j:preview-down,ctrl-k:preview-up,ctrl-space:toggle-preview' --preview-window right:60% \

The actual trick is finding all python functions and methods names in a given file using grep

$ grep -o -P '(?<=def ).*?(?=\()' rich/columns.py
__init__
add_renderable
__rich_console__
iter_renderables

Next we plug the function name with filename in this git command

git log -L :funciton_name:relative_file_path

Read more about git log searching

Below is a screencast demoing the same for rich package

git-search-demo-gif

If you are still interested, here is the script to hack around.

I wish this was scalable to all the programming languages but currently I don’t have any clue on how to do this
If you want to contribute help me by adding grep patterns to do the same search for you favourite programming language. Thanks


Print Share Comment Cite Upload Translate
APA
Bhupesh Varshney 👾 | Sciencx (2024-03-28T15:03:38+00:00) » View a python function’s history over-time with Git & FZF. Retrieved from https://www.scien.cx/2021/12/13/view-a-python-functions-history-over-time-with-git-fzf/.
MLA
" » View a python function’s history over-time with Git & FZF." Bhupesh Varshney 👾 | Sciencx - Monday December 13, 2021, https://www.scien.cx/2021/12/13/view-a-python-functions-history-over-time-with-git-fzf/
HARVARD
Bhupesh Varshney 👾 | Sciencx Monday December 13, 2021 » View a python function’s history over-time with Git & FZF., viewed 2024-03-28T15:03:38+00:00,<https://www.scien.cx/2021/12/13/view-a-python-functions-history-over-time-with-git-fzf/>
VANCOUVER
Bhupesh Varshney 👾 | Sciencx - » View a python function’s history over-time with Git & FZF. [Internet]. [Accessed 2024-03-28T15:03:38+00:00]. Available from: https://www.scien.cx/2021/12/13/view-a-python-functions-history-over-time-with-git-fzf/
CHICAGO
" » View a python function’s history over-time with Git & FZF." Bhupesh Varshney 👾 | Sciencx - Accessed 2024-03-28T15:03:38+00:00. https://www.scien.cx/2021/12/13/view-a-python-functions-history-over-time-with-git-fzf/
IEEE
" » View a python function’s history over-time with Git & FZF." Bhupesh Varshney 👾 | Sciencx [Online]. Available: https://www.scien.cx/2021/12/13/view-a-python-functions-history-over-time-with-git-fzf/. [Accessed: 2024-03-28T15:03:38+00:00]
rf:citation
» View a python function’s history over-time with Git & FZF | Bhupesh Varshney 👾 | Sciencx | https://www.scien.cx/2021/12/13/view-a-python-functions-history-over-time-with-git-fzf/ | 2024-03-28T15:03:38+00:00
https://github.com/addpipe/simple-recorderjs-demo