<commit_before>#!/usr/bin/env bash
### _dotfileshelp.sh -- grep for comments in readline, bash, zsh, i3, vim cfg

_DOTFILES_GREP_NUMBER_LINES=""

#   dotfileshelp  [-n] [-h] [-v -e -d] [<cmd> [<arg1> [<argn>]]]
#
#     <cmd> may be zero or one of { all, readline, bash, zsh, i3, vim }
#
#     -n/--number-lines  -- print line numbers
#
#     -h/--help          -- print help
#     -v/--verbose       -- set -x       (print commands and arguments)
#     -e/--errexit       -- set -e       (exit if any command returns nonzero)
#     -d/--debug         -- set -x -v -e (see: ``help set``)
#        --test          -- run tests
#
#     Usage examples:
#
#         $ dotfileshelp -h
#         $ dotfileshelp -v -h
#         $ dhelp
#         $ dh
#         $ dh all
#         $ dh all -n -v
#         $ dh readline
#         $ dh bash
#         $ dh zsh
#         $ dh i3
#         $ dh vim
#         $ dh dotfiles
#
#  ### dhelp bash functions:
#

if [ -z "${__DOTFILES}" ]; then
    if [ -n "${BASH_SOURCE}" ]; then
        __DOTFILES="$(dirname "$(dirname "${BASH_SOURCE}")")"
    else
        echo "Err: __DOTFILES is not set. defaulting to '.'" >&2
        __DOTFILES="."
    fi
fi

PYLINE="${PYLINE:-"${__DOTFILES}/scripts/pyline.py"}"
if [ ! -f "${PYLINE}" ]; then
    echo 'Err: PYLINE="'"${PYLINE}"'" not found'
fi

_SRC_GITBRANCH="${_SRC_GITBRANCH:-"develop"}"
_SRC_URL="https://github.com/westurner/dotfiles/tree/${_SRC_GITBRANCH}"

_SRC_GITBRANCH__DOTVIM="${_SRC_GITBRANCH__DOTVIM:-"master"}"
_SRC_URL__DOTVIM="https://github.com/westurner/dotvim/tree/${_SRC_GITBRANCH__DOTVIM}"

function dhelp_shell {
    ## dhelp_shell()             -- grep comments in a .sh file
    local _file="${1}"
    "${PYLINE}" \
        -r '^(\s*)(#+)(\s)(\s*.*)' \
        'rgx and u"%s%s%s%s" % ((rgx.group(1), " " if len(rgx.group(2)) == 1 else rgx.group(2), rgx.group(3), rgx.group(4)))' \
        -f "${_file}" \
        "${_DOTFILES_GREP_NUMBER_LINES}";
}

function dhelp_help {
    ## dhelp_help() -- grep shell comments in this file ($BASH_SOURCE)
    local _file="${1:-"${BASH_SOURCE}"}"
    printf_file_heading "=" "${_file}"
    dhelp_shell "${_file}" \
        | printf_code "bash"
    echo ""
    echo ""
    return
}

function dhelp_dotfiles {
    ## dhelp_dotfiles()          -- grep comments in bootstrap_dotfiles.sh
    local _file="${1:-"${__DOTFILES}/scripts/bootstrap_dotfiles.sh"}"
    printf_file_heading "=" "${_file}"
    "${_file}" -h \
        | printf_code "bash"<commit_msg>DOC: _dotfileshelp.sh (dh): skip '# shellcheck' directives<commit_after>#!/usr/bin/env bash
### _dotfileshelp.sh -- grep for comments in readline, bash, zsh, i3, vim cfg

_DOTFILES_GREP_NUMBER_LINES=""

#   dotfileshelp  [-n] [-h] [-v -e -d] [<cmd> [<arg1> [<argn>]]]
#
#     <cmd> may be zero or one of { all, readline, bash, zsh, i3, vim }
#
#     -n/--number-lines  -- print line numbers
#
#     -h/--help          -- print help
#     -v/--verbose       -- set -x       (print commands and arguments)
#     -e/--errexit       -- set -e       (exit if any command returns nonzero)
#     -d/--debug         -- set -x -v -e (see: ``help set``)
#        --test          -- run tests
#
#     Usage examples:
#
#         $ dotfileshelp -h
#         $ dotfileshelp -v -h
#         $ dhelp
#         $ dh
#         $ dh all
#         $ dh all -n -v
#         $ dh readline
#         $ dh bash
#         $ dh zsh
#         $ dh i3
#         $ dh vim
#         $ dh dotfiles
#
#  ### dhelp bash functions:
#

if [ -z "${__DOTFILES}" ]; then
    if [ -n "${BASH_SOURCE}" ]; then
        __DOTFILES="$(dirname "$(dirname "${BASH_SOURCE}")")"
    else
        echo "Err: __DOTFILES is not set. defaulting to '.'" >&2
        __DOTFILES="."
    fi
fi

PYLINE="${PYLINE:-"${__DOTFILES}/scripts/pyline.py"}"
if [ ! -f "${PYLINE}" ]; then
    echo 'Err: PYLINE="'"${PYLINE}"'" not found'
fi

_SRC_GITBRANCH="${_SRC_GITBRANCH:-"develop"}"
_SRC_URL="https://github.com/westurner/dotfiles/tree/${_SRC_GITBRANCH}"

_SRC_GITBRANCH__DOTVIM="${_SRC_GITBRANCH__DOTVIM:-"master"}"
_SRC_URL__DOTVIM="https://github.com/westurner/dotvim/tree/${_SRC_GITBRANCH__DOTVIM}"

function dhelp_shell {
    ## dhelp_shell()             -- grep comments in a .sh file
    local _file="${1}"
    "${PYLINE}" \
        -r '^(\s*)(#+)(\s)(\s*.*)' \
        'rgx and u"%s%s%s%s" % ((rgx.group(1), " " if len(rgx.group(2)) == 1 else rgx.group(2), rgx.group(3), rgx.group(4))) if not l.lstrip().startswith("# shellcheck") else None' \
        -f "${_file}" \
        "${_DOTFILES_GREP_NUMBER_LINES}";
}

function dhelp_help {
    ## dhelp_help() -- grep shell comments in this file ($BASH_SOURCE)
    local _file="${1:-"${BASH_SOURCE}"}"
    printf_file_heading "=" "${_file}"
    dhelp_shell "${_file}" \
        | printf_code "bash"
    echo ""
    echo ""
    return
}

function dhelp_dotfiles {
    ## dhelp_dotfiles()          -- grep comments in bootstrap_dotfiles.sh
    local _file="${1:-"${__DOTFILES}/scripts/bootstrap_dotfiles.sh"}"
    printf_file_heading "=" "${_file}"
    "${_file}" -h \
        | printf_code "bash"
{'fraction_non_alphanumeric': 0.18846002363135092, 'fraction_numerical': 0.005513981882630957, 'mean_word_length': 2.298051948051948, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2726191', 'n_tokens_mistral': 1977, 'n_tokens_neox': 1924, 'n_words': 416}