mirror of
https://github.com/ivuorinen/dotfiles.git
synced 2026-02-16 20:54:00 +00:00
fix(dfm): update traps and tests (#124)
* fix(dfm): update traps and tests * fix(dfm): initialize defaults and secure tests * fix(tests): secure helper quoting and extend install coverage * fix(utils): avoid double extension when resolving command * fix(tests): quote paths and add strict mode * fix(utils): escape function name in regex
This commit is contained in:
@@ -673,19 +673,21 @@ main::get_command_functions()
|
||||
# desc=$(main::get_function_description "install" "my_function")
|
||||
main::get_function_description()
|
||||
{
|
||||
local cmd="$1"
|
||||
local cmd_file="$1"
|
||||
local func="$2"
|
||||
local cmd_file="${DFM_CMD_DIR}/${cmd}.sh"
|
||||
|
||||
if [[ ! -f "$cmd_file" && -f "$cmd" ]]; then
|
||||
cmd_file="$cmd"
|
||||
fi
|
||||
|
||||
if [[ ! -f "$cmd_file" ]]; then
|
||||
return 1
|
||||
[[ -n ${DFM_CMD_DIR:-} ]] || return 1
|
||||
cmd_file="${DFM_CMD_DIR}/${cmd_file}"
|
||||
[[ "$cmd_file" == *.sh ]] || cmd_file="${cmd_file}.sh"
|
||||
fi
|
||||
|
||||
grep -B1 "^[[:space:]]*\(function[[:space:]]*\)\{0,1\}$func().*{" "$cmd_file" \
|
||||
[[ -f "$cmd_file" ]] || return 1
|
||||
|
||||
local escaped_func
|
||||
escaped_func=$(printf '%s' "$func" | sed 's/[][\\.^$*+?(){}|]/\\&/g')
|
||||
|
||||
grep -B5 -E "^[[:space:]]*(function[[:space:]]*)?${escaped_func}[[:space:]]*\\(\\)[[:space:]]*(\\{)?[[:space:]]*$" "$cmd_file" \
|
||||
| grep "@description" \
|
||||
| sed -E 's/^[[:space:]]*#[[:space:]]*@description[[:space:]]*//'
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user