Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Bash CI #4

Merged
merged 4 commits into from
May 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .github/workflows/bash_ci.yml
Original file line number Diff line number Diff line change
@@ -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
95 changes: 52 additions & 43 deletions bashrc_snippet.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/bin/bash

# Configuration variables
GIT_SHOW_BRANCH=true
GIT_SHOW_COMMITS=true
Expand All @@ -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
Expand Down