Created
January 30, 2026 19:31
-
-
Save johnlindquist/4deb59e4d74a36c8a4cc2362663f8299 to your computer and use it in GitHub Desktop.
funced - Edit zsh functions in your editor at the definition line
This file contains hidden or 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
| funced () { | |
| [[ -z "$1" ]] && { | |
| echo "Usage: funced <function_name>" | |
| return 1 | |
| } | |
| local func="$1" | |
| [[ $(whence -w "$func" 2>/dev/null) != *function* ]] && { | |
| echo "'$func' is not a function" | |
| return 1 | |
| } | |
| local file="${functions_source[$func]}" | |
| [[ -z "$file" || ! -f "$file" ]] && { | |
| echo "Can't find source file for '$func'" | |
| return 1 | |
| } | |
| local line=$(grep -n -m1 -E "^\s*(function\s+)?${func}\s*\(|eval\s+[\"']${func}\s*\(" "$file" | cut -d: -f1) | |
| [[ -z "$line" ]] && line=1 | |
| local editor_name="${EDITOR_CMD:t}" | |
| case "$editor_name" in | |
| (zed) "$EDITOR_CMD" "$file:$line" ;; | |
| (cursor | code | code-insiders) "$EDITOR_CMD" -g "$file:$line" ;; | |
| (micro) "$EDITOR_CMD" "+$line" "$file" ;; | |
| (vim | nvim) "$EDITOR_CMD" "+$line" "$file" ;; | |
| (*) "$EDITOR_CMD" "$file:$line" ;; | |
| esac | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment