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…


This content originally appeared on DEV Community and was authored by Bhupesh Varshney 👾

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


This content originally appeared on DEV Community and was authored by Bhupesh Varshney 👾


Print Share Comment Cite Upload Translate Updates
APA

Bhupesh Varshney 👾 | Sciencx (2021-12-13T10:14:17+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 ,<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 ]. 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 . 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: ]
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/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.