Created
October 3, 2018 02:58
-
-
Save wting/2d104796dbd52e1e8220473351afe2b0 to your computer and use it in GitHub Desktop.
Open up all definitions of a Python class or function as vim tabs.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env zsh | |
local args name num | |
if git rev-parse --git-dir &>/dev/null; then | |
git grep -En "(def|class) ${@}[[:space:]]*[(:]" \ | |
| uniq \ | |
| while read line; do | |
name=$(echo "${line}" | awk 'BEGIN { FS=":" }; { print $1 }') | |
num=$(echo "${line}" | awk 'BEGIN { FS=":" }; { print $2 }') | |
if [ ! "${args}" ]; then | |
args=("+${num}" "${name}") | |
else | |
args+=(+"tabnew +${num} ${name}") | |
fi | |
done | |
else | |
find . \ | |
-iname "*.py" \ | |
-type f \ | |
-regextype posix-egrep \ | |
! -path './.git/*' \ | |
! -path './.tox/*' \ | |
! -path '*/build/*' \ | |
! -path '*/css/*' \ | |
! -path '*.egg-info/*' \ | |
! -path './google_appengine*/*' \ | |
! -path './logs/*' \ | |
! -path './sandbox*/*' \ | |
! -path './tmp/*' \ | |
! -path './virtualenv*/*' \ | |
! -regex "./[^/]*templates/.*" \ | |
! -path "*htdocs*" \ | |
| xargs grep -En "(def|class) ${@}[[:space:]]*[(:]" \ | |
| uniq \ | |
| while read line; do | |
name=$(echo "${line}" | awk 'BEGIN { FS=":" }; { print $1 }') | |
num=$(echo "${line}" | awk 'BEGIN { FS=":" }; { print $2 }') | |
if [ ! "${args}" ]; then | |
args=("+${num}" "${name}") | |
else | |
args+=(+"tabnew +${num} ${name}") | |
fi | |
done | |
fi | |
if [ "${args}" ]; then | |
echo "${args[@]}" | |
\vim "${args[@]}" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment