summaryrefslogtreecommitdiff
path: root/bash/prompt.sh
blob: 1a1434cf808e39ba46eba218ffcfba09d6b4ef2c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/bin/bash
# Bash Prompt

WHOAMI=$(id -un)
if [ "$WHOAMI" = "root" ] ; then
	PATHCOLOR='\[\033[01;31m\]'
	PROMPTCHR='\[\033[00;31m\]#'
	SHOWUSER=""
elif [ "$WHOAMI" == "kinote" ] || [ "$WHOAMI" == "aguespjo" ] ; then
	PATHCOLOR='\[\033[01;34m\]'
	PROMPTCHR='\[\033[00;34m\]%'
	SHOWUSER=""
else
	PATHCOLOR='\[\033[01;34m\]'
	PROMPTCHR='\[\033[01;34m\]%'
	SHOWUSER="$WHOAMI@"
fi

case "$(hostname)" in
	"surtr")         HOSTCOLOR='\[\033[00;36m\]';;
	"grani")         HOSTCOLOR='\[\033[01;30m\]';;
	"ymir")          HOSTCOLOR='\[\033[01;31m\]';;
	"niflheim")      HOSTCOLOR='\[\033[00;34m\]';;
	"nbiku1352")     HOSTCOLOR='\[\033[01;32m\]';;
	"fafnir")        HOSTCOLOR='\[\033[00;31m\]';;
	"pumuckl")       HOSTCOLOR='\[\033[01;31m\]';;
	"nothung")       HOSTCOLOR='\[\033[00;36m\]';;
	"mime")          HOSTCOLOR='\[\033[01;36m\]';;
	"loge")          HOSTCOLOR='\[\033[00;35m\]';;
	"freki")         HOSTCOLOR='\[\033[38;5;38m\]';;
	*)               HOSTCOLOR='\[\033[00;32m\]';;
esac


CERRAR='\[\033[00m\]'

export GIT_PS1_SHOWDIRTYSTATE=1
#export GIT_PS1_SHOWCOLORHINTS=1

if [[ "$INSIDE_EMACS" = 'vterm' ]]; then
    function vterm_printf(){
        if [ -n "$TMUX" ]; then
            # tell tmux to pass the escape sequences through
            # (Source: http://permalink.gmane.org/gmane.comp.terminal-emulators.tmux.user/1324)
            printf "\ePtmux;\e\e]%s\007\e\\" "$1"
        elif [ "${TERM%%-*}" = "screen" ]; then
            # GNU screen (screen, screen-256color, screen-256color-bce)
            printf "\eP\e]%s\007\e\\" "$1"
        else
            printf "\e]%s\e\\" "$1"
        fi
    }

    function clear(){
        vterm_printf "51;Evterm-clear-scrollback";
        tput clear;
    }

    vterm_prompt_end(){
        vterm_printf "51;A$(whoami)@$(hostname):$(pwd)"
    }
    PS1=$PS1'\[$(vterm_prompt_end)\]'
fi

# Export prompt
set_bash_prompt()
{
	# schroot indicator
	CHR="${SCHROOT_CHROOT_NAME:+(\[\033[01;32m\]$SCHROOT_CHROOT_NAME\[\033[00m\]) }"
	# virtualenv indicator
	VENV="${VIRTUAL_ENV:+(\[\033[00;32m\]venv\[\033[00m\])}"
	# Show only last two dirs in path
	LAST_TWO_DIRS=$(pwd | sed s_"$HOME"_~_ |rev| awk -F / '{print $1,"/",$2}' | rev | sed s_\ /\ _/_ | sed s_^/~_~_)
	# Git prompt
	GITPS1=$(__git_ps1 ':%s')
	if [[ "$GITPS1" == *\ * ]]; then
		GITPSCOLOR='\[\033[01;31m\]'
	else
		GITPSCOLOR='\[\033[01;35m\]'
	fi
	# Yocto BUILDDIR
	if [[ x"$BUILDDIR" != x"" ]]; then
		BUILDPS1='\[\033[01;31m\](build)'
	else
		BUILDPS1=""
	fi
	# Prompt
	PS1="$CHR$VENV$HOSTCOLOR$SHOWUSER\\h$CERRAR $BUILDPS1$PATHCOLOR$LAST_TWO_DIRS$CERRAR$GITPSCOLOR$GITPS1$CERRAR $PROMPTCHR $CERRAR"
        if [[ "$INSIDE_EMACS" = 'vterm' ]]; then
        	PS1=$PS1'\[$(vterm_prompt_end)\]'
        fi
}
PROMPT_COMMAND=set_bash_prompt
# vim: set ts=8 sts=8 sw=8 noexpandtab :