From c5d16114b8e65b7ce0201946a139830a1b2eff61 Mon Sep 17 00:00:00 2001 From: Jonas Forsberg Date: Fri, 12 Nov 2021 12:21:38 +0100 Subject: [PATCH] . --- .functions/dotfiles.sh | 31 +++++++++++++++++++++++++++++++ .functions/ps1.sh | 20 +++++++++++++++++++- 2 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 .functions/dotfiles.sh diff --git a/.functions/dotfiles.sh b/.functions/dotfiles.sh new file mode 100644 index 0000000..5b5720e --- /dev/null +++ b/.functions/dotfiles.sh @@ -0,0 +1,31 @@ +#!/bin/bash +function dotf(){ + /usr/bin/git --git-dir="$HOME"/.dotfiles --work-tree="$HOME" "$@" +} + +dotfiles_status(){ + case $1 in + check_error) + result="$(/usr/bin/git --git-dir="$HOME"/.dotfiles --work-tree="$HOME" status --short 2> /dev/null)" + # shellcheck disable=SC2181 + if [[ $? -ne 0 ]]; then + echo YES + fi + ;; + check_status) + result="$(/usr/bin/git --git-dir="$HOME"/.dotfiles --work-tree="$HOME" status --short 2> /dev/null)" + if [[ -n "$result" ]]; then + echo YES + fi + ;; + check_push) + result="$(/usr/bin/git --git-dir="$HOME"/.dotfiles --work-tree="$HOME" status --short 2> /dev/null)" + if [[ -z "$result" ]]; then + result="$(/usr/bin/git --git-dir="$HOME"/.dotfiles --work-tree="$HOME" cherry -v )" + if [[ -n "$result" ]]; then + echo YES + fi + fi + ;; + esac +} diff --git a/.functions/ps1.sh b/.functions/ps1.sh index efc5c67..8fc91d1 100644 --- a/.functions/ps1.sh +++ b/.functions/ps1.sh @@ -5,6 +5,8 @@ function set_bash_prompt () { local GIT_BRANCH="" local PYTHON_ENV="" local K8S_CURRENT_CONTEXT="" + local DOTF="" + local STATUS="" local COLOR_OFF='\033[0m' local COLOR_DIVIDER="\033[0;32m" @@ -16,6 +18,8 @@ function set_bash_prompt () { local COLOR_PATH="\033[0;37m" local COLOR_EXIT_STATUS="[\033[1;37m\033[41m" local COLOR_KUBERNETES="\033[1;37m\033[44m" + local COLOR_TODO="'\033[1;30m''\033[43m'" + local COLOR_DOTF="\033[1;30m\033[45m" local CURRENT_CONTEXT="" @@ -29,7 +33,21 @@ function set_bash_prompt () { fi fi - PS1="\n${COLOR_DIVIDER}┌──(${COLOR_USERNAME}\u${COLOR_USERHOSTAT}@${COLOR_HOSTNAME}\h${COLOR_DIVIDER})─[${COLOR_PATH}\w${COLOR_DIVIDER}]${EXIT_STATUS}${PYTHON_ENV}${K8S_CURRENT_CONTEXT}${GIT_BRANCH}" + if [[ $(type -t dotfiles_status) == function ]];then + if [[ $(dotfiles_status check_error) == YES ]];then + DOTF="${COLOR_DOTF}E" + elif [[ $(dotfiles_status check_status) ]];then + DOTF="${COLOR_DOTF}." + elif [[ $(dotfiles_status check_push) ]];then + DOTF="${COLOR_DOTF}p" + fi + fi + + if [[ -n $DOTF ]];then + STATUS="${COLOR_DIVIDER}[${DOTF}${COLOR_DIVIDER}]" + fi + + PS1="\n${COLOR_DIVIDER}┌──(${COLOR_USERNAME}\u${COLOR_USERHOSTAT}@${COLOR_HOSTNAME}\h${COLOR_DIVIDER})─[${COLOR_PATH}\w${COLOR_DIVIDER}]${EXIT_STATUS}${STATUS}${PYTHON_ENV}${K8S_CURRENT_CONTEXT}${GIT_BRANCH}" PS1="${PS1}\n${COLOR_DIVIDER}└─\$${COLOR_OFF} " }