blob: 26e8ee471505839889f5110f4550aad802feb13d (
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
|
#!/usr/bin/env bash
# ~/.config/bash/bashrc
# Config principal do bash, seguindo XDG (chamado via ~/.bashrc)
[[ $- != *i* ]] && return # só roda em shell interativo
source "$HOME/.config/bash/aliases"
### HISTÓRICO ###
export HISTFILE="$HOME/.local/state/bash/history"
if [ ! -f "$HISTFILE" ]; then mkdir -p "$(dirname "$HISTFILE")"; fi
export HISTSIZE=10000
export HISTFILESIZE=20000
export HISTCONTROL=ignoreboth:erasedups # ignora duplicatas e comandos com espaço na frente
shopt -s histappend # append em vez de overwrite entre sessões
shopt -s cmdhist # comandos multi-linha viram uma entrada só
### NAVEGAÇÃO ###
shopt -s autocd
shopt -s cdspell
shopt -s dirspell
shopt -s globstar
### COMPLETION NATIVA ###
bind "set completion-ignore-case on" # completion case-insensitive
bind "set show-all-if-ambiguous on" # mostra opções na primeira TAB, sem precisar apertar 2x
bind "set menu-complete-display-prefix on"
if [ -f /usr/share/bash-completion/bash_completion ]; then
source "/usr/share/bash-completion/bash_completion"
elif [ -f /etc/bash_completion ]; then
source "/etc/bash_completion"
fi
### CORES BASE (gruvbox-ish) ###
C_RESET="\[\e[0m\]"
C_USER="\[\e[38;5;214m\]" # laranja
C_DIR="\[\e[38;5;109m\]" # azul claro
C_GIT="\[\e[38;5;172m\]" # amarelo/mostarda
C_ERR="\[\e[38;5;167m\]" # vermelho
### GIT BRANCH NO PROMPT ###
__git_branch() {
local branch
branch=$(git symbolic-ref --short HEAD 2>/dev/null) || \
branch=$(git rev-parse --short HEAD 2>/dev/null)
[ -n "$branch" ] && printf " (%s)" "$branch"
}
### MONTA O PROMPT ###
# Formato: [código-erro-se-houver] usuário@host diretório (git-branch)
# $ (usuário comum) ou # (root)
build_prompt() {
local last_exit=$?
PS1=""
if [ $last_exit -ne 0 ]; then
PS1+="${C_ERR}[${last_exit}]${C_RESET} "
fi
PS1+="${C_USER}\u@\h${C_RESET}:${C_DIR}\w${C_RESET}"
PS1+="${C_GIT}\$(__git_branch)${C_RESET}"
if [ "$(id -u)" -eq 0 ]; then
PS1+=" \[\e[1;31m\]#\[\e[0m\] "
else
PS1+=" \[\e[1m\]\$\[\e[0m\] "
fi
}
PROMPT_COMMAND="build_prompt"
### VARIÁVEIS ÚTEIS ###
export EDITOR=nvim
export VISUAL=nvim
export LESSHISTFILE="$HOME/.local/state/bash/lesshst"
# reorganize
set bell-style none
|