sort functions

This commit is contained in:
zenobit 2023-03-21 02:31:51 +01:00
parent b406572a16
commit 01ae9d4802
1 changed files with 17 additions and 0 deletions

17
config/sort_functions.sh Normal file
View File

@ -0,0 +1,17 @@
#!/bin/bash
# Get the name of the script from the command line argument
script_name=$1
# Get a list of all the function names in the script
function_names=$(grep -oP '^[[:space:]]*function \K\w+' "$script_name")
# Sort the function names alphabetically
sorted_function_names=$(echo "$function_names" | sort)
# Loop through the sorted function names and print the function definitions
for function_name in $sorted_function_names
do
# Print the function definition to stdout
grep -A $(wc -l < "$script_name") -w "function $function_name" "$script_name"
done