docs(shell): add function docstring comments

This commit is contained in:
2026-02-07 15:07:22 +02:00
parent 4266567327
commit 3ff83754b1
31 changed files with 135 additions and 3 deletions

View File

@@ -42,6 +42,7 @@ done
# Mark certain repositories shallow
git config -f .gitmodules submodule.antidote.shallow true
# Log a message using msgr if available, else echo
_log() {
local msg="$1"
if command -v msgr > /dev/null 2>&1; then
@@ -52,6 +53,7 @@ _log() {
return 0
}
# Remove a stale git submodule and clean up references
remove_old_submodule() {
local name="$1" path="$2"

View File

@@ -150,6 +150,7 @@ commit()
git commit -a -m "$commitMessage"
}
# Run Laravel scheduler in a loop
scheduler()
{
while :; do

View File

@@ -13,6 +13,7 @@ if ! command -v sesh &>/dev/null; then
exit 0
fi
# Pick a sesh session using gum filter
pick_with_gum() {
sesh list -i \
| gum filter \
@@ -41,16 +42,19 @@ FZF_COMMON_OPTS=(
--preview 'sesh preview {}'
)
# Pick a sesh session using fzf-tmux popup
pick_with_fzf_tmux() {
sesh list --icons | fzf-tmux -p 80%,70% "${FZF_COMMON_OPTS[@]}"
return 0
}
# Pick a sesh session using fzf inline
pick_with_fzf() {
sesh list --icons | fzf "${FZF_COMMON_OPTS[@]}"
return 0
}
# Pick a sesh session using bash select menu
pick_with_select() {
local sessions
mapfile -t sessions < <(sesh list)

View File

@@ -64,6 +64,7 @@ menu_builder()
done
}
# Handle install section commands
section_install()
{
USAGE_PREFIX="$SCRIPT install <command>"
@@ -193,6 +194,7 @@ section_install()
esac
}
# Handle Homebrew section commands
section_brew()
{
USAGE_PREFIX="$SCRIPT brew <command>"
@@ -291,6 +293,7 @@ section_brew()
esac
}
# Handle helper utility commands
section_helpers()
{
USAGE_PREFIX="$SCRIPT helpers <command>"
@@ -367,6 +370,7 @@ section_helpers()
esac
}
# Handle apt package manager commands
section_apt()
{
USAGE_PREFIX="$SCRIPT apt <command>"
@@ -435,6 +439,7 @@ section_apt()
esac
}
# Handle documentation generation commands
section_docs()
{
USAGE_PREFIX="$SCRIPT docs <command>"
@@ -459,6 +464,7 @@ section_docs()
esac
}
# Handle dotfiles formatting and reset commands
section_dotfiles()
{
USAGE_PREFIX="$SCRIPT dotfiles <command>"
@@ -526,6 +532,7 @@ section_dotfiles()
esac
}
# Handle system check commands (arch, hostname)
section_check()
{
USAGE_PREFIX="$SCRIPT check <command>"
@@ -552,6 +559,7 @@ section_check()
esac
}
# Handle install script execution
section_scripts()
{
USAGE_PREFIX="$SCRIPT scripts <command>"
@@ -619,6 +627,7 @@ section_tests()
esac
}
# Display main usage information for all sections
usage()
{
echo ""
@@ -642,6 +651,7 @@ usage()
section_helpers
}
# Parse section argument and dispatch to handler
main()
{
SECTION="${1:-}"

View File

@@ -22,32 +22,37 @@ if [ "$DEBUG" -eq 1 ]; then
set -x
fi
# Output functions
# Print an error message in red
msg_err()
{
echo -e "\e[31m$*\e[0m" >&2
}
# Print a success message in green
msg_success()
{
echo -e "\e[32m$*\e[0m"
}
# Print a warning message in yellow
msg_warn()
{
echo -e "\e[33m$*\e[0m" >&2
}
# Print an info message in blue
msg_info()
{
echo -e "\e[36m$*\e[0m"
}
# Print a debug message when verbose mode is on
msg_debug()
{
[[ $VERBOSE -eq 1 ]] && echo -e "\e[35m$*\e[0m"
}
# Display usage information and examples
show_help()
{
cat << EOF

View File

@@ -90,13 +90,14 @@ declare -A DIR_HAS_REPOS
# Record start time
START_TIME=$(date +%s)
# Logging functions
# Log an error message
log_error()
{
print_color "31" "ERROR:" >&2
echo " $*" >&2
}
# Log an informational message
log_info()
{
if [[ $VERBOSE -eq 1 ]]; then
@@ -105,6 +106,7 @@ log_info()
fi
}
# Log a warning message
log_warn()
{
print_color "33" "WARNING:" >&2
@@ -911,6 +913,7 @@ process_in_parallel()
echo -e "\nProcessed $total repositories in $dur (Total runtime: $runtime)"
}
# Check a directory for git status with progress tracking
check_directory_with_progress()
{
local dir

View File

@@ -23,21 +23,25 @@ CLR_RESET="\033[0m"
# │ Color functions │
# ╰──────────────────────────────────────────────────────────╯
# Wrap text in red color
function __color_red()
{
local MSG="$1"
echo -e "${CLR_RED}${MSG}${CLR_RESET}"
}
# Wrap text in yellow color
function __color_yellow()
{
local MSG="$1"
echo -e "${CLR_YELLOW}${MSG}${CLR_RESET}"
}
# Wrap text in green color
function __color_green()
{
local MSG="$1"
echo -e "${CLR_GREEN}${MSG}${CLR_RESET}"
}
# Wrap text in blue color
function __color_blue()
{
local MSG="$1"
@@ -48,36 +52,43 @@ function __color_blue()
# │ Helpers │
# ╰──────────────────────────────────────────────────────────╯
# Print blue arrow marker
function __log_marker()
{
echo -e "${CLR_BLUE}➜${CLR_RESET}"
}
# Print green checkmark marker
function __log_marker_ok()
{
echo -e "${CLR_GREEN}✔${CLR_RESET}"
}
# Print blue checkmark marker
function __log_marker_ok_blue()
{
echo -e "${CLR_BLUE}✔${CLR_RESET}"
}
# Print yellow warning marker
function __log_marker_warn()
{
echo -e "${CLR_YELLOW}⁕${CLR_RESET}"
}
# Print yellow question marker
function __log_marker_question()
{
echo -e "${CLR_YELLOW}?${CLR_RESET}"
}
# Print red error marker
function __log_marker_err()
{
echo -e "${CLR_RED}⛌${CLR_RESET}"
}
# Print indentation spacing
function __log_indent()
{
echo " "
@@ -87,71 +98,85 @@ function __log_indent()
# │ Log functions │
# ╰──────────────────────────────────────────────────────────╯
# Print a message with arrow marker
function msg()
{
echo -e "$(__log_marker) $1"
}
# Print a celebration message
function msg_yay()
{
echo -e "🎉 $1"
}
# Print a celebration message with checkmark
function msg_yay_done()
{
echo -e "🎉 $1 ...$(__log_marker_ok)"
}
# Print a message with completion checkmark
function msg_done()
{
echo -e "$(__log_marker) $1 ...$(__log_marker_ok)"
}
# Print a completion checkmark suffix
function msg_done_suffix()
{
echo -e "$(__log_marker) ...$(__log_marker_ok)"
}
# Print a prompt-style message
function msg_prompt()
{
echo -e "$(__log_marker_question) $1"
}
# Print a prompt message with checkmark
function msg_prompt_done()
{
echo -e "$(__log_marker_question) $1 ...$(__log_marker_ok)"
}
# Print an indented message
function msg_nested()
{
echo -e "$(__log_indent)$(__log_marker) $1"
}
# Print an indented message with checkmark
function msg_nested_done()
{
echo -e "$(__log_indent)$(__log_marker) $1 ...$(__log_marker_ok)"
}
# Print a running-task message in green
function msg_run()
{
echo -e "${CLR_GREEN}➜ $1${CLR_RESET} $2"
}
# Print a running-task message with checkmark
function msg_run_done()
{
echo -e "${CLR_GREEN}➜ $1${CLR_RESET} $2 ...$(__log_marker_ok)"
}
# Print an ok/success message
function msg_ok()
{
echo -e "$(__log_marker_ok) $1"
}
# Print a warning message
function msg_warn()
{
echo -e "$(__log_marker_warn) $1"
}
# Print an error message
function msg_err()
{
echo -e "$(__log_marker_err) $1"
@@ -174,6 +199,7 @@ ask()
# If this is being sourced, no need to run the next steps.
[ "$sourced" = 1 ] && return
# Run visual tests for all message types
function __tests()
{
msg "[ msg ]"
@@ -192,6 +218,7 @@ function __tests()
msg_yay_done "[ yay_done ]"
}
# Show usage information and examples
function usage()
{
echo "usage: msgr [type] [message] [optional second message]"

View File

@@ -19,7 +19,7 @@ set -euo pipefail # Add error handling
LATEST_VERSION_FORMULA="php" # The formula name for latest PHP version
PHP_VERSION_FILE=".php-version" # File name to look for when auto-switching
# Switch brew php version
# Verify that Homebrew is installed
function check_dependencies()
{
if ! command -v brew > /dev/null 2>&1; then
@@ -28,6 +28,7 @@ function check_dependencies()
fi
}
# Display help message and usage examples
function usage()
{
echo "Brew PHP Switcher - Switch between PHP versions installed via Homebrew"
@@ -53,6 +54,7 @@ function usage()
exit 0
}
# List all PHP versions installed via Homebrew
function list_php_versions()
{
# Check Homebrew's installation path for PHP versions
@@ -185,6 +187,7 @@ function list_php_versions()
done
}
# Convert a version number to a Homebrew formula name
function get_php_formula_for_version()
{
local version="$1"
@@ -199,6 +202,7 @@ function get_php_formula_for_version()
echo "php@$version"
}
# Check if a Homebrew formula is installed
function check_formula_installed()
{
local formula="$1"
@@ -216,6 +220,7 @@ function check_formula_installed()
return 1
}
# Unlink the currently active PHP version
function unlink_current_php()
{
local current_formula=""
@@ -241,6 +246,7 @@ function unlink_current_php()
fi
}
# Link a specific PHP formula as the active version
function link_php_version()
{
local formula="$1"
@@ -265,6 +271,7 @@ function link_php_version()
fi
}
# Display the currently active PHP version
function get_current_version()
{
if ! command -v php > /dev/null 2>&1; then
@@ -300,6 +307,7 @@ function get_current_version()
fi
}
# Validate PHP version format (x.y or latest)
function validate_version()
{
local version="$1"
@@ -312,6 +320,7 @@ function validate_version()
fi
}
# Search for .php-version file in directory hierarchy
function find_php_version_file()
{
local dir="$PWD"
@@ -334,6 +343,7 @@ function find_php_version_file()
return 1
}
# Auto-switch PHP based on .php-version file
function auto_switch_php_version()
{
local version_file
@@ -360,6 +370,7 @@ function auto_switch_php_version()
switch_php_version "$version"
}
# Switch to a specific PHP version
function switch_php_version()
{
local version="$1"
@@ -398,6 +409,7 @@ function switch_php_version()
echo "PHP executable: $(command -v php)"
}
# Parse arguments and dispatch to appropriate action
function main()
{
local version=""

View File

@@ -5,6 +5,7 @@
#
# Modified by Ismo Vuorinen <https://github.com/ivuorinen> 2023
# Display usage information for pushover
__pushover_usage()
{
printf "pushover <options> <message>\n"
@@ -23,6 +24,7 @@ __pushover_usage()
return 1
}
# Format an optional curl form field
__pushover_opt_field()
{
field=$1
@@ -33,6 +35,7 @@ __pushover_opt_field()
fi
}
# Send a pushover notification via curl
__pushover_send_message()
{
device="${1:-}"

View File

@@ -10,6 +10,7 @@ VERSION="1.0.0"
LANG_MAP="c:.c,.h|cpp:.cpp,.cc,.cxx,.hpp,.hxx|csharp:.cs|go:.go|java:.java|
javascript:.js,.jsx,.mjs,.ts,.tsx|python:.py|ruby:.rb|swift:.swift"
# Display usage information and options
usage()
{
cat << EOF
@@ -24,22 +25,26 @@ EOF
exit "${1:-0}"
}
# Log a timestamped message to stderr
log()
{
printf '[%s] %s\n' "$(date '+%H:%M:%S')" "$*" >&2
}
# Log an error message and exit
err()
{
log "ERROR: $*"
exit 1
}
# Verify codeql binary is available in PATH
check_codeql()
{
command -v codeql > /dev/null 2>&1 || err "codeql binary not found in PATH"
log "Found codeql: $(codeql version --format=terse)"
}
# Get or create the CodeQL cache directory
get_cache_dir()
{
cache="${XDG_CACHE_HOME:-$HOME/.cache}/codeql"
@@ -47,6 +52,7 @@ get_cache_dir()
printf '%s' "$cache"
}
# Detect supported programming languages in source path
detect_languages()
{
src_path="$1"
@@ -85,6 +91,7 @@ detect_languages()
printf '%s' "$detected" | tr ' ' '\n' | sort -u | tr '\n' ' ' | sed 's/ $//'
}
# Create a CodeQL database for a language
create_database()
{
lang="$1"
@@ -98,6 +105,7 @@ create_database()
--overwrite
}
# Display analysis result statistics from SARIF file
show_results_stats()
{
sarif_file="$1"
@@ -126,6 +134,7 @@ show_results_stats()
return 0
}
# Run CodeQL analysis for a single language
analyze_language()
{
lang="$1"
@@ -172,6 +181,7 @@ analyze_language()
rm -rf "$db_path"
}
# Parse arguments and run CodeQL analysis pipeline
main()
{
src_path="."

View File

@@ -190,6 +190,7 @@ get_custom_group()
return 1
}
# Check if a key matches the skipped keys list
is_skipped()
{
local key=$1

View File

@@ -41,6 +41,7 @@ LOOP=0
SLEEP=1
TIMEOUT=5
# Display usage information and options
usage()
{
echo "Usage: $0 [--loop|--forever] [--sleep=N] hostname1 hostname2 ..."

View File

@@ -39,16 +39,19 @@ log_error()
{
echo -e "${RED}ERROR:${NC} $1" >&2
}
# Log a warning message
log_warn()
{
echo -e "${YELLOW}WARN:${NC} $1" >&2
}
# Log an informational message
log_info()
{
if [[ "${INFO:-0}" == "1" ]]; then
echo -e "${GREEN}INFO:${NC} $1" >&2
fi
}
# Log a debug message
log_debug()
{
if [[ "${DEBUG:-0}" == "1" ]]; then

View File

@@ -49,16 +49,19 @@ log_error()
{
echo -e "${RED}ERROR:${NC} $1" >&2
}
# Log a warning message
log_warn()
{
echo -e "${YELLOW}WARN:${NC} $1" >&2
}
# Log an informational message
log_info()
{
if [[ "${INFO:-0}" == "1" ]]; then
echo -e "${GREEN}INFO:${NC} $1" >&2
fi
}
# Log a debug message
log_debug()
{
if [[ "${DEBUG:-0}" == "1" ]]; then

View File

@@ -154,6 +154,7 @@ get_state()
# ERROR HANDLING AND CLEANUP
# ============================================================================
# Clean up temporary files and handle exit
cleanup()
{
exit_code=$?
@@ -177,6 +178,7 @@ trap cleanup EXIT INT TERM
# LOGGING FUNCTIONS
# ============================================================================
# Create audit directories and initialize log file
setup_logging()
{
# Create all necessary directories
@@ -197,6 +199,7 @@ setup_logging()
} >> "$LOG_FILE"
}
# Log a message with timestamp and severity level
log_message()
{
level="$1"
@@ -225,6 +228,7 @@ log_message()
# INPUT VALIDATION
# ============================================================================
# Validate hostname format for SSH connection
validate_hostname()
{
hostname="$1"
@@ -244,6 +248,7 @@ validate_hostname()
return 0
}
# Validate username format for SSH connection
validate_username()
{
username="$1"
@@ -263,6 +268,7 @@ validate_username()
return 0
}
# Parse input file into validated host entries
parse_host_list()
{
input_file="$1"
@@ -309,6 +315,7 @@ parse_host_list()
# SSH CONNECTION FUNCTIONS
# ============================================================================
# Execute SSH command with retry logic and key fallback
ssh_with_retry()
{
host="$1"
@@ -373,6 +380,7 @@ ssh_with_retry()
return 1
}
# Verify SSH connectivity to a host
test_ssh_connectivity()
{
host="$1"
@@ -392,6 +400,7 @@ test_ssh_connectivity()
# SSH SECURITY AUDIT FUNCTIONS
# ============================================================================
# Audit SSH daemon configuration on a remote host
check_sshd_config()
{
host="$1"
@@ -451,6 +460,7 @@ check_sshd_config()
# AUTOMATED UPDATES DETECTION
# ============================================================================
# Check if automated security updates are enabled
check_automated_updates()
{
host="$1"
@@ -532,6 +542,7 @@ check_automated_updates()
# PENDING REBOOT DETECTION
# ============================================================================
# Detect if a remote host requires a reboot
check_pending_reboot()
{
host="$1"
@@ -602,6 +613,7 @@ check_pending_reboot()
# REMEDIATION FUNCTIONS
# ============================================================================
# Create a timestamped backup of sshd_config
backup_sshd_config()
{
host="$1"
@@ -616,6 +628,7 @@ backup_sshd_config()
" "$ssh_key"
}
# Disable password authentication on a remote host
disable_password_auth()
{
host="$1"
@@ -668,6 +681,7 @@ ClientAliveCountMax 2
# REPORTING FUNCTIONS
# ============================================================================
# Generate CSV report from audit results
generate_csv_report()
{
report_file="$1"
@@ -693,6 +707,7 @@ generate_csv_report()
done < "$HOSTS_LIST_FILE"
}
# Display formatted audit summary to terminal
display_summary()
{
printf '\n'
@@ -743,6 +758,7 @@ display_summary()
# MAIN AUDIT FUNCTION
# ============================================================================
# Run all audit checks on a single host
audit_host()
{
host_entry="$1"
@@ -788,6 +804,7 @@ audit_host()
# MAIN EXECUTION
# ============================================================================
# Main entry point: parse args, run audits, generate report
main()
{
input_file="${1:-}"

View File

@@ -9,11 +9,13 @@
# <r> <g> <b> range from 0 to 255 inclusive.
# The escape sequence ^[0m returns output to default
# Set terminal background to an RGB color
setBackgroundColor()
{
echo -en "\x1b[48;2;$1;$2;$3""m"
}
# Reset terminal output formatting
resetOutput()
{
echo -en "\x1b[0m\n"

View File

@@ -28,6 +28,7 @@
set -euo pipefail
# Display usage information and options
usage()
{
cat << EOF
@@ -52,6 +53,7 @@ THUMB_SUFFIX="${THUMB_SUFFIX:-_thumb}"
# List of MIME types supported by ImageMagick (adjust as needed)
ALLOWED_MIMETYPES=("image/jpeg" "image/png" "image/gif" "image/bmp" "image/tiff" "image/webp")
# Verify ImageMagick is available
check_magick_installed()
{
if ! command -v magick &> /dev/null; then
@@ -60,6 +62,7 @@ check_magick_installed()
fi
}
# Verify mimetype command is available
check_mimetype_installed()
{
if ! command -v mimetype &> /dev/null; then
@@ -165,6 +168,7 @@ generate_thumbnails()
done < <(find "$source_dir" -type f -print0)
}
# Parse options, validate inputs, and generate thumbnails
main()
{
parse_options "$@"

View File

@@ -26,6 +26,7 @@ if [ "$#" -lt 2 ]; then
exit 1
fi
# Wait until host stops responding to ping
wait_for_host_down()
{
local host=$1
@@ -37,6 +38,7 @@ wait_for_host_down()
done
}
# Wait for host to go down then execute command
main()
{
local host=$1

View File

@@ -30,6 +30,7 @@ if [ "$#" -lt 2 ]; then
exit 1
fi
# Extract hostname from arguments, handling ssh shortcut
get_host()
{
if [ "$1" = "ssh" ]; then
@@ -39,6 +40,7 @@ get_host()
fi
}
# Wait until host responds to ping
wait_for_host()
{
local host=$1
@@ -50,6 +52,7 @@ wait_for_host()
done
}
# Wait for host to come online then execute command
main()
{
local host

View File

@@ -7,6 +7,7 @@ set -euo pipefail
source "${DOTFILES}/config/shared.sh"
DEST="$HOME/.dotfiles/docs/nvim-keybindings.md"
# Generate Neovim keybindings documentation
main()
{
msg "Generating Neovim keybindings documentation"

View File

@@ -6,6 +6,7 @@
source "${DOTFILES}/config/shared.sh"
DEST="$HOME/.dotfiles/docs/wezterm-keybindings.md"
# Generate wezterm keybindings documentation
main()
{
msg "Generating wezterm keybindings documentation"

View File

@@ -41,6 +41,7 @@ packages=(
software-properties-common # add-apt-repository command
)
# Install apt packages that are not already present
install_packages()
{
local to_install=()
@@ -67,6 +68,7 @@ install_packages()
return 0
}
# Install all apt packages and report completion
main()
{
install_packages

View File

@@ -76,6 +76,7 @@ post_install_steps()
return 0
}
# Install cargo packages and run post-install steps
main()
{
install_packages

View File

@@ -12,6 +12,7 @@ PBB_SYNTAX="syntax: bash"
PBB_TAGS="tags: [bash]"
PBB_TEMP_DIR="${XDG_CACHE_HOME:-$HOME/.cache}/cheat/pbb"
# Verify required tools are installed
check_required_tools()
{
for t in "${PBB_REQUIRED_TOOLS[@]}"; do
@@ -23,6 +24,7 @@ check_required_tools()
return 0
}
# Clone or update the pure-bash-bible repository
clone_or_update_repo()
{
if [[ ! -d "$PBB_TEMP_DIR/.git" ]]; then
@@ -38,6 +40,7 @@ clone_or_update_repo()
return 0
}
# Get the cheat destination directory for pure-bash-bible
prepare_cheat_dest()
{
local cheat_dest
@@ -95,6 +98,7 @@ process_chapters()
return 0
}
# Install pure-bash-bible cheatsheets
main()
{
check_required_tools

View File

@@ -39,6 +39,7 @@ packages=(
gnupg2 # GPG encryption/signing
)
# Install the Development Tools dnf group
install_dev_tools_group()
{
if dnf group list installed 2>/dev/null | grep -q "Development Tools"; then
@@ -50,6 +51,7 @@ install_dev_tools_group()
return 0
}
# Install dnf packages that are not already present
install_packages()
{
local to_install=()
@@ -75,6 +77,7 @@ install_packages()
return 0
}
# Install all dnf packages and report completion
main()
{
install_dev_tools_group

View File

@@ -52,12 +52,14 @@ install_fonts()
return 0
}
# Remove the temporary nerd-fonts clone directory
remove_tmp_path()
{
rm -rf "$TMP_PATH"
return 0
}
# Clone, sparse-checkout, install fonts, and clean up
main()
{
clone_or_update_repo

View File

@@ -48,6 +48,7 @@ install_extensions()
return 0
}
# Install all GitHub CLI extensions
main()
{
install_extensions

View File

@@ -56,6 +56,7 @@ clear_go_cache()
return 0
}
# Install go packages, completions, and clear cache
main()
{
install_packages

View File

@@ -58,6 +58,7 @@ clean_npm_cache()
return 0
}
# Install, upgrade, and clean npm packages
main()
{
install_packages

View File

@@ -49,6 +49,7 @@ install_ntfy()
return 0
}
# Download and install ntfy
main()
{
install_ntfy

View File

@@ -68,6 +68,7 @@ upgrade_tools()
return 0
}
# Install Python tools, libraries, and upgrade all
main()
{
install_tools