dot

packages and services management
Log | Files | Refs | README

commit 3f38605d5dd494c861c40ce73368f886c7c5e7bc
parent 5ff556d655464f26151f2f33522aa6a266981615
Author: josuah <mail@josuah.net>
Date:   Tue,  1 Nov 2016 15:50:00 -0400

Added a very nice git prompt

Diffstat:
Mbin/status | 27++++++++++++++-------------
Mgit/.config/git/config | 2+-
Mshell/.profile | 115+++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------
3 files changed, 90 insertions(+), 54 deletions(-)

diff --git a/bin/status b/bin/status @@ -1,4 +1,3 @@ -#!/bin/sh # | | # ,--- |-- ,--. |-- , , ,--- # `--. | ,--| | | | `--. @@ -6,22 +5,23 @@ #------------------------------------------------------------------------------- # Plain text status line for wherever useful -BLACK=0 RED=1 GREEN=2 YELLOW=3 BLUE=4 MAGENTA=5 CYAN=6 WHITE=7 +mail="$(ls "$MAIL/new" | wc -l)" +mail="${mail#0}" +mail="${mail:+mail $mail}" -mail="$( - count="$(find "$MAIL/new" -type f 2>/dev/null | wc -l)" - [ "$count" -gt 0 ] && printf '%s mails' "$count" -)" +date="$(date +'%Y-%m-%d %H:%M')" -date="$( - date +'%Y-%m-%d %H:%M' -)" +cpu="$(awk '/cpu/ { + usage = ($2 + $4) * 100 / ($2 + $4 + $5); +} +END { + printf("%i%%", usage); +}' /proc/stat)" -battery="$( - cat "$(find -L /sys/class/ -maxdepth 3 -name capacity 2> /dev/null)" -)%" +battery="$(tee < /sys/class/power_supply/BAT1/capacity)%" main() { + printf ' ' while [ "$#" -gt 0 ] do printf '%s' "$1" @@ -30,6 +30,7 @@ main() { shift done + printf ' ' } -main "$mail" "$battery" "$date" +main "$mail" "cpu $cpu" "bat $battery" "$date" diff --git a/git/.config/git/config b/git/.config/git/config @@ -21,7 +21,7 @@ c = commit p = push origin master u = pull origin master - s = status + s = status -s -b l = log --graph --color --pretty=format:"%C(yellow)%H%C(green)%d%C(reset)%n%x20%cd%n%x20%cn%x20(%ce)%n%x20%s%n" acp = !git a && git c && git p acpa = !git a && git c --amend && git p --force diff --git a/shell/.profile b/shell/.profile @@ -16,61 +16,96 @@ # PROMPT #------------------------------------------------------------------------------- -PS1='$( - ps1 "$?" -)' +trap 'status_line' SIGWINCH + +PS1='$(ps1 "$?")' PS2=' > ' PS3=' > ' ps1() { - local code="$1" pwd status col color pwd="$(pwd)" + local code="$1" color + [ "$code" -eq 0 ] && color=32 || color=31 - # Path + local pwd="$(pwd)" [ -z "${pwd##$HOME*}" ] && pwd="~${pwd#$HOME}" - # Status line - local status="$(status)" - local col="$(stty size | cut -d ' ' -f 2)" - printf '\033[s\033[2;0H\033[K' - printf '\033[%sC%s' "$(($col - ${#status}))" "$status" - printf '\033[2;0H%s %s' "$pwd" "$(git_status)" - printf '\033[u' + local col="$(stty size)"; + col="$((${col#* } - ${#status} - 1))" - # Error code and actual prompt - [ "$code" -eq 0 ] && color=32 || color=31 - printf "\n \033[1;30m>\033[0;%sm>\033[1m>\033[0m " "$color" + # terminal name + printf '\033]0;%s %s\007' "$pwd" + + # prompt + printf '\n \033[1;30m>\033[0;%sm>\033[1m>\033[0m ' "$color" - # tmux/dvtm status line - [ "$TMUX" ] && tmux refresh-client -S - [ "$DVTM" ] && status > "$STATUS_FIFO" + status_line +} + +status_line() +{ + local pwd="$(pwd)" + [ -z "${pwd##$HOME*}" ] && pwd="~${pwd#$HOME}" - # Terminal name - printf "\033]0;%s %s\007" "$pwd" "$git" + printf '\033[s\033[0;0H\033[K' + printf '\r %s %s\n\033[K\033[u' "$pwd" "$(git_status)" } git_status() { - # Git status - if git rev-parse &> /dev/null - then - local branch="$(git branch | sed -n 's/^\* // p')" - local status="$(git status --porcelain)" - - local M="$(printf %s "$status" | grep '^ M' | wc -l)" - local A="$(printf %s "$status" | grep '^ A' | wc -l)" - local D="$(printf %s "$status" | grep '^ D' | wc -l)" - local R="$(printf %s "$status" | grep '^ R' | wc -l)" - local U="$(printf %s "$status" | grep '^??' | wc -l)" - - [ "${M#0}" ] && M=" \033[33m~$M\033[0m" || M='' - [ "${A#0}" ] && A=" \033[32m+$A\033[0m" || A='' - [ "${D#0}" ] && D=" \033[31m-$D\033[0m" || D='' - [ "${R#0}" ] && R=" \033[36m>$R\033[0m" || R='' - [ "${U#0}" ] && U=" \033[34m?$U\033[0m" || U='' - - printf "\033[1m$branch\033\0m$M$D$U" - fi + git rev-parse &>/dev/null || return 0 + + local branch="$(git branch)" + printf %s "${branch#??}" + + local behind=0 ahead=0 untracked=0 conflicts=0 changed=0 staged=0 + + while IFS='' read -r status + do + case "$status" in + ?? ) behind="$((behind + 1))" ahead="$((ahead + 1))" ;; + ' '? ) behind="$((behind + 1))" ;; + ?' ' ) ahead="$((ahead + 1))" ;; + esac + # thanks to magicmonty@github for this part + while [ "$status" ] + do + case "$status" in + #two fixed character matches, loop finished + '??' ) untracked="$((untracked + 1))"; break ;; + U? ) conflicts="$((conflicts + 1))"; break ;; + ?U ) conflicts="$((conflicts + 1))"; break ;; + DD ) conflicts="$((conflicts + 1))"; break ;; + AA ) conflicts="$((conflicts + 1))"; break ;; + + # first loop: two character matches + ?M ) changed="$((changed + 1))" ;; + ?D ) changed="$((changed + 1))" ;; + ?' ') ;; + + # second loop: single character matches + U ) conflicts="$((conflicts + 1))" ;; + ' ' ) ;; + * ) staged="$((staged + 1))" ;; + esac + + status="${status%?}" + + done + done << EOF +$(git status --porcelain | sed -r 's/(..).*/\1/') +EOF + printf '\033[1m' + + [ "$ahead$behind" = '00' ] && printf ' \033[32m✔\033[0m' && return + [ "${untracked#0}" ] && printf ' \033[34m?\033[37m%s' "$untracked" + [ "${conflicts#0}" ] && printf ' \033[31m!\033[37m%s' "$conflicts" + [ "${changed#0}" ] && printf ' \033[32m+\033[37m%s' "$changed" + [ "${staged#0}" ] && printf ' \033[33m*\033[37m%s' "$staged" + [ "${behind#0}" ] && printf ' \033[36m↓\033[37m%s' "$behind" + [ "${ahead#0}" ] && printf ' \033[36m↑\033[37m%s' "$ahead" + + printf '\033[0m' } while true