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

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

# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
# Path
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
export PATH="$HOME/.cargo/bin:$PATH"
export PATH="$HOME/.local/bin:$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

# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
# macOS stuff
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
if [[ "$KERNEL" == Darwin* ]]; then
    eval "$(/opt/homebrew/bin/brew shellenv)"
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}"