diff options
author | Ismaël Bouya <ismael.bouya@fretlink.com> | 2018-11-08 09:47:19 +0100 |
---|---|---|
committer | Ismaël Bouya <ismael.bouya@fretlink.com> | 2018-11-08 09:47:19 +0100 |
commit | de1c634c1fda61e34522595b40c66af17681bd14 (patch) | |
tree | 115addd5065cf8e2817ebbac744625489107988e /roles/shell | |
parent | 78ae9604c629fcfadbbcb70ae743068ea6d40278 (diff) | |
download | Ansible-de1c634c1fda61e34522595b40c66af17681bd14.tar.gz Ansible-de1c634c1fda61e34522595b40c66af17681bd14.tar.zst Ansible-de1c634c1fda61e34522595b40c66af17681bd14.zip |
Add a tmux_dev command
Diffstat (limited to 'roles/shell')
-rw-r--r-- | roles/shell/bash/templates/bashrc.j2 | 37 |
1 files changed, 37 insertions, 0 deletions
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() { | |||
45 | echo "{$FRETLINK_ENV} " | 45 | echo "{$FRETLINK_ENV} " |
46 | fi | 46 | fi |
47 | } | 47 | } |
48 | |||
49 | function tmux_dev() { | ||
50 | type="${1:-bash}" | ||
51 | if [ -n "$TMUX" ]; then | ||
52 | m=switch-client | ||
53 | else | ||
54 | m=attach-session | ||
55 | fi | ||
56 | |||
57 | if tmux has-session -t "$type" 2>/dev/null; then | ||
58 | tmux $m -t "$type" | ||
59 | else | ||
60 | if [ "$type" = "bash" ]; then | ||
61 | tmux new-session -d -s "$type" | ||
62 | tmux $m -t "$type" | ||
63 | else | ||
64 | tmux new-session -d -c "$HOME/workdir/$type" -s "$type" \; \ | ||
65 | $m -t "$type" \; \ | ||
66 | send-keys "../start" C-m \; \ | ||
67 | rename-window "running" \; \ | ||
68 | new-window -c "$HOME/workdir/$type" | ||
69 | fi | ||
70 | fi | ||
71 | } | ||
72 | |||
73 | _tmux_dev() { | ||
74 | COMPREPLY=() | ||
75 | local cur="${COMP_WORDS[COMP_CWORD]}" | ||
76 | prefix="$HOME/workdir/" | ||
77 | local IFS=$'\n' | ||
78 | local items=($(compgen -W "bash" -- $cur) $(compgen -d $prefix$cur)) | ||
79 | for item in ${items[@]}; do | ||
80 | [[ $item == $prefix.* ]] && continue | ||
81 | COMPREPLY+=("${item#$prefix}") | ||
82 | done | ||
83 | } | ||
84 | complete -o filenames -F _tmux_dev tmux_dev | ||
48 | ##### /Fretlink | 85 | ##### /Fretlink |
49 | {% endif %} | 86 | {% endif %} |
50 | 87 | ||