dot

packages and services management
Log | Files | Refs | README

commit e410fff3a0ea591277a3dc0f27235ad963355913
parent bd4caa48e94a1c242bb02bc101d6410ce24ad541
Author: josuah <mail@josuah.net>
Date:   Fri, 18 Nov 2016 16:31:08 +0100

Trying to simplify and improve status

Diffstat:
M.profile | 23+++++++----------------
Mbin/buffer | 3---
Mbin/status | 41++++++++++++++++++++++-------------------
3 files changed, 29 insertions(+), 38 deletions(-)

diff --git a/.profile b/.profile @@ -26,24 +26,15 @@ export PAGER="less -R" export MANPAGER="$PAGER" export DVTM_EDITOR="$PAGER" -export PS1='$( - [ "$?" -eq 0 ] && color=2 || color=1 +PS1='$( + [ $? -eq 0 ] && color=2 || color=1 - # status line - printf %s "$PWD" > $HOME/.cache/status/pwd - printf "\n%$(stty size | cut -d " " -f 2)s" "$(status)" - - # terminal name - printf "\033]0;shell\007" - - # TTY cursor shape - printf "\033[?6c" - - # prompt character - printf "\033[3%s;1m\n ───\033[0m " "$color" + printf "\n%$(stty size | cut -d " " -f 2)s\r%s" \ + "$(status)" "$(status path "$PWD")" + printf "\033[1;3%sm\n ─── \033[0m" "$color" )' -export PS2=' > ' -export PS3=' > ' +PS2=' > ' +PS3=' > ' alias l='ls -lhF --color' diff --git a/bin/buffer b/bin/buffer @@ -89,9 +89,6 @@ get_name() [ "$path" ] && name="$name ${path:+~${path#$HOME}}" - # set terminal's name - printf '\033]0;%s\007' "$name" 1>&2 - # return the result without forbidden characters printf %s "$name" | tr / ! } diff --git a/bin/status b/bin/status @@ -19,19 +19,13 @@ STOP=' ' # status_path() { - cd $SHELL_PWD + local pwd="$1" - local pwd="$(pwd)" + [ -z "${pwd##$HOME*}" ] && printf ~%s "${pwd#$HOME}" || printf %s "$pwd" - if [ -z "${pwd##$HOME*}" ] - then - printf '~%s' "${pwd#$HOME}" - fi - - git rev-parse &>/dev/null || return 0 + cd "$pwd" && git rev-parse &>/dev/null || return 0 git status --porcelain -b | awk ' - /^## / { branch = $0; sub(/^##/, "", branch); @@ -63,18 +57,18 @@ status_path() m == 1 { m = 0; } END { - printf("%s", branch); + printf(" \033[1m%s", branch); if (untracked + conflicts + changed + staged + behind + ahead \ == 0) { - printf " ok"; + printf " \033[32mok\033[0m"; } else { - if (untracked) printf " ?%d", untracked; - if (conflicts) printf " !%d", conflicts; - if (changed ) printf " +%d", changed ; - if (staged ) printf " *%d", staged ; - if (behind ) printf " ↓%d", behind ; - if (ahead ) printf " ↑%d", ahead ; + if (untracked) printf " \033[33m?\033[0m%d", untracked; + if (conflicts) printf " \033[31m!\033[0m%d", conflicts; + if (changed ) printf " \033[32m+\033[0m%d", changed ; + if (staged ) printf " \033[34m*\033[0m%d", staged ; + if (behind ) printf " \033[35m↓\033[0m%d", behind ; + if (ahead ) printf " \033[35m↑\033[0m%d", ahead ; } }' } @@ -145,10 +139,19 @@ main() mkdir -p "$STATUS" + printf "$START" while [ "$#" -gt 0 ] do - segment="$(status_$1)" + case "$1" in + path ) + segment="$(status_$1 $2)" + shift 1 + ;; + * ) + segment="$(status_$1)" + ;; + esac printf %s "$segment" @@ -160,4 +163,4 @@ main() } -main ${@:-path mail abduco cpu battery date} +main ${@:-mail abduco cpu battery date}