nix/home/program/bash/module/Help.nix

30 lines
666 B
Nix
Raw Normal View History

2024-04-06 03:03:58 +03:00
{ ... }: {
text = ''
# Get help about dotfiles bash function.
# Usage: help <FUNCTION>
function help() {
local fun="''${1}"
2024-05-04 15:03:52 +03:00
if [[ "''${fun}" = "" ]] || [[ "$(find_function | grep ''${fun})" = "" ]]; then
2024-04-06 03:03:58 +03:00
help help
return 2
fi
2024-08-16 21:07:54 +03:00
cat ~/.bashrc | sed -n -e "/^function ''${fun}()/q;p" | tac | sed -n -e "/^[^#]/q;p" | tac | sed -e "s/^# \+//" -e "\$i \ " | sed "1{/^$/d}" | sed "1{/^ *$/d}"
2024-04-06 03:03:58 +03:00
}
# Short for help.
# Usage: h <FUNCTION>
function h() {
help "''${@}"
}
# Autocomplete with available functions.
function _help_functions() {
_autocomplete_first $(find_function)
}
complete -F _help_functions help h
'';
}