Пример bashrc

bash example
bash color example 543x243
bash_ps.png
bash server example
bash server color example 543x243
bash_ps1.png
bash lxc example
bash lxc color example 543x243
bash_ps2.png

Простой пример .bashrc с историей и своими настройками цвета.
Помогает интуитивно отличать продакшн сервер от роутера и тестовое окружение от окружения разработки.

Где HISTSIZE=500000000 и HISTFILESIZE=500000000 устанавливают расширенные лимиты строк файла истории и его размера,
а HISTTIMEFORMAT="[%y%m%d %H:%M:%S] " задаёт форматирование истории команд.

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
case $- in
    *i*) ;;
      *) return;;
esac

HISTCONTROL=ignoreboth
# HISTCONTROL=ignoredups
# HISTCONTROL="ignorespace:erasedups"
shopt -s histappend
HISTSIZE=500000000
HISTFILESIZE=500000000
HISTTIMEFORMAT="[%y%m%d %H:%M:%S]  "
shopt -s checkwinsize
PROMPT_COMMAND="history -a; $PROMPT_COMMAND"
if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then
    debian_chroot=$(cat /etc/debian_chroot)
fi
case "$TERM" in
    xterm-color|*-256color) color_prompt=yes;;
esac
if [ -n "$force_color_prompt" ]; then
    if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
        color_prompt=yes
    else
        color_prompt=
    fi
fi

if [ "$color_prompt" = yes ]; then
    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
else
    PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi
unset color_prompt force_color_prompt

case "$TERM" in
xterm*|rxvt*)
    PS1='\[\e[38;5;237m\](\[\e[m\]\[\e[38;5;82m\]$debian_chroot\[\e[m\]\[\e[38;5;237m\])\[\e[m\]\[\e[38;5;25m\]\u\[\e[m\]\[\e[38;5;239m\]@\[\e[m\]\[\e[38;5;189m\]\h\[\e[m\]\[\e[38;5;239m\]:\[\e[m\]\[\e[38;5;111m\]\w\[\e[m\]\$ '
    ;;
*)
    ;;
esac
if [ -x /usr/bin/dircolors ]; then
    test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
    alias ls='ls --color=auto'
fi
if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases
fi
if ! shopt -oq posix; then
  if [ -f /usr/share/bash-completion/bash_completion ]; then
    . /usr/share/bash-completion/bash_completion
  elif [ -f /etc/bash_completion ]; then
    . /etc/bash_completion
  fi
fi

Объяснение параметров PS1

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
\[\e[38;5;237m\]        < color start       code: 237
  (                     < character '('
\[\e[m\]                < clear color

\[\e[38;5;82m\]         < color start       code: 82
  $debian_chroot        < var
\[\e[m\]                < clear color

\[\e[38;5;237m\]        < color start       code: 237
  )                     < character ')'
\[\e[m\]                < clear color

\[\e[38;5;25m\]         < color start       code: 25
  \u                    < $user var
\[\e[m\]                < clear color

\[\e[38;5;239m\]        < color start       code: 239
  @                     < character '@'
\[\e[m\]                < clear color

\[\e[38;5;189m\]        < color start       code: 189
  \h                    < $host var
\[\e[m\]                < clear color

\[\e[38;5;239m\]        < color start       code: 239
  :                     < character ':'
\[\e[m\]                < clear color

\[\e[38;5;111m\]        < color start       code: 111
  \w                    < $pwd var
\[\e[m\]                < clear color
  \$                    < escaped \character '$'