From: Ismaƫl Bouya Date: Thu, 8 Nov 2018 08:47:19 +0000 (+0100) Subject: Add a tmux_dev command X-Git-Tag: v1.0~35 X-Git-Url: https://git.immae.eu/?a=commitdiff_plain;h=de1c634c1fda61e34522595b40c66af17681bd14;p=perso%2FImmae%2FConfig%2FAnsible.git Add a tmux_dev command --- diff --git a/roles/shell/bash/templates/bashrc.j2 b/roles/shell/bash/templates/bashrc.j2 index 99ed55f..742e1e0 100644 --- a/roles/shell/bash/templates/bashrc.j2 +++ b/roles/shell/bash/templates/bashrc.j2 @@ -45,6 +45,43 @@ function dev_prompt() { echo "{$FRETLINK_ENV} " fi } + +function tmux_dev() { + type="${1:-bash}" + if [ -n "$TMUX" ]; then + m=switch-client + else + m=attach-session + fi + + if tmux has-session -t "$type" 2>/dev/null; then + tmux $m -t "$type" + else + if [ "$type" = "bash" ]; then + tmux new-session -d -s "$type" + tmux $m -t "$type" + 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 + fi +} + +_tmux_dev() { + COMPREPLY=() + local cur="${COMP_WORDS[COMP_CWORD]}" + prefix="$HOME/workdir/" + local IFS=$'\n' + local items=($(compgen -W "bash" -- $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 ##### /Fretlink {% endif %} diff --git a/roles/tools/templates/tmux.conf.j2 b/roles/tools/templates/tmux.conf.j2 index 8aad615..a7ac4ce 100644 --- a/roles/tools/templates/tmux.conf.j2 +++ b/roles/tools/templates/tmux.conf.j2 @@ -65,24 +65,3 @@ set-window-option -g window-status-bell-style fg=yellow,bold,underscore set -g default-terminal screen-256color set -g mouse on - -{% if role.get(profile) == "fretlink" %} -new-session -A -c "$HOME/workdir/admin-root" -s admin-root -send-keys "../start" C-m -rename-window "running" -new-window -new-session -A -c "$HOME/workdir/carrier-directory" -s carrier-directory -send-keys "../start" C-m -rename-window "running" -new-window -new-session -A -c "$HOME/workdir/notifier" -s notifier -send-keys "../start" C-m -rename-window "running" -new-window -new-session -A -c "$HOME/workdir/geodata" -s geodata -new-session -A -c "$HOME/workdir/app" -s app -send-keys "../start" C-m -rename-window "running" -new-window -select-window -t 1 -{% endif %}