]> git.immae.eu Git - perso/Immae/Config/Ansible.git/blame - roles/shell/bash/templates/bashrc.j2
add autorun for pcmanfm and a check for tmux_dev
[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
ae3ee401
IB
34[[ -f /usr/share/stgit/completion/stgit-completion.bash ]] && . /usr/share/stgit/completion/stgit-completion.bash
35
397c4fed
IB
36{% if role.get(profile) == "fretlink" %}
37##### Some Fretlink aliases
38alias getDump='s3cmd -c <(pass show Travail/Fretlink/S3) get '
39
40function vpn() {
41 TMPFILE=$(mktemp /tmp/openvpn.XXXXXX)
42 pass show Travail/Fretlink/OpenVPN >> $TMPFILE
43 sudo openvpn $TMPFILE
44 rm -f $TMPFILE
45}
46
47function dev_prompt() {
48 if [ -n "$FRETLINK_ENV" ]; then
49 echo "{$FRETLINK_ENV} "
50 fi
51}
de1c634c
IB
52
53function tmux_dev() {
54 type="${1:-bash}"
55 if [ -n "$TMUX" ]; then
56 m=switch-client
57 else
58 m=attach-session
59 fi
60
a65169cc
IB
61 case "$type" in
62 "bash") start_dir="$HOME";;
1f22cde1 63 "remote") start_dir="$HOME";;
a65169cc
IB
64 "puppet") start_dir="/etc/puppetlabs/code"
65 esac
66
de1c634c
IB
67 if tmux has-session -t "$type" 2>/dev/null; then
68 tmux $m -t "$type"
69 else
1f22cde1
IB
70 if [ "$type" = "remote" ]; then
71 tmux new-session -d -c $start_dir -s "$type" mosh immae.eu \; \
72 $m -t "$type"
73 elif [ -n "$start_dir" ]; then
a65169cc
IB
74 tmux new-session -d -c $start_dir -s "$type" \; \
75 $m -t "$type" \; \
76 new-window -c $start_dir
29585ffb 77 elif [ -d "$HOME/workdir/$type" ]; then
de1c634c
IB
78 tmux new-session -d -c "$HOME/workdir/$type" -s "$type" \; \
79 $m -t "$type" \; \
80 send-keys "../start" C-m \; \
81 rename-window "running" \; \
82 new-window -c "$HOME/workdir/$type"
29585ffb
IB
83 else
84 echo "Unknown session" >&2
85 false
de1c634c
IB
86 fi
87 fi
88}
89
90_tmux_dev() {
91 COMPREPLY=()
92 local cur="${COMP_WORDS[COMP_CWORD]}"
93 prefix="$HOME/workdir/"
94 local IFS=$'\n'
1f22cde1 95 local items=($(IFS=' ' compgen -W "bash remote puppet" -- $cur) $(compgen -d $prefix$cur))
de1c634c
IB
96 for item in ${items[@]}; do
97 [[ $item == $prefix.* ]] && continue
98 COMPREPLY+=("${item#$prefix}")
99 done
100}
101complete -o filenames -F _tmux_dev tmux_dev
bfe7d9cb
IB
102
103if [ -n "$TMUX" ]; then
104 TMUX_SESSION_NAME=$(tmux display-message -p "#S")
105 export HISTFILE="$XDG_STATE_HOME/bash/tmux_${TMUX_SESSION_NAME}_history"
106fi
397c4fed
IB
107##### /Fretlink
108{% endif %}
109
110# Non-printable chars need to be wrapped by \[ ... \] otherwise bash
111# will wrongly count the size of the prompt and glitch when going
112# through history
113function git_prompt_color() {
114 git diff --quiet 2>/dev/null && git diff --cached --quiet 2>/dev/null
115 gitstatus=$?
116 if [ "$gitstatus" -gt 0 ]; then
117 av=$'\033[01;31m'
118 else
119 av=$'\033[01;34m'
120 fi
121 echo "$av"
122}
123
124function git_prompt() {
125 gitinfo=$(git branch 2>/dev/null | grep "^*" | cut -c3-);
126 git diff --quiet 2>/dev/null && git diff --cached --quiet 2>/dev/null
127 gitstatus=$?
128 gitlsfiles=$(git ls-files . 2>/dev/null | wc -l);
129 if [ "$gitinfo" -a "$gitlsfiles" -gt 0 ]; then
130 echo -e "($gitinfo) "
131 fi
132}
853c1445 133{% set ps1_git = '\[$(git_prompt_color)\]$(git_prompt)' %}
397c4fed
IB
134
135function error_code() {
136 ret=$?
137 if [[ $ret != 0 ]]; then
138 echo "$ret "
139 fi
140}
141
142function running_jobs() {
143 ret=$(jobs | wc -l)
144 if [[ $ret != 0 ]]; then
145 echo "[$ret] "
146 fi
147}
853c1445 148{% set ps1_status = '\[\\033[01;31m\]$(error_code)\[\\033[00;00m\]$(running_jobs)' -%}
397c4fed 149
853c1445
IB
150{# Ensure new line before the prompt #}
151{% set ps1_newline = '$(printf "%$((`tput cols`-1))s\\r")' -%}
152
153{% set ps1_other = '' %}
154{% if role.get(profile) == "fretlink" -%}
155 {% set ps1_other = '\[\\033[01;32m\]$(dev_prompt)' %}
156{%- endif %}
157
158PS1='{{ ps1_newline }}{{ ps1_status }}{{ ps1_other }}{{ ps1_git }}\[\033[00;32m\]\u@\h\[\033[94m\] \w \$\[\033[00m\] '
397c4fed 159
853c1445 160PROMPT_COMMAND="[[ -f $XDG_STATE_HOME/bash/bashrc_temp ]] && . $XDG_STATE_HOME/bash/bashrc_temp"
a19180df 161
397c4fed
IB
162{% if "nodejs" in features.get(profile, []) %}
163source /usr/share/nvm/init-nvm.sh
164{% endif %}