]> git.immae.eu Git - perso/Immae/Config/Ansible.git/blob - roles/shell/bash/templates/bashrc.j2
742e1e02e6c79fc5d35f3930580502f98879bb24
[perso/Immae/Config/Ansible.git] / roles / shell / bash / templates / bashrc.j2
1 #
2 # ~/.bashrc
3 #
4
5 [[ -f "$HOME/.bashrc_temp" ]] && . $HOME/.bashrc_temp
6
7 if [ -n "$HOME/.local/bin" ]; then
8 PATH="$HOME/.local/bin:$PATH"
9 fi
10
11 # If not running interactively, don't do anything
12 [[ $- != *i* ]] && return
13
14 export GPG_TTY=$(tty)
15 export HISTFILE="$XDG_STATE_HOME/bash/history"
16
17 alias vi=vim
18 alias ls='ls --color=auto -F -T 0'
19 alias tmux='tmux -f $XDG_CONFIG_HOME/tmux/tmux.conf'
20
21 alias grep='grep --color=auto'
22 alias fgrep='fgrep --color=auto'
23 alias egrep='egrep --color=auto'
24
25 alias sudo="sudo "
26 alias mv="mv -i"
27 alias cp="cp -i"
28 alias rm="rm -i"
29 alias psp="pstree -aUp $USER"
30 alias dotdrop="dotdrop --cfg $XDG_CONFIG_HOME/dotdrop/config.yaml"
31
32 {% if role.get(profile) == "fretlink" %}
33 ##### Some Fretlink aliases
34 alias getDump='s3cmd -c <(pass show Travail/Fretlink/S3) get '
35
36 function vpn() {
37 TMPFILE=$(mktemp /tmp/openvpn.XXXXXX)
38 pass show Travail/Fretlink/OpenVPN >> $TMPFILE
39 sudo openvpn $TMPFILE
40 rm -f $TMPFILE
41 }
42
43 function dev_prompt() {
44 if [ -n "$FRETLINK_ENV" ]; then
45 echo "{$FRETLINK_ENV} "
46 fi
47 }
48
49 function tmux_dev() {
50 type="${1:-bash}"
51 if [ -n "$TMUX" ]; then
52 m=switch-client
53 else
54 m=attach-session
55 fi
56
57 if tmux has-session -t "$type" 2>/dev/null; then
58 tmux $m -t "$type"
59 else
60 if [ "$type" = "bash" ]; then
61 tmux new-session -d -s "$type"
62 tmux $m -t "$type"
63 else
64 tmux new-session -d -c "$HOME/workdir/$type" -s "$type" \; \
65 $m -t "$type" \; \
66 send-keys "../start" C-m \; \
67 rename-window "running" \; \
68 new-window -c "$HOME/workdir/$type"
69 fi
70 fi
71 }
72
73 _tmux_dev() {
74 COMPREPLY=()
75 local cur="${COMP_WORDS[COMP_CWORD]}"
76 prefix="$HOME/workdir/"
77 local IFS=$'\n'
78 local items=($(compgen -W "bash" -- $cur) $(compgen -d $prefix$cur))
79 for item in ${items[@]}; do
80 [[ $item == $prefix.* ]] && continue
81 COMPREPLY+=("${item#$prefix}")
82 done
83 }
84 complete -o filenames -F _tmux_dev tmux_dev
85 ##### /Fretlink
86 {% endif %}
87
88 # Non-printable chars need to be wrapped by \[ ... \] otherwise bash
89 # will wrongly count the size of the prompt and glitch when going
90 # through history
91 function git_prompt_color() {
92 git diff --quiet 2>/dev/null && git diff --cached --quiet 2>/dev/null
93 gitstatus=$?
94 if [ "$gitstatus" -gt 0 ]; then
95 av=$'\033[01;31m'
96 else
97 av=$'\033[01;34m'
98 fi
99 echo "$av"
100 }
101
102 function git_prompt() {
103 gitinfo=$(git branch 2>/dev/null | grep "^*" | cut -c3-);
104 git diff --quiet 2>/dev/null && git diff --cached --quiet 2>/dev/null
105 gitstatus=$?
106 gitlsfiles=$(git ls-files . 2>/dev/null | wc -l);
107 if [ "$gitinfo" -a "$gitlsfiles" -gt 0 ]; then
108 echo -e "($gitinfo) "
109 fi
110 }
111
112 function error_code() {
113 ret=$?
114 if [[ $ret != 0 ]]; then
115 echo "$ret "
116 fi
117 }
118
119 function running_jobs() {
120 ret=$(jobs | wc -l)
121 if [[ $ret != 0 ]]; then
122 echo "[$ret] "
123 fi
124 }
125
126 {% if role.get(profile) == "fretlink" %}
127 PS1='\[\033[01;31m\]$(error_code)\[\033[00;00m\]$(running_jobs)\[\033[01;32m\]$(dev_prompt)\[$(git_prompt_color)\]$(git_prompt)\[\033[00;32m\]\u@\h\[\033[94m\] \w \$\[\033[00m\] '
128 {% else %}
129 PS1='\[\033[01;31m\]$(error_code)\[\033[00;00m\]$(running_jobs)\[$(git_prompt_color)\]$(git_prompt)\[\033[00;32m\]\u@\h\[\033[94m\] \w \$\[\033[00m\] '
130 {% endif %}
131
132 {% if "nodejs" in features.get(profile, []) %}
133 source /usr/share/nvm/init-nvm.sh
134 {% endif %}