diff --git a/.aliases_functions.sh b/.aliases_functions.sh index 03d0161..7cfe10b 100644 --- a/.aliases_functions.sh +++ b/.aliases_functions.sh @@ -99,6 +99,24 @@ define(){ declare -f $1 | bat --style numbers,grid --language sh || return 0 # declare only on functions, don't error out if $1 is an alias } +# Shows definition of all functions that match the passed string (case insensitive). TODO: support aliases as well +define_all() { + local function_names="" + + if [ -n "$BASH_VERSION" ]; then + function_names=$(declare -F | awk '{print $3}') + elif [ -n "$ZSH_VERSION" ]; then + function_names=$(print -l ${(k)functions}) + fi + + matches=$(echo $function_names | grep -i $1) + + # ${=var} splits the string on whitespace into an array. Only required for zhs, in bash this is a noop and works as expected. + for match in ${=matches}; do + define $match + done +} + # default: returns a default value if STDIN is empty, otherwise return STDIN default() { grep . || echo $1 @@ -465,4 +483,4 @@ EOF export TABLEAU_SITE_ID=$(tableau_get "/sites" | jq -r ".sites.site[] | select(.contentUrl == \"$TABLEAU_CONTENTURL\").id") cenv TABLEAU_SITE_ID -} \ No newline at end of file +}