]> git.immae.eu Git - perso/Immae/Config/Ansible.git/blame - roles/shell/bash/templates/bashrc.j2
Completion for stgit is now in standard location
[perso/Immae/Config/Ansible.git] / roles / shell / bash / templates / bashrc.j2
CommitLineData
397c4fed
IB
1#
2# ~/.bashrc
3#
4
a19180df 5[[ -f "$XDG_STATE_HOME/bash/bashrc_temp" ]] && . $XDG_STATE_HOME/bash/bashrc_temp
c235f9be 6
397c4fed
IB
7if [ -n "$HOME/.local/bin" ]; then
8 PATH="$HOME/.local/bin:$PATH"
9fi
10
11# If not running interactively, don't do anything
12[[ $- != *i* ]] && return
13
14export GPG_TTY=$(tty)
15export HISTFILE="$XDG_STATE_HOME/bash/history"
dd308b2f
IB
16export HISTTIMEFORMAT='%F %T '
17export HISTCONTROL="ignorespace:ignoredups"
397c4fed
IB
18
19alias vi=vim
20alias ls='ls --color=auto -F -T 0'
21alias tmux='tmux -f $XDG_CONFIG_HOME/tmux/tmux.conf'
22
23alias grep='grep --color=auto'
24alias fgrep='fgrep --color=auto'
25alias egrep='egrep --color=auto'
26
27alias sudo="sudo "
28alias mv="mv -i"
29alias cp="cp -i"
30alias rm="rm -i"
31alias psp="pstree -aUp $USER"
853c1445 32alias info='info -v active-link-style=yellow,bold -v link-style=yellow'
397c4fed 33
9f528ac4
IB
34if [[ -d "$XDG_DATA_HOME/bash_completion" ]]; then
35 for i in $XDG_DATA_HOME/bash_completion/*; do
36 [[ -f "$i" && -r "$i" ]] && . "$i"
37 done
38fi
39
397c4fed
IB
40{% if role.get(profile) == "fretlink" %}
41##### Some Fretlink aliases
9f528ac4
IB
42alias vpn=fl_vpn
43alias tmux_dev=fl_tmux_dev
44complete -o filenames -F _fl_tmux_dev tmux_dev
397c4fed
IB
45
46function dev_prompt() {
47 if [ -n "$FRETLINK_ENV" ]; then
48 echo "{$FRETLINK_ENV} "
49 fi
50}
de1c634c 51
bfe7d9cb
IB
52if [ -n "$TMUX" ]; then
53 TMUX_SESSION_NAME=$(tmux display-message -p "#S")
54 export HISTFILE="$XDG_STATE_HOME/bash/tmux_${TMUX_SESSION_NAME}_history"
55fi
397c4fed
IB
56##### /Fretlink
57{% endif %}
58
59# Non-printable chars need to be wrapped by \[ ... \] otherwise bash
60# will wrongly count the size of the prompt and glitch when going
61# through history
62function git_prompt_color() {
63 git diff --quiet 2>/dev/null && git diff --cached --quiet 2>/dev/null
64 gitstatus=$?
65 if [ "$gitstatus" -gt 0 ]; then
66 av=$'\033[01;31m'
67 else
68 av=$'\033[01;34m'
69 fi
70 echo "$av"
71}
72
73function git_prompt() {
74 gitinfo=$(git branch 2>/dev/null | grep "^*" | cut -c3-);
75 git diff --quiet 2>/dev/null && git diff --cached --quiet 2>/dev/null
76 gitstatus=$?
77 gitlsfiles=$(git ls-files . 2>/dev/null | wc -l);
78 if [ "$gitinfo" -a "$gitlsfiles" -gt 0 ]; then
79 echo -e "($gitinfo) "
80 fi
81}
853c1445 82{% set ps1_git = '\[$(git_prompt_color)\]$(git_prompt)' %}
397c4fed
IB
83
84function error_code() {
85 ret=$?
86 if [[ $ret != 0 ]]; then
87 echo "$ret "
88 fi
89}
90
91function running_jobs() {
92 ret=$(jobs | wc -l)
93 if [[ $ret != 0 ]]; then
94 echo "[$ret] "
95 fi
96}
853c1445 97{% set ps1_status = '\[\\033[01;31m\]$(error_code)\[\\033[00;00m\]$(running_jobs)' -%}
397c4fed 98
853c1445
IB
99{# Ensure new line before the prompt #}
100{% set ps1_newline = '$(printf "%$((`tput cols`-1))s\\r")' -%}
101
102{% set ps1_other = '' %}
103{% if role.get(profile) == "fretlink" -%}
104 {% set ps1_other = '\[\\033[01;32m\]$(dev_prompt)' %}
105{%- endif %}
106
107PS1='{{ ps1_newline }}{{ ps1_status }}{{ ps1_other }}{{ ps1_git }}\[\033[00;32m\]\u@\h\[\033[94m\] \w \$\[\033[00m\] '
397c4fed 108
853c1445 109PROMPT_COMMAND="[[ -f $XDG_STATE_HOME/bash/bashrc_temp ]] && . $XDG_STATE_HOME/bash/bashrc_temp"
a19180df 110
397c4fed
IB
111{% if "nodejs" in features.get(profile, []) %}
112source /usr/share/nvm/init-nvm.sh
113{% endif %}