This repository has been archived on 2024-03-04. You can view files and clone it, but cannot push or open issues or pull requests.
linux/.config/bash/module/help.sh

26 lines
566 B
Bash
Raw Normal View History

2023-12-07 04:02:47 +03:00
# Get help about dotfiles bash function.
# Usage: help <FUNCTION>
2023-12-07 01:44:42 +03:00
function help() {
local fun="${1}"
2023-12-07 04:51:23 +03:00
if [[ "${fun}" = "" ]] || [[ "$(find_function | grep ${fun})" = "" ]]; then
2023-12-07 04:02:47 +03:00
help help
return 2
2023-12-07 01:44:42 +03:00
fi
2023-12-07 04:02:47 +03:00
sed -e '$s/$/\n/' -s "${BASH_MODULE_PATH}"/* | sed -n -e "/function ${fun}()/q;p" | tac | sed -n -e "/^$/q;p" | tac | sed -e "s/^# \+//"
2023-12-07 01:44:42 +03:00
}
# Short for help.
2023-12-07 04:02:47 +03:00
# Usage: h <FUNCTION>
2023-12-07 01:44:42 +03:00
function h() {
help "${@}"
}
2023-12-07 01:51:33 +03:00
2023-12-07 04:02:47 +03:00
# Autocomplete with available functions.
2023-12-07 01:51:33 +03:00
function _help_functions() {
2023-12-07 04:51:23 +03:00
_autocomplete_first $(find_function)
2023-12-07 01:51:33 +03:00
}
complete -F _help_functions help h