]> git.immae.eu Git - perso/Immae/Config/Ansible.git/blobdiff - roles/shell/bash/templates/bashrc.j2
Add remote session for tmux
[perso/Immae/Config/Ansible.git] / roles / shell / bash / templates / bashrc.j2
index fff19f762624f64731767fdc92db6c4f8de0d8a4..08518c9dca101e731573bb85154913c7c132c9d4 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"
@@ -58,13 +58,17 @@ function tmux_dev() {
 
   case "$type" in
     "bash") start_dir="$HOME";;
+    "remote") start_dir="$HOME";;
     "puppet") start_dir="/etc/puppetlabs/code"
   esac
 
   if tmux has-session -t "$type" 2>/dev/null; then
     tmux $m -t "$type"
   else
-    if [ -n "$start_dir" ]; then
+    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
@@ -83,13 +87,18 @@ _tmux_dev() {
   local cur="${COMP_WORDS[COMP_CWORD]}"
   prefix="$HOME/workdir/"
   local IFS=$'\n'
-  local items=($(IFS=' ' compgen -W "bash puppet" -- $cur) $(compgen -d $prefix$cur))
+  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 %}
 
@@ -137,6 +146,8 @@ PS1='\[\033[01;31m\]$(error_code)\[\033[00;00m\]$(running_jobs)\[\033[01;32m\]$(
 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 %}
 
+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
 {% endif %}