]> git.immae.eu Git - perso/Immae/Config/Ansible.git/blobdiff - roles/shell/bash/templates/bashrc.j2
Move bash functions to separate scripts
[perso/Immae/Config/Ansible.git] / roles / shell / bash / templates / bashrc.j2
index 99ed55f9919c2cb7dbcdc10069003df462e4e77e..0dc80c0962da9f074424121615fb2dcf9e0cbf0b 100644 (file)
@@ -2,7 +2,7 @@
 # ~/.bashrc
 #
 
-[[ -f "$HOME/.bashrc_temp" ]] && . $HOME/.bashrc_temp
+[[ -f "$XDG_STATE_HOME/bash/bashrc_temp" ]] && . $XDG_STATE_HOME/bash/bashrc_temp
 
 if [ -n "$HOME/.local/bin" ]; then
   PATH="$HOME/.local/bin:$PATH"
@@ -13,6 +13,8 @@ fi
 
 export GPG_TTY=$(tty)
 export HISTFILE="$XDG_STATE_HOME/bash/history"
+export HISTTIMEFORMAT='%F %T '
+export HISTCONTROL="ignorespace:ignoredups"
 
 alias vi=vim
 alias ls='ls --color=auto -F -T 0'
@@ -27,24 +29,32 @@ alias mv="mv -i"
 alias cp="cp -i"
 alias rm="rm -i"
 alias psp="pstree -aUp $USER"
-alias dotdrop="dotdrop --cfg $XDG_CONFIG_HOME/dotdrop/config.yaml"
+alias info='info -v active-link-style=yellow,bold -v link-style=yellow'
+
+[[ -f /usr/share/stgit/completion/stgit-completion.bash ]] && . /usr/share/stgit/completion/stgit-completion.bash
+
+if [[ -d "$XDG_DATA_HOME/bash_completion" ]]; then
+  for i in $XDG_DATA_HOME/bash_completion/*; do
+    [[ -f "$i" && -r "$i" ]] && . "$i"
+  done
+fi
 
 {% if role.get(profile) == "fretlink" %}
 ##### Some Fretlink aliases
-alias getDump='s3cmd -c <(pass show Travail/Fretlink/S3) get '
-
-function vpn() {
-  TMPFILE=$(mktemp /tmp/openvpn.XXXXXX)
-  pass show Travail/Fretlink/OpenVPN >> $TMPFILE
-  sudo openvpn $TMPFILE
-  rm -f $TMPFILE
-}
+alias vpn=fl_vpn
+alias tmux_dev=fl_tmux_dev
+complete -o filenames -F _fl_tmux_dev tmux_dev
 
 function dev_prompt() {
   if [ -n "$FRETLINK_ENV" ]; then
     echo "{$FRETLINK_ENV} "
   fi
 }
+
+if [ -n "$TMUX" ]; then
+  TMUX_SESSION_NAME=$(tmux display-message -p "#S")
+  export HISTFILE="$XDG_STATE_HOME/bash/tmux_${TMUX_SESSION_NAME}_history"
+fi
 ##### /Fretlink
 {% endif %}
 
@@ -71,6 +81,7 @@ function git_prompt() {
     echo -e "($gitinfo) "
   fi
 }
+{% set ps1_git = '\[$(git_prompt_color)\]$(git_prompt)' %}
 
 function error_code() {
   ret=$?
@@ -85,12 +96,19 @@ function running_jobs() {
     echo "[$ret] "
   fi
 }
+{% set ps1_status = '\[\\033[01;31m\]$(error_code)\[\\033[00;00m\]$(running_jobs)' -%}
 
-{% if role.get(profile) == "fretlink" %}
-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\] '
-{% else %}
-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\] '
-{% endif %}
+{# Ensure new line before the prompt #}
+{% set ps1_newline = '$(printf "%$((`tput cols`-1))s\\r")' -%}
+
+{% set ps1_other = '' %}
+{% if role.get(profile) == "fretlink" -%}
+  {% set ps1_other = '\[\\033[01;32m\]$(dev_prompt)' %}
+{%- endif %}
+
+PS1='{{ ps1_newline }}{{ ps1_status }}{{ ps1_other }}{{ ps1_git }}\[\033[00;32m\]\u@\h\[\033[94m\] \w \$\[\033[00m\] '
+
+PROMPT_COMMAND="[[ -f $XDG_STATE_HOME/bash/bashrc_temp ]] && . $XDG_STATE_HOME/bash/bashrc_temp"
 
 {% if "nodejs" in features.get(profile, []) %}
 source /usr/share/nvm/init-nvm.sh