From e95506e776af3578b678b03a36cb02c4e44428f0 Mon Sep 17 00:00:00 2001 From: "Brian A. Teller" Date: Fri, 5 May 2023 18:35:46 -0400 Subject: [PATCH 1/4] Add Bash CI --- .github/workflows/bash_ci.yml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 .github/workflows/bash_ci.yml diff --git a/.github/workflows/bash_ci.yml b/.github/workflows/bash_ci.yml new file mode 100644 index 0000000..628cebb --- /dev/null +++ b/.github/workflows/bash_ci.yml @@ -0,0 +1,17 @@ +name: bash_ci +on: + - pull_request +jobs: + sh-checker: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Run the sh-checker + uses: luizm/action-sh-checker@master + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SHELLCHECK_OPTS: -e SC1004 # exclude some shellcheck warnings. + SHFMT_OPTS: -s # arguments to shfmt. + with: + sh_checker_comment: true + sh_checker_exclude: ".terraform ^dir/example.sh" From 88f26a49df4cf4c2598ec8447714d976d00926bb Mon Sep 17 00:00:00 2001 From: "Brian A. Teller" Date: Fri, 5 May 2023 18:42:10 -0400 Subject: [PATCH 2/4] Switch Bash CI --- .github/workflows/bash_ci.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/bash_ci.yml b/.github/workflows/bash_ci.yml index 628cebb..18e2411 100644 --- a/.github/workflows/bash_ci.yml +++ b/.github/workflows/bash_ci.yml @@ -14,4 +14,3 @@ jobs: SHFMT_OPTS: -s # arguments to shfmt. with: sh_checker_comment: true - sh_checker_exclude: ".terraform ^dir/example.sh" From eca928aed282d74cf83e26c2d703298c1b776222 Mon Sep 17 00:00:00 2001 From: Brian Teller Date: Fri, 5 May 2023 18:50:19 -0400 Subject: [PATCH 3/4] Update formatting --- bashrc_snippet.sh | 88 ++++++++++++++++++++++++----------------------- 1 file changed, 45 insertions(+), 43 deletions(-) diff --git a/bashrc_snippet.sh b/bashrc_snippet.sh index 52a9931..2d553e7 100644 --- a/bashrc_snippet.sh +++ b/bashrc_snippet.sh @@ -1,3 +1,5 @@ +#!/bin/bash + # Configuration variables GIT_SHOW_BRANCH=true GIT_SHOW_COMMITS=true @@ -8,62 +10,62 @@ GIT_SHOW_UNCOMMITTED_CHANGES=true GIT_SHOW_UNTRACKED_FILES=true is_git_repository() { - git rev-parse --is-inside-work-tree >/dev/null 2>&1 && [ -d .git ] + git rev-parse --is-inside-work-tree >/dev/null 2>&1 && [ -d .git ] } get_git_info() { - local output="" + local output="" - if is_git_repository; then - local current_branch=$(git symbolic-ref --short HEAD 2>/dev/null) + if is_git_repository; then + local current_branch=$(git symbolic-ref --short HEAD 2>/dev/null) - if [ "$GIT_SHOW_USER_INFO" = true ]; then - local user_name=$(git config user.name) - local user_email=$(git config user.email) - output+="($user_name <$user_email>) " - fi + if [ "$GIT_SHOW_USER_INFO" = true ]; then + local user_name=$(git config user.name) + local user_email=$(git config user.email) + output+="($user_name <$user_email>) " + fi - if [ "$GIT_SHOW_BRANCH" = true ]; then - output+="$current_branch " - fi + if [ "$GIT_SHOW_BRANCH" = true ]; then + output+="$current_branch " + fi - if [ "$GIT_SHOW_COMMITS" = true ]; then - local commits_ahead=$(git rev-list --count --left-only HEAD...@'{u}' 2>/dev/null) - if [ "$commits_ahead" != "0" ]; then - output+="↑$commits_ahead " - fi - fi + if [ "$GIT_SHOW_COMMITS" = true ]; then + local commits_ahead=$(git rev-list --count --left-only HEAD...@'{u}' 2>/dev/null) + if [ "$commits_ahead" != "0" ]; then + output+="↑$commits_ahead " + fi + fi - if [ "$GIT_SHOW_STAGED_COMMITS" = true ]; then - local commits_behind=$(git rev-list --count --right-only HEAD...@'{u}' 2>/dev/null) - if [ "$commits_behind" != "0" ]; then - output+="↓$commits_behind " - fi - fi + if [ "$GIT_SHOW_STAGED_COMMITS" = true ]; then + local commits_behind=$(git rev-list --count --right-only HEAD...@'{u}' 2>/dev/null) + if [ "$commits_behind" != "0" ]; then + output+="↓$commits_behind " + fi + fi - if [ "$GIT_SHOW_FILES_DIFF_COUNT" = true ]; then - local files_diff_count=$(git diff --name-only "$current_branch" "origin/$current_branch" 2>/dev/null | wc -l | tr -d '[:space:]') - if [ "$files_diff_count" != "0" ]; then - output+="Δ$files_diff_count " - fi - fi + if [ "$GIT_SHOW_FILES_DIFF_COUNT" = true ]; then + local files_diff_count=$(git diff --name-only "$current_branch" "origin/$current_branch" 2>/dev/null | wc -l | tr -d '[:space:]') + if [ "$files_diff_count" != "0" ]; then + output+="Δ$files_diff_count " + fi + fi - if [ "$GIT_SHOW_UNCOMMITTED_CHANGES" = true ]; then - git diff --quiet 2>/dev/null || output+="+ " - fi + if [ "$GIT_SHOW_UNCOMMITTED_CHANGES" = true ]; then + git diff --quiet 2>/dev/null || output+="+ " + fi - if [ "$GIT_SHOW_UNTRACKED_FILES" = true ]; then - local untracked_files=$(git ls-files --others --exclude-standard 2>/dev/null | wc -l | tr -d '[:space:]') - if [ "$untracked_files" != "0" ]; then - output+="✚$untracked_files " - fi - fi + if [ "$GIT_SHOW_UNTRACKED_FILES" = true ]; then + local untracked_files=$(git ls-files --others --exclude-standard 2>/dev/null | wc -l | tr -d '[:space:]') + if [ "$untracked_files" != "0" ]; then + output+="✚$untracked_files " + fi + fi - else - output="Not a Git repository" - fi + else + output="Not a Git repository" + fi - iterm2_set_user_var gitInfo "$output" + iterm2_set_user_var gitInfo "$output" } # Call get_git_info when the shell prompt is displayed From ffd49482de7986a2ce114c42c8fb350ed39a3114 Mon Sep 17 00:00:00 2001 From: Brian Teller Date: Fri, 5 May 2023 18:56:32 -0400 Subject: [PATCH 4/4] Fix Shell Checker Errors --- bashrc_snippet.sh | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/bashrc_snippet.sh b/bashrc_snippet.sh index 2d553e7..af5a17b 100644 --- a/bashrc_snippet.sh +++ b/bashrc_snippet.sh @@ -17,11 +17,14 @@ get_git_info() { local output="" if is_git_repository; then - local current_branch=$(git symbolic-ref --short HEAD 2>/dev/null) + local current_branch + current_branch=$(git symbolic-ref --short HEAD 2>/dev/null) if [ "$GIT_SHOW_USER_INFO" = true ]; then - local user_name=$(git config user.name) - local user_email=$(git config user.email) + local user_name + user_name=$(git config user.name) + local user_email + user_email=$(git config user.email) output+="($user_name <$user_email>) " fi @@ -30,21 +33,24 @@ get_git_info() { fi if [ "$GIT_SHOW_COMMITS" = true ]; then - local commits_ahead=$(git rev-list --count --left-only HEAD...@'{u}' 2>/dev/null) + local commits_ahead + commits_ahead=$(git rev-list --count --left-only HEAD...@'{u}' 2>/dev/null) if [ "$commits_ahead" != "0" ]; then output+="↑$commits_ahead " fi fi if [ "$GIT_SHOW_STAGED_COMMITS" = true ]; then - local commits_behind=$(git rev-list --count --right-only HEAD...@'{u}' 2>/dev/null) + local commits_behind + commits_behind=$(git rev-list --count --right-only HEAD...@'{u}' 2>/dev/null) if [ "$commits_behind" != "0" ]; then output+="↓$commits_behind " fi fi if [ "$GIT_SHOW_FILES_DIFF_COUNT" = true ]; then - local files_diff_count=$(git diff --name-only "$current_branch" "origin/$current_branch" 2>/dev/null | wc -l | tr -d '[:space:]') + local files_diff_count + files_diff_count=$(git diff --name-only "$current_branch" "origin/$current_branch" 2>/dev/null | wc -l | tr -d '[:space:]') if [ "$files_diff_count" != "0" ]; then output+="Δ$files_diff_count " fi @@ -55,7 +61,8 @@ get_git_info() { fi if [ "$GIT_SHOW_UNTRACKED_FILES" = true ]; then - local untracked_files=$(git ls-files --others --exclude-standard 2>/dev/null | wc -l | tr -d '[:space:]') + local untracked_files + untracked_files=$(git ls-files --others --exclude-standard 2>/dev/null | wc -l | tr -d '[:space:]') if [ "$untracked_files" != "0" ]; then output+="✚$untracked_files " fi