From 65b687a383edcab81cec301dbb19f63fb15babdc Mon Sep 17 00:00:00 2001 From: Jake Rogers Date: Sat, 6 Jul 2024 20:06:01 -0600 Subject: [PATCH 1/4] feat(omz): add log-cmd function to log the stderr and stdout of a command --- omz/functions.zsh | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/omz/functions.zsh b/omz/functions.zsh index ce79851..9a1a071 100644 --- a/omz/functions.zsh +++ b/omz/functions.zsh @@ -22,6 +22,24 @@ getsudohash() { fi } +function log-cmd () { + local header="####################################################\n" + + # check if log file has been named + if [ -z "${CMD_LOG_FILE}" ]; then + local CMD_LOG_FILE="/tmp/command.log" + echo "No log file specified, using default: ${CMD_LOG_FILE}\n" + fi + + { + printf ${header} + printf "\`%s\` executed at $(date '+%Y-%m-%d %H:%M:%S')\n" "$*" + printf ${header} + "$@" + printf "\n" + } 2>&1 | tee -a "${CMD_LOG_FILE}" +} + update_forge_modules () { for dir in $(ls -1); do echo $dir From 1f50a1e4d7ae707d4ab7092563e8afea5b55a217 Mon Sep 17 00:00:00 2001 From: Jake Rogers Date: Sat, 6 Jul 2024 20:26:34 -0600 Subject: [PATCH 2/4] refactor(omz): order functions alphabetically --- omz/functions.zsh | 124 +++++++++++++++++++++++----------------------- 1 file changed, 62 insertions(+), 62 deletions(-) diff --git a/omz/functions.zsh b/omz/functions.zsh index 9a1a071..96b64b2 100644 --- a/omz/functions.zsh +++ b/omz/functions.zsh @@ -1,16 +1,5 @@ # functions -joincsv () { - if [[ $1 == "--help" || $1 == "-h" || $1 == "-?" ]]; then - echo "Usage: joincsv [ file1 ] [ file2 ]" - echo -e "Purpose: add data from the second csv as a new column in the first csv" - echo "Example 1:" - echo -e " server> joincsv svrChkr-2015-08-27.csv OWNERS.csv\n" - else - join -t, -a1 --header --nocheck-order <(cat <(head -n1 "$1") <(sed 1d "$1" | sort) | sed 's/\r//') <(cat <(head -n1 "$2") <(sed 1d "$2"| sort) | sed 's/\r//') - fi -} - getsudohash() { if [[ $1 == "--help" || $1 == "-h" || $1 == "-?" ]]; then echo "Usage: getsudohash [ hostname ]" @@ -22,31 +11,37 @@ getsudohash() { fi } -function log-cmd () { - local header="####################################################\n" - - # check if log file has been named - if [ -z "${CMD_LOG_FILE}" ]; then - local CMD_LOG_FILE="/tmp/command.log" - echo "No log file specified, using default: ${CMD_LOG_FILE}\n" +# function to check child directories for pull requests +# usage: git-check-prs [ --help ] +git-pr-check() { + if [[ $1 == "--help" || $1 == "-h" || $1 == "-?" ]]; then + echo "Usage: git-pr-check [ --help ]" + echo -e "Purpose: check child directories for pull requests" + echo "Example 1:" + echo -e " server> git-pr-check\n" + return + fi + for dir in $(find . -mindepth 1 -maxdepth 1 -type d -printf '%P\n'); do + cd "$dir" + # has a .git directory + if [ -d .git ]; then + # has a GitHub remote + if git remote -v | grep -iq github; then + echo + echo "$(tput setaf 2)🟢 $dir$(tput sgr0)" + gh pr list + echo + # does not have a GitHub remote + else + echo "$(tput setaf 214)🟠 $dir, not using GitHub$(tput sgr0)" + cd .. + continue + fi + # does not have a .git directory + else + echo "$(tput setaf 7)➖ $dir, not a git repo$(tput sgr0)" fi - - { - printf ${header} - printf "\`%s\` executed at $(date '+%Y-%m-%d %H:%M:%S')\n" "$*" - printf ${header} - "$@" - printf "\n" - } 2>&1 | tee -a "${CMD_LOG_FILE}" -} - -update_forge_modules () { - for dir in $(ls -1); do - echo $dir - git -C "$dir" fetch -p origin - git -C "$dir" push --mirror - echo - echo + cd .. done } @@ -114,36 +109,41 @@ git-tag-semver() { fi } -# function to check child directories for pull requests -# usage: git-check-prs [ --help ] -git-pr-check() { +joincsv () { if [[ $1 == "--help" || $1 == "-h" || $1 == "-?" ]]; then - echo "Usage: git-pr-check [ --help ]" - echo -e "Purpose: check child directories for pull requests" + echo "Usage: joincsv [ file1 ] [ file2 ]" + echo -e "Purpose: add data from the second csv as a new column in the first csv" echo "Example 1:" - echo -e " server> git-pr-check\n" - return + echo -e " server> joincsv svrChkr-2015-08-27.csv OWNERS.csv\n" + else + join -t, -a1 --header --nocheck-order <(cat <(head -n1 "$1") <(sed 1d "$1" | sort) | sed 's/\r//') <(cat <(head -n1 "$2") <(sed 1d "$2"| sort) | sed 's/\r//') fi - for dir in $(find . -mindepth 1 -maxdepth 1 -type d -printf '%P\n'); do - cd "$dir" - # has a .git directory - if [ -d .git ]; then - # has a GitHub remote - if git remote -v | grep -iq github; then - echo - echo "$(tput setaf 2)🟢 $dir$(tput sgr0)" - gh pr list - echo - # does not have a GitHub remote - else - echo "$(tput setaf 214)🟠 $dir, not using GitHub$(tput sgr0)" - cd .. - continue - fi - # does not have a .git directory - else - echo "$(tput setaf 7)➖ $dir, not a git repo$(tput sgr0)" +} + +function log-cmd () { + local header="####################################################\n" + + # check if log file has been named + if [ -z "${CMD_LOG_FILE}" ]; then + local CMD_LOG_FILE="/tmp/command.log" + echo "No log file specified, using default: ${CMD_LOG_FILE}\n" fi - cd .. + + { + printf ${header} + printf "\`%s\` executed at $(date '+%Y-%m-%d %H:%M:%S')\n" "$*" + printf ${header} + "$@" + printf "\n" + } 2>&1 | tee -a "${CMD_LOG_FILE}" +} + +update_forge_modules () { + for dir in $(ls -1); do + echo $dir + git -C "$dir" fetch -p origin + git -C "$dir" push --mirror + echo + echo done } From 6213cce030a946f42265a1e0eb17ac9c107edc2c Mon Sep 17 00:00:00 2001 From: Jake Rogers Date: Sat, 6 Jul 2024 21:59:03 -0600 Subject: [PATCH 3/4] docs(omz): document all functions using the google bash style guide --- omz/functions.zsh | 66 ++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 57 insertions(+), 9 deletions(-) diff --git a/omz/functions.zsh b/omz/functions.zsh index 96b64b2..9ef0c69 100644 --- a/omz/functions.zsh +++ b/omz/functions.zsh @@ -1,6 +1,13 @@ # functions -getsudohash() { +####################################### +# ssh to the server, concatenate the sudo files, and calculate the resulting SHA1 hash +# Arguments: +# $1 - hostname of the server to ssh into +# Outputs: +# Writes the server hostname and resulting SHA1 hash to stdout +####################################### +function getsudohash() { if [[ $1 == "--help" || $1 == "-h" || $1 == "-?" ]]; then echo "Usage: getsudohash [ hostname ]" echo -e "Purpose: ssh to server and report hash" @@ -11,9 +18,15 @@ getsudohash() { fi } -# function to check child directories for pull requests -# usage: git-check-prs [ --help ] -git-pr-check() { + +####################################### +# check child directories for pull requests using the GitHub CLI +# Arguments: +# None +# Outputs: +# Writes any existing GitHub pull requests to stdout +####################################### +function git-pr-check() { if [[ $1 == "--help" || $1 == "-h" || $1 == "-?" ]]; then echo "Usage: git-pr-check [ --help ]" echo -e "Purpose: check child directories for pull requests" @@ -45,9 +58,17 @@ git-pr-check() { done } -# function to semantically tag a git repository, optionally with floating tags -# usage: git-tag-semver [float] [push] [--help] -git-tag-semver() { + +####################################### +# add signed & annontated semantic version tags(either single or floating tags) to a git repository +# Arguments: +# $1 - major|minor|patch (required) +# $2 - 'float' to add floating tags, null otherwise +# $3 - 'push' the tags to the remote +# Outputs: +# Writes the latest tag, the new tag, and the floating tags (if requested) to stdout +####################################### +function git-tag-semver() { if [[ $1 == "--help" || $1 == "-h" || $1 == "-?" ]]; then echo "Usage: git-tag-semver [ major | minor | patch ] [float] [push] [--help]" echo -e "Purpose: semantically tag a git repository" @@ -109,7 +130,16 @@ git-tag-semver() { fi } -joincsv () { + +####################################### +# join two csv files on the first column. The first row of each file is assumed to be the header. +# Arguments: +# $1 - 'file1' the first csv file +# $2 - 'file2' the second csv file +# Outputs: +# Writes the joined csv to stdout +####################################### +function joincsv () { if [[ $1 == "--help" || $1 == "-h" || $1 == "-?" ]]; then echo "Usage: joincsv [ file1 ] [ file2 ]" echo -e "Purpose: add data from the second csv as a new column in the first csv" @@ -120,6 +150,16 @@ joincsv () { fi } + +####################################### +# log a shell command, its stdout, and stderr to a file +# Globals: +# CMD_LOG_FILE - the file to log the command and its output to +# Arguments: +# $* - the command to execute +# Outputs: +# Writes the command and its output to the log file and stdout +####################################### function log-cmd () { local header="####################################################\n" @@ -138,7 +178,15 @@ function log-cmd () { } 2>&1 | tee -a "${CMD_LOG_FILE}" } -update_forge_modules () { + +####################################### +# update all mirrored puppet forge modules in the current directory +# Arguments: +# None +# Outputs: +# Writes the git fetch and push status to stdout +####################################### +function update_forge_modules () { for dir in $(ls -1); do echo $dir git -C "$dir" fetch -p origin From 55b1bdd1a7ea4fb3bb3e9d838d7ee64da3512c62 Mon Sep 17 00:00:00 2001 From: Jake Rogers Date: Sun, 7 Jul 2024 08:30:36 -0600 Subject: [PATCH 4/4] =?UTF-8?q?bump:=20version=201.5.1=20=E2=86=92=201.6.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .cz.yaml | 2 +- CHANGELOG.md | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/.cz.yaml b/.cz.yaml index 10b463b..8479c57 100644 --- a/.cz.yaml +++ b/.cz.yaml @@ -9,5 +9,5 @@ commitizen: template: .cz.changelog.md.j2 update_changelog_on_bump: true use_shortcuts: true - version: 1.5.1 + version: 1.6.0 version_scheme: semver diff --git a/CHANGELOG.md b/CHANGELOG.md index 90f1e77..22ecf6d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,13 @@ +## v1.6.0 (2024-07-07) + +### Feature + +- **omz**: add log-cmd function to log the stderr and stdout of a command + +### Refactor + +- **omz**: order functions alphabetically + ## v1.5.1 (2024-06-28) ### Fix