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 GOPATH="$HOME/go"
export PATH=$PATH:$HOME/.local/bin:$GOPATH/bin:$HOME/scripts export PATH=$PATH:$HOME/.local/bin:$GOPATH/bin:$HOME/scripts
source ./themes/inkletblotsh.zsh source "$ZDOTDIR/themes/inkletblotsh.zsh"
# Enable colors and change prompt: # Enable colors and change prompt:
autoload -U colors && colors # Load colors autoload -U colors && colors # Load colors

View File

@ -1,22 +1,83 @@
#!/bin/bash #!/bin/bash
if git status &>/dev/null; then # Thanks alrra, https://github.com/alrra/dotfiles/blob/main/src/shell/bash_prompt
branch=$(git branch --show-current)
if [ -z "$branch" ]; then branchName=""
echo "(detached)" tmp=""
exit 0 sync=""
fi
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# 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
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# 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")"
read -ra counts <<< "$(git rev-list --left-right --count "$branch"...origin/"$branch")"
to_push=${counts[0]} to_push=${counts[0]}
to_pull=${counts[1]} 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↓")
if [[ $(git diff --shortstat 2> /dev/null | tail -n1) != "" ]]; then
echo "($branch*$extras)"
else
echo "($branch~$extras)"
fi
fi fi
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
printf "%s" "($branchName$tmp$sync)"

View File

@ -1,6 +1,7 @@
#!/bin/sh #!/bin/sh
# Syncs repositories and downloads updates, meant to be run as a cronjob. # 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..." 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." 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\]" if pacman -Qu | grep -v "\[ignored\]"
then then
notify-send "Repository Sync" "Sync comelete. You have updates $(pacman -Qu | grep -vc "\[ignored\]") available." notify-send "Repository Sync" "Sync comelete. You have updates $(pacman -Qu | grep -vc "\[ignored\]") available."

View File

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