]> git.immae.eu Git - perso/Immae/Config/Ansible.git/blame - roles/shell/bash/templates/bashrc.j2
Move bashrc temporary file to state dir
[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"
16
17alias vi=vim
18alias ls='ls --color=auto -F -T 0'
19alias tmux='tmux -f $XDG_CONFIG_HOME/tmux/tmux.conf'
20
21alias grep='grep --color=auto'
22alias fgrep='fgrep --color=auto'
23alias egrep='egrep --color=auto'
24
25alias sudo="sudo "
26alias mv="mv -i"
27alias cp="cp -i"
28alias rm="rm -i"
29alias psp="pstree -aUp $USER"
30alias dotdrop="dotdrop --cfg $XDG_CONFIG_HOME/dotdrop/config.yaml"
31
ae3ee401
IB
32[[ -f /usr/share/stgit/completion/stgit-completion.bash ]] && . /usr/share/stgit/completion/stgit-completion.bash
33
397c4fed
IB
34{% if role.get(profile) == "fretlink" %}
35##### Some Fretlink aliases
36alias getDump='s3cmd -c <(pass show Travail/Fretlink/S3) get '
37
38function vpn() {
39 TMPFILE=$(mktemp /tmp/openvpn.XXXXXX)
40 pass show Travail/Fretlink/OpenVPN >> $TMPFILE
41 sudo openvpn $TMPFILE
42 rm -f $TMPFILE
43}
44
45function dev_prompt() {
46 if [ -n "$FRETLINK_ENV" ]; then
47 echo "{$FRETLINK_ENV} "
48 fi
49}
de1c634c
IB
50
51function tmux_dev() {
52 type="${1:-bash}"
53 if [ -n "$TMUX" ]; then
54 m=switch-client
55 else
56 m=attach-session
57 fi
58
a65169cc
IB
59 case "$type" in
60 "bash") start_dir="$HOME";;
61 "puppet") start_dir="/etc/puppetlabs/code"
62 esac
63
de1c634c
IB
64 if tmux has-session -t "$type" 2>/dev/null; then
65 tmux $m -t "$type"
66 else
a65169cc
IB
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
de1c634c
IB
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'
a65169cc 86 local items=($(IFS=' ' compgen -W "bash puppet" -- $cur) $(compgen -d $prefix$cur))
de1c634c
IB
87 for item in ${items[@]}; do
88 [[ $item == $prefix.* ]] && continue
89 COMPREPLY+=("${item#$prefix}")
90 done
91}
92complete -o filenames -F _tmux_dev tmux_dev
397c4fed
IB
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
99function 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
110function 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
120function error_code() {
121 ret=$?
122 if [[ $ret != 0 ]]; then
123 echo "$ret "
124 fi
125}
126
127function 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" %}
135PS1='\[\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 %}
137PS1='\[\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
a19180df
IB
140PROMPT_COMMAND="[[ -f "$XDG_STATE_HOME/bash/bashrc_temp" ]] && . $XDG_STATE_HOME/bash/bashrc_temp"
141
397c4fed
IB
142{% if "nodejs" in features.get(profile, []) %}
143source /usr/share/nvm/init-nvm.sh
144{% endif %}