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

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

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

# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
# MSYS2 stuff
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
KERNEL="$(uname -s)"
if [[ "$KERNEL" == MSYS* || "$KERNEL" == MINGW* || "$KERNEL" == CLANG* ]]; then
    export MSYS=winsymlinks:nativestrict
fi

# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
# 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}"