]> git.immae.eu Git - perso/Immae/Config/dotdrop.git/blob - dotfiles/shell_bash/bashrc
8f4328339bf63ecd688dbbfafc6941af4c1fbd19
[perso/Immae/Config/dotdrop.git] / dotfiles / shell_bash / bashrc
1 #
2 # ~/.bashrc
3 #
4
5 if [ -n "$HOME/.local/bin" ]; then
6 PATH="$HOME/.local/bin:$PATH"
7 fi
8
9 # If not running interactively, don't do anything
10 [[ $- != *i* ]] && return
11
12 export HISTFILE="$XDG_STATE_HOME/bash/history"
13
14 alias vi=vim
15 alias ls='ls --color=auto -F -T 0'
16 alias tmux='tmux -f $XDG_CONFIG_HOME/tmux/tmux.conf'
17
18 alias grep='grep --color=auto'
19 alias fgrep='fgrep --color=auto'
20 alias egrep='egrep --color=auto'
21
22 alias sudo="sudo "
23 alias mv="mv -i"
24 alias cp="cp -i"
25 alias rm="rm -i"
26 alias psp="pstree -aUp $USER"
27 alias dotdrop="dotdrop --cfg $XDG_CONFIG_HOME/dotdrop/config.yaml"
28
29 {%@@ if role.get(profile) == "fretlink" @@%}
30 ##### Some Fretlink aliases
31 alias getDump='s3cmd -c <(pass show Travail/Fretlink/S3) get '
32
33 function vpn() {
34 TMPFILE=$(mktemp /tmp/openvpn.XXXXXX)
35 pass show Travail/Fretlink/OpenVPN >> $TMPFILE
36 sudo openvpn $TMPFILE
37 rm -f $TMPFILE
38 }
39
40 function dev_prompt() {
41 if [ -n "$FRETLINK_ENV" ]; then
42 echo "{$FRETLINK_ENV} "
43 fi
44 }
45 ##### /Fretlink
46 {%@@ endif @@%}
47
48 # Non-printable chars need to be wrapped by \[ ... \] otherwise bash
49 # will wrongly count the size of the prompt and glitch when going
50 # through history
51 function git_prompt_color() {
52 git diff --quiet 2>/dev/null && git diff --cached --quiet 2>/dev/null
53 gitstatus=$?
54 if [ "$gitstatus" -gt 0 ]; then
55 av=$'\033[01;31m'
56 else
57 av=$'\033[01;34m'
58 fi
59 echo "$av"
60 }
61
62 function git_prompt() {
63 gitinfo=$(git branch 2>/dev/null | grep "^*" | cut -c3-);
64 git diff --quiet 2>/dev/null && git diff --cached --quiet 2>/dev/null
65 gitstatus=$?
66 gitlsfiles=$(git ls-files . 2>/dev/null | wc -l);
67 if [ "$gitinfo" -a "$gitlsfiles" -gt 0 ]; then
68 echo -e "($gitinfo) "
69 fi
70 }
71
72 function error_code() {
73 ret=$?
74 if [[ $ret != 0 ]]; then
75 echo "$ret "
76 fi
77 }
78
79 function running_jobs() {
80 ret=$(jobs | wc -l)
81 if [[ $ret != 0 ]]; then
82 echo "[$ret] "
83 fi
84 }
85
86 {%@@ if role.get(profile) == "fretlink" @@%}
87 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\] '
88 {%@@ else @@%}
89 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\] '
90 {%@@ endif @@%}
91
92 {%@@ if "nodejs" in features.get(profile, []) @@%}
93 source /usr/share/nvm/init-nvm.sh
94 {%@@ endif @@%}