Skip to content

Commit

Permalink
Refactorings. Removing __hhs_help. It was moved to hhs app: 'hhs help…
Browse files Browse the repository at this point in the history
…'and re-aliases help to hhs help
  • Loading branch information
yorevs committed Nov 8, 2024
1 parent c48af1b commit 4413d63
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 34 deletions.
34 changes: 32 additions & 2 deletions bin/apps/bash/hhs-app/functions/built-ins.bash
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function list() {
&& for next in $(compgen -c __hhs); do echo -n "${next} "; done
[[ ${#args[@]} -eq 1 || "${args[*]}" =~ -aliases ]] \
&& for next in "${HHS_ALIASES[@]}"; do echo -n "${next} "; done
quit 0 ''
quit 0
else
columns="$(tput cols)"
count=$((${#PLUGINS[@]} > ${#HHS_APP_FUNCTIONS[@]} ? ${#PLUGINS[@]} : ${#HHS_APP_FUNCTIONS[@]}))
Expand All @@ -48,7 +48,7 @@ function list() {
fi
fi

quit 0 ''
quit 0
}

# @purpose: Search for all __hhs_functions describing it's containing file name and line number.
Expand Down Expand Up @@ -192,6 +192,36 @@ function man() {
return 0
}

# @purpose: Attempt to display the help for the given command.
# @param $1 [Req] : The command to get help.
function help() {

local cmd="${1}" help_msg
if [[ -z "${cmd}" || "$1" == "-h" || "$1" == "--help" ]]; then
echo "usage: ${FUNCNAME[0]} <command>"
return 1
fi

__hhs_has "${cmd}" || { __hhs_errcho "${RED}Command not found: '${cmd}'"; return 1; }

help_msg="$(${cmd} --help 2>&1 | awk '/^usage:/ {found=1} found')"
if [[ -z "${help_msg}" ]]; then
help_msg="$(${cmd} help 2>&1 | awk '/^usage:/ {found=1} found')"
if [[ -z "${help_msg}" ]]; then
help_msg="$(${cmd} --0h012hux267844asu 2>&1 | awk '/^usage:/ {found=1} found')"
if [[ -z "${help_msg}" ]]; then
__hhs_errcho "${RED}Help not available for: '${cmd}'"
fi
fi
return 1
fi

echo -e "${YELLOW}Displaying help for: ${BLUE}'${cmd}'${NC}\n"
echo -e "${help_msg}\n"

return 0
}

# @purpose: Clear HomeSetup logs, backups and caches and restore original HomeSetup files.
function reset() {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

# Script: misc.bash
# Script: term.bash
# Purpose: Contains all extra HHS-App functions
# Created: Apr 29, 2020
# Author: <B>H</B>ugo <B>S</B>aporetti <B>J</B>unior
Expand Down
6 changes: 3 additions & 3 deletions bin/apps/bash/hhs-app/hhs.bash
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ function cleanup_plugins() {
# @purpose: Program entry point.
function main() {

local fn_name
local fn_name="${1}"

# Execute a cleanup after the application has exited.
trap cleanup_plugins EXIT
Expand All @@ -462,16 +462,16 @@ function main() {
register_functions
register_plugins

fn_name="${1//help/list}"

if has_function "${fn_name}"; then
shift
${fn_name} "${@}" # Invoke internal function
${fn_name} "${@}" # Invoke internal hhs-function
quit $?
fi

[[ ${#INVALID[@]} -gt 0 ]] && quit 1 "Invalid plugins found: [${RED}${INVALID[*]}${NC}]"

fn_name="${fn_name//help/list}"
invoke_plugin "${@}" || quit 2

quit 255 "${RED}Failed to invoke hhs command: ${*} ${NC}"
Expand Down
28 changes: 1 addition & 27 deletions bin/hhs-functions/bash/hhs-built-ins.bash
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ function __hhs_edit() {
# @param $1 [Req] : The command to check.
function __hhs_about() {

local cmd type_ret=() i=0 re_alias re_function re_command recurse="${2}"
local cmd type_ret=() re_alias re_function re_command recurse="${2}"
re_alias="(.*) is aliased to \`(.*)'"
re_function="(.*) is a function"
re_command="(.*) is (.*)"
Expand Down Expand Up @@ -133,32 +133,6 @@ function __hhs_about() {
return 0
}

# @function: Display a help for the given command.
# @param $1 [Req] : The command to get help.
function __hhs_help() {

local cmd

if [[ $# -eq 0 || "$1" == "-h" || "$1" == "--help" ]]; then
echo "usage: ${FUNCNAME[0]} <command>"
return 1
else
cmd="${1}"
if ! ${cmd} --help 2> /dev/null; then
if ! ${cmd} -h 2> /dev/null; then
if ! ${cmd} help 2> /dev/null; then
if ! ${cmd} /? 2> /dev/null; then
__hhs_errcho "${RED}Help not available for ${cmd}"
fi
fi
return 1
fi
fi
fi

return 0
}

# @function: Display the current dir (pwd) and remote repo url, if it applies.
# @param $1 [Req] : The command to get help.
function __hhs_where_am_i() {
Expand Down
2 changes: 1 addition & 1 deletion dotfiles/bash/bash_aliases.bash
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ alias dirs='__hhs_dirs'
# @alias: Built-ins replacement for `cat'
__hhs_has "bat" && alias cat='bat'
# @alias: Built-ins replacement for `help'
alias help='__hhs_help'
alias help='__hhs help'
# @alias: Starship replacement for `starship' binary
alias starship='__hhs_starship'
# @alias: Shortcut for `gtrash put' binary
Expand Down

0 comments on commit 4413d63

Please sign in to comment.