summaryrefslogtreecommitdiff
path: root/.bashrc
blob: 18ab8e4fda5d0fe0072c8a310a6eb9856a44eb80 (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
#!/bin/sh

DOTFILES_DIR="$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")"

# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
# Path
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
export PATH="$DOTFILES_DIR/bin:$PATH"

# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
# Prompt
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
git_branch() {
    local branch
    branch=$(git symbolic-ref --short HEAD 2>/dev/null) || return
    local dirty=""
    [ -n "$(git status --porcelain 2>/dev/null)" ] && dirty="*"
    echo " (${branch}${dirty})"
}

# Colors
RESET='\[\e[0m\]'
BOLD='\[\e[1m\]'
GREEN='\[\e[32m\]'
BLUE='\[\e[34m\]'
YELLOW='\[\e[33m\]'
RED='\[\e[31m\]'

# Exit-status-aware prompt (shows red if last command failed)
set_prompt() {
    local exit_code=$?
    local status_color="${GREEN}"
    [ $exit_code -ne 0 ] && status_color="${RED}"

    PS1="${status_color}\u${RESET}@${GREEN}\h${RESET}:${YELLOW}\w${RESET}\$(git_branch)${BOLD} \$ ${RESET}"
}
PROMPT_COMMAND="set_prompt; ${PROMPT_COMMAND}"