Skip to content

Instantly share code, notes, and snippets.

@sebastiancarlos
Last active August 23, 2023 12:02
Show Gist options
  • Save sebastiancarlos/6bdab0fcabe62818e9d04a77d31254c3 to your computer and use it in GitHub Desktop.
Save sebastiancarlos/6bdab0fcabe62818e9d04a77d31254c3 to your computer and use it in GitHub Desktop.
Custom version of "declare -F" with filename and line number.
# All my gist code is licensed under the terms of the MIT license.
# Video demo: https://www.youtube.com/shorts/q26DJ5qOXxM
# custom declare -F
# - add filename and table output to "declare -F"
# - this is based on the "declare -F name" output when shopt extdebug is on
function declare () {
if [[ $# == 1 && "$1" == "-F" ]]; then
shopt -s extdebug
source <(
command declare -F | \
awk '
{
print "declare -F " $NF;
}'
) | \
sed -E "s|$HOME|~|g" | \
column -t
shopt -u extdebug
else
command declare "$@";
fi;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment