Skip to content

Instantly share code, notes, and snippets.

@johnlindquist
Created January 30, 2026 19:31
Show Gist options
  • Select an option

  • Save johnlindquist/4deb59e4d74a36c8a4cc2362663f8299 to your computer and use it in GitHub Desktop.

Select an option

Save johnlindquist/4deb59e4d74a36c8a4cc2362663f8299 to your computer and use it in GitHub Desktop.
funced - Edit zsh functions in your editor at the definition line
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