diff options
| author | Kรฉvin Le Gouguec <kevin.legouguec@gmail.com> | 2016-11-04 18:29:48 +0100 |
|---|---|---|
| committer | Kรฉvin Le Gouguec <kevin.legouguec@gmail.com> | 2016-11-04 18:29:48 +0100 |
| commit | a766685321f35f131863041e10d8a36e4814eab0 (patch) | |
| tree | e1b9ea51c101abacf00a0e1f0b2cf12f1cc59839 | |
| download | dotfiles-a766685321f35f131863041e10d8a36e4814eab0.tar.xz | |
Add initial script
| -rw-r--r-- | .bashprompt | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/.bashprompt b/.bashprompt new file mode 100644 index 0000000..2e0ba7d --- /dev/null +++ b/.bashprompt @@ -0,0 +1,98 @@ +__set-title () +{ + local title + local path=$(git root 2> /dev/null) + + if [ -n "${path}" ] + then + title=$(basename ${path}) + else + title="${USER}:${PWD/~/\~}" + fi + + echo -ne "\033]2;${title}\007" +} + +__fontify () +{ + local -A codes + codes[red]='31' + codes[green]='32' + codes[blue]='34' + codes[white]='37' + codes[bold]='1' + codes[dim]='2' + codes[clear]='0' + + local string=$1 + shift + + # We need to add \[ \] around CSI sequences so that Bash can tell which + # characters are non-printing. + + echo -en '\[\033[' + + local attributes=($@) + local nb=$# + + for ((i=0; i<nb; i++)) + do + a=${attributes[${i}]} + echo -en ${codes[${a}]} + + if ((i<nb-1)) + then + echo -en ';' + else + echo -en 'm\]' + fi + done + + echo -n "${string}" + echo -en "\[\033[0m\]" +} + +__set-prompt () +{ + local last_status=$1 + + PS1='' + + if [ ${last_status} -ne 0 ] + then + PS1+=$(__fontify "${last_status} " bold red) + fi + + PS1+=$(__fontify '\u' green) + PS1+=$(__fontify : bold white) + PS1+=$(__fontify '\w' bold blue) + PS1+=$(__fontify "$(__git_ps1 '(%s)')" red) + PS1+=$(__fontify '\$' bold white) + PS1+=' ' +} + +__draw-rule () +{ + rule='' + for ((i=0; i<COLUMNS; i++)) + do + rule+=โ + done + __fontify ${rule} dim +} + +__refresh-terminal () +{ + local last_status=$? + + __set-title + __set-prompt ${last_status} + # __draw-rule +} + + +. /usr/lib/git-core/git-sh-prompt +GIT_PS1_SHOWDIRTYSTATE=t +GIT_PS1_SHOWUPSTREAM=auto + +export PROMPT_COMMAND=__refresh-terminal |
