]> git.immae.eu Git - perso/Immae/Config/Ansible.git/blobdiff - roles/shell/bash/templates/bashrc.j2
Add backup script
[perso/Immae/Config/Ansible.git] / roles / shell / bash / templates / bashrc.j2
index 91311e5eb8060276f668f48d138c6f83f3f74782..d6db656bc6d4cc160c9a1659c4916ac676edabd5 100644 (file)
@@ -31,18 +31,17 @@ alias rm="rm -i"
 alias psp="pstree -aUp $USER"
 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
@@ -50,57 +49,19 @@ function dev_prompt() {
   fi
 }
 
-function tmux_dev() {
-  type="${1:-bash}"
-  if [ -n "$TMUX" ]; then
-    m=switch-client
-  else
-    m=attach-session
-  fi
-
-  case "$type" in
-    "bash") start_dir="$HOME";;
-    "remote") start_dir="$HOME";;
-    "puppet") start_dir="/etc/puppetlabs/code"
-  esac
+if [ -n "$TMUX" ]; then
+  TMUX_SESSION_NAME=$(tmux display-message -p "#S")
+  export HISTFILE="$XDG_STATE_HOME/bash/tmux_${TMUX_SESSION_NAME}_history"
+fi
 
-  if tmux has-session -t "$type" 2>/dev/null; then
-    tmux $m -t "$type"
+function load_dev_env() {
+  if [ -z "$1" ]; then
+    source ../environment
   else
-    if [ "$type" = "remote" ]; then
-      tmux new-session -d -c $start_dir -s "$type" mosh immae.eu \; \
-          $m -t "$type"
-    elif [ -n "$start_dir" ]; then
-      tmux new-session -d -c $start_dir -s "$type" \; \
-          $m -t "$type" \; \
-          new-window -c $start_dir
-    else
-      tmux new-session -d -c "$HOME/workdir/$type" -s "$type" \; \
-          $m -t "$type" \; \
-          send-keys "../start" C-m \; \
-          rename-window "running" \; \
-          new-window -c "$HOME/workdir/$type"
-    fi
+    FL_ENV="$1" source ../environment
   fi
 }
 
-_tmux_dev() {
-  COMPREPLY=()
-  local cur="${COMP_WORDS[COMP_CWORD]}"
-  prefix="$HOME/workdir/"
-  local IFS=$'\n'
-  local items=($(IFS=' ' compgen -W "bash remote puppet" -- $cur) $(compgen -d $prefix$cur))
-  for item in ${items[@]}; do
-    [[ $item == $prefix.* ]] && continue
-    COMPREPLY+=("${item#$prefix}")
-  done
-}
-complete -o filenames -F _tmux_dev tmux_dev
-
-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 %}
 
@@ -129,32 +90,41 @@ function git_prompt() {
 }
 {% set ps1_git = '\[$(git_prompt_color)\]$(git_prompt)' %}
 
-function error_code() {
-  ret=$?
-  if [[ $ret != 0  ]]; then
-    echo "$ret "
-  fi
-}
-
 function running_jobs() {
   ret=$(jobs | wc -l)
   if [[ $ret != 0  ]]; then
     echo "[$ret] "
   fi
 }
-{% set ps1_status = '\[\\033[01;31m\]$(error_code)\[\\033[00;00m\]$(running_jobs)' -%}
 
-{# Ensure new line before the prompt #}
-{% set ps1_newline = '$(printf "%$((`tput cols`-1))s\\r")' -%}
+PROMPT_COMMAND=__prompt_command
 
-{% set ps1_other = '' %}
-{% if role.get(profile) == "fretlink" -%}
-  {% set ps1_other = '\[\\033[01;32m\]$(dev_prompt)' %}
-{%- endif %}
+__prompt_command () {
+  local ret="$?"
+  PS1=""
+  d="\[\033[00;00m\]"
+  red="\[\033[01;31m\]"
+  bgreen="\[\033[01;32m\]"
+  green="\[\033[00;32m\]"
+  blue="\[\033[94m\]"
 
-PS1='{{ ps1_newline }}{{ ps1_status }}{{ ps1_other }}{{ ps1_git }}\[\033[00;32m\]\u@\h\[\033[94m\] \w \$\[\033[00m\] '
+  # Ensure new line before the prompt
+  PS1='$(printf "%$((`tput cols`-1))s\r")'
+  if [[ $ret != 0  ]]; then
+    PS1+="$red$ret $d"
+  fi
+  PS1+='$(running_jobs)'
+{% if role.get(profile) == "fretlink" %}
+  PS1+="$bgreen"'$(dev_prompt)'
+{% endif %}
+  PS1+='\[$(git_prompt_color)\]$(git_prompt)'
+  PS1+="$green\u@\h$blue \w \$$d "
+}
 
-PROMPT_COMMAND="[[ -f $XDG_STATE_HOME/bash/bashrc_temp ]] && . $XDG_STATE_HOME/bash/bashrc_temp"
+NIX_PATH=nixpkgs=channel:nixpkgs-unstable
+source /usr/share/fzf/key-bindings.bash
+source /usr/share/fzf/completion.bash
+export FZF_COMPLETION_TRIGGER='#'
 
 {% if "nodejs" in features.get(profile, []) %}
 source /usr/share/nvm/init-nvm.sh