]> git.immae.eu Git - perso/Immae/Config/Ansible.git/blob - roles/shell/bash/templates/bashrc.j2
Move bashrc temporary file to state dir
[perso/Immae/Config/Ansible.git] / roles / shell / bash / templates / bashrc.j2
1 #
2 # ~/.bashrc
3 #
4
5 [[ -f "$XDG_STATE_HOME/bash/bashrc_temp" ]] && . $XDG_STATE_HOME/bash/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 [[ -f /usr/share/stgit/completion/stgit-completion.bash ]] && . /usr/share/stgit/completion/stgit-completion.bash
33
34 {% if role.get(profile) == "fretlink" %}
35 ##### Some Fretlink aliases
36 alias getDump='s3cmd -c <(pass show Travail/Fretlink/S3) get '
37
38 function vpn() {
39 TMPFILE=$(mktemp /tmp/openvpn.XXXXXX)
40 pass show Travail/Fretlink/OpenVPN >> $TMPFILE
41 sudo openvpn $TMPFILE
42 rm -f $TMPFILE
43 }
44
45 function dev_prompt() {
46 if [ -n "$FRETLINK_ENV" ]; then
47 echo "{$FRETLINK_ENV} "
48 fi
49 }
50
51 function tmux_dev() {
52 type="${1:-bash}"
53 if [ -n "$TMUX" ]; then
54 m=switch-client
55 else
56 m=attach-session
57 fi
58
59 case "$type" in
60 "bash") start_dir="$HOME";;
61 "puppet") start_dir="/etc/puppetlabs/code"
62 esac
63
64 if tmux has-session -t "$type" 2>/dev/null; then
65 tmux $m -t "$type"
66 else
67 if [ -n "$start_dir" ]; then
68 tmux new-session -d -c $start_dir -s "$type" \; \
69 $m -t "$type" \; \
70 new-window -c $start_dir
71 else
72 tmux new-session -d -c "$HOME/workdir/$type" -s "$type" \; \
73 $m -t "$type" \; \
74 send-keys "../start" C-m \; \
75 rename-window "running" \; \
76 new-window -c "$HOME/workdir/$type"
77 fi
78 fi
79 }
80
81 _tmux_dev() {
82 COMPREPLY=()
83 local cur="${COMP_WORDS[COMP_CWORD]}"
84 prefix="$HOME/workdir/"
85 local IFS=$'\n'
86 local items=($(IFS=' ' compgen -W "bash puppet" -- $cur) $(compgen -d $prefix$cur))
87 for item in ${items[@]}; do
88 [[ $item == $prefix.* ]] && continue
89 COMPREPLY+=("${item#$prefix}")
90 done
91 }
92 complete -o filenames -F _tmux_dev tmux_dev
93 ##### /Fretlink
94 {% endif %}
95
96 # Non-printable chars need to be wrapped by \[ ... \] otherwise bash
97 # will wrongly count the size of the prompt and glitch when going
98 # through history
99 function git_prompt_color() {
100 git diff --quiet 2>/dev/null && git diff --cached --quiet 2>/dev/null
101 gitstatus=$?
102 if [ "$gitstatus" -gt 0 ]; then
103 av=$'\033[01;31m'
104 else
105 av=$'\033[01;34m'
106 fi
107 echo "$av"
108 }
109
110 function git_prompt() {
111 gitinfo=$(git branch 2>/dev/null | grep "^*" | cut -c3-);
112 git diff --quiet 2>/dev/null && git diff --cached --quiet 2>/dev/null
113 gitstatus=$?
114 gitlsfiles=$(git ls-files . 2>/dev/null | wc -l);
115 if [ "$gitinfo" -a "$gitlsfiles" -gt 0 ]; then
116 echo -e "($gitinfo) "
117 fi
118 }
119
120 function error_code() {
121 ret=$?
122 if [[ $ret != 0 ]]; then
123 echo "$ret "
124 fi
125 }
126
127 function running_jobs() {
128 ret=$(jobs | wc -l)
129 if [[ $ret != 0 ]]; then
130 echo "[$ret] "
131 fi
132 }
133
134 {% if role.get(profile) == "fretlink" %}
135 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\] '
136 {% else %}
137 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\] '
138 {% endif %}
139
140 PROMPT_COMMAND="[[ -f "$XDG_STATE_HOME/bash/bashrc_temp" ]] && . $XDG_STATE_HOME/bash/bashrc_temp"
141
142 {% if "nodejs" in features.get(profile, []) %}
143 source /usr/share/nvm/init-nvm.sh
144 {% endif %}