summaryrefslogtreecommitdiff
path: root/roles/shell
diff options
context:
space:
mode:
Diffstat (limited to 'roles/shell')
-rw-r--r--roles/shell/bash/files/bashrc1
-rw-r--r--roles/shell/bash/tasks/main.yml17
-rw-r--r--roles/shell/bash/templates/bash_profile.j29
-rw-r--r--roles/shell/bash/templates/bashrc.j295
4 files changed, 122 insertions, 0 deletions
diff --git a/roles/shell/bash/files/bashrc b/roles/shell/bash/files/bashrc
new file mode 100644
index 0000000..28d0af9
--- /dev/null
+++ b/roles/shell/bash/files/bashrc
@@ -0,0 +1 @@
coucou
diff --git a/roles/shell/bash/tasks/main.yml b/roles/shell/bash/tasks/main.yml
new file mode 100644
index 0000000..d74421a
--- /dev/null
+++ b/roles/shell/bash/tasks/main.yml
@@ -0,0 +1,17 @@
1---
2- name: Add bashrc config
3 template:
4 src: bashrc.j2
5 dest: $HOME/.bashrc
6- name: Add bash_profile config
7 template:
8 src: bash_profile.j2
9 dest: $HOME/.bash_profile
10- name: Create bash state dir
11 file:
12 path: $XDG_STATE_HOME/bash
13 state: directory
14- name: Create less state dir
15 file:
16 path: $XDG_STATE_HOME/less
17 state: directory
diff --git a/roles/shell/bash/templates/bash_profile.j2 b/roles/shell/bash/templates/bash_profile.j2
new file mode 100644
index 0000000..06210fa
--- /dev/null
+++ b/roles/shell/bash/templates/bash_profile.j2
@@ -0,0 +1,9 @@
1# Some variables are loaded via pam (see .config/pam_environment)
2
3[[ -f ~/.bashrc ]] && . ~/.bashrc
4{% if "graphical_vt" in features.get(profile, []) %}
5
6if [[ ! $DISPLAY && $XDG_VTNR -eq 1 ]]; then
7 exec startx $XDG_CONFIG_HOME/xinitrc > $XDG_STATE_HOME/xsession_errors 2>&1
8fi
9{% endif %}
diff --git a/roles/shell/bash/templates/bashrc.j2 b/roles/shell/bash/templates/bashrc.j2
new file mode 100644
index 0000000..2285d2b
--- /dev/null
+++ b/roles/shell/bash/templates/bashrc.j2
@@ -0,0 +1,95 @@
1#
2# ~/.bashrc
3#
4
5if [ -n "$HOME/.local/bin" ]; then
6 PATH="$HOME/.local/bin:$PATH"
7fi
8
9# If not running interactively, don't do anything
10[[ $- != *i* ]] && return
11
12export GPG_TTY=$(tty)
13export HISTFILE="$XDG_STATE_HOME/bash/history"
14
15alias vi=vim
16alias ls='ls --color=auto -F -T 0'
17alias tmux='tmux -f $XDG_CONFIG_HOME/tmux/tmux.conf'
18
19alias grep='grep --color=auto'
20alias fgrep='fgrep --color=auto'
21alias egrep='egrep --color=auto'
22
23alias sudo="sudo "
24alias mv="mv -i"
25alias cp="cp -i"
26alias rm="rm -i"
27alias psp="pstree -aUp $USER"
28alias dotdrop="dotdrop --cfg $XDG_CONFIG_HOME/dotdrop/config.yaml"
29
30{% if role.get(profile) == "fretlink" %}
31##### Some Fretlink aliases
32alias getDump='s3cmd -c <(pass show Travail/Fretlink/S3) get '
33
34function vpn() {
35 TMPFILE=$(mktemp /tmp/openvpn.XXXXXX)
36 pass show Travail/Fretlink/OpenVPN >> $TMPFILE
37 sudo openvpn $TMPFILE
38 rm -f $TMPFILE
39}
40
41function dev_prompt() {
42 if [ -n "$FRETLINK_ENV" ]; then
43 echo "{$FRETLINK_ENV} "
44 fi
45}
46##### /Fretlink
47{% endif %}
48
49# Non-printable chars need to be wrapped by \[ ... \] otherwise bash
50# will wrongly count the size of the prompt and glitch when going
51# through history
52function git_prompt_color() {
53 git diff --quiet 2>/dev/null && git diff --cached --quiet 2>/dev/null
54 gitstatus=$?
55 if [ "$gitstatus" -gt 0 ]; then
56 av=$'\033[01;31m'
57 else
58 av=$'\033[01;34m'
59 fi
60 echo "$av"
61}
62
63function git_prompt() {
64 gitinfo=$(git branch 2>/dev/null | grep "^*" | cut -c3-);
65 git diff --quiet 2>/dev/null && git diff --cached --quiet 2>/dev/null
66 gitstatus=$?
67 gitlsfiles=$(git ls-files . 2>/dev/null | wc -l);
68 if [ "$gitinfo" -a "$gitlsfiles" -gt 0 ]; then
69 echo -e "($gitinfo) "
70 fi
71}
72
73function error_code() {
74 ret=$?
75 if [[ $ret != 0 ]]; then
76 echo "$ret "
77 fi
78}
79
80function running_jobs() {
81 ret=$(jobs | wc -l)
82 if [[ $ret != 0 ]]; then
83 echo "[$ret] "
84 fi
85}
86
87{% if role.get(profile) == "fretlink" %}
88PS1='\[\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\] '
89{% else %}
90PS1='\[\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\] '
91{% endif %}
92
93{% if "nodejs" in features.get(profile, []) %}
94source /usr/share/nvm/init-nvm.sh
95{% endif %}