git status script update + others

This commit is contained in:
Solomon Laing 2023-02-17 22:45:22 +10:30
parent 857c6ec62c
commit 9533d52a8d
4 changed files with 83 additions and 18 deletions

View File

@ -2,7 +2,7 @@
export GOPATH="$HOME/go"
export PATH=$PATH:$HOME/.local/bin:$GOPATH/bin:$HOME/scripts
source ./themes/inkletblotsh.zsh
source "$ZDOTDIR/themes/inkletblotsh.zsh"
# Enable colors and change prompt:
autoload -U colors && colors # Load colors

View File

@ -1,22 +1,83 @@
#!/bin/bash
if git status &>/dev/null; then
branch=$(git branch --show-current)
# Thanks alrra, https://github.com/alrra/dotfiles/blob/main/src/shell/bash_prompt
if [ -z "$branch" ]; then
echo "(detached)"
exit 0
branchName=""
tmp=""
sync=""
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Check if the current directory is in a Git repository.
! git rev-parse &>/dev/null \
&& exit
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Check if in `.git/` directory (some of the following
# checks don't make sense/won't work in the `.git` directory).
[ "$(git rev-parse --is-inside-git-dir)" == "true" ] \
&& exit
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Check for uncommitted changes in the index.
if ! git diff --quiet --ignore-submodules --cached; then
tmp="$tmp+";
fi
read -ra counts <<< "$(git rev-list --left-right --count "$branch"...origin/"$branch")"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Check for unstaged changes.
if ! git diff-files --quiet --ignore-submodules --; then
tmp="$tmp*";
fi
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Check for untracked files.
if [ -n "$(git ls-files --others --exclude-standard)" ]; then
tmp="$tmp?";
fi
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Check for stashed files.
if git rev-parse --verify refs/stash &>/dev/null; then
tmp="$tmp""[s]";
fi
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
[ -z "$tmp" ] && \
tmp="~";
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
branchName="$( printf "%s" "$( git rev-parse --abbrev-ref HEAD 2> /dev/null \
|| git rev-parse --short HEAD 2> /dev/null \
|| printf " (unknown)" )" | \
tr -d "\n" )"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Count how many commits behind and ahead we are.
if git rev-list --left-right --count "$branchName"...origin/"$branchName" &>/dev/null; then
read -ra counts <<< "$(git rev-list --left-right --count "$branchName"...origin/"$branchName")"
to_push=${counts[0]}
to_pull=${counts[1]}
extras=$([[ ${counts[0]} -eq 0 && ${counts[1]} -eq 0 ]] || echo " $to_push↑ $to_pull↓")
sync=$([[ ${counts[0]} -eq 0 && ${counts[1]} -eq 0 ]] || echo " $to_push↑ $to_pull↓")
fi
if [[ $(git diff --shortstat 2> /dev/null | tail -n1) != "" ]]; then
echo "($branch*$extras)"
else
echo "($branch~$extras)"
fi
fi
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
printf "%s" "($branchName$tmp$sync)"

View File

@ -1,6 +1,7 @@
#!/bin/sh
# Syncs repositories and downloads updates, meant to be run as a cronjob.
# make sure you have set up passwordless sudo in SUDOERS file for this script
notify-send "Repository Sync" "Checking for package updates..."
@ -8,6 +9,8 @@ sudo pacman -Syyuw --noconfirm || notify-send "Error downloading updates.
Check your internet connection, if pacman is already running, or run update manually to see errors."
pkill -RTMIN+8 "${STATUSBAR:-dwmblocks}"
if pacman -Qu | grep -v "\[ignored\]"
then
notify-send "Repository Sync" "Sync comelete. You have updates $(pacman -Qu | grep -vc "\[ignored\]") available."

View File

@ -15,6 +15,7 @@ split() {
set -- $1
printf '%s' "$@"
}
vol="$(split "$vol" ".")"
vol="${vol##0}"
@ -22,7 +23,7 @@ case 1 in
$((vol >= 70)) ) icon="" ;;
$((vol >= 30)) ) icon="" ;;
$((vol >= 1)) ) icon="" ;;
* ) echo  && exit ;;
* ) echo " " && exit ;;
esac
echo "$icon $vol%"