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