diff --git a/.github/workflows/bash_ci.yml b/.github/workflows/bash_ci.yml new file mode 100644 index 0000000..18e2411 --- /dev/null +++ b/.github/workflows/bash_ci.yml @@ -0,0 +1,16 @@ +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 diff --git a/bashrc_snippet.sh b/bashrc_snippet.sh index 52a9931..af5a17b 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,69 @@ 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 + 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 + user_name=$(git config user.name) + local user_email + 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 + 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 + 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 + 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 + 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