summaryrefslogtreecommitdiff
path: root/roles
diff options
context:
space:
mode:
Diffstat (limited to 'roles')
-rw-r--r--roles/contexts/fretlink/files/scripts/_fl_tmux_dev14
-rw-r--r--roles/contexts/fretlink/files/scripts/fl_getDump3
-rw-r--r--roles/contexts/fretlink/files/scripts/fl_tmux_dev36
-rw-r--r--roles/contexts/fretlink/files/scripts/fl_vpn8
-rw-r--r--roles/contexts/fretlink/tasks/main.yml21
-rw-r--r--roles/shell/bash/templates/bashrc.j267
-rw-r--r--roles/tools/templates/tmux.conf.j22
7 files changed, 92 insertions, 59 deletions
diff --git a/roles/contexts/fretlink/files/scripts/_fl_tmux_dev b/roles/contexts/fretlink/files/scripts/_fl_tmux_dev
new file mode 100644
index 0000000..3cfe50a
--- /dev/null
+++ b/roles/contexts/fretlink/files/scripts/_fl_tmux_dev
@@ -0,0 +1,14 @@
1#!/bin/bash
2
3_fl_tmux_dev() {
4 COMPREPLY=()
5 local cur="${COMP_WORDS[COMP_CWORD]}"
6 prefix="$HOME/workdir/"
7 local IFS=$'\n'
8 local items=($(IFS=' ' compgen -W "bash remote puppet" -- $cur) $(compgen -d $prefix$cur))
9 for item in ${items[@]}; do
10 [[ $item == $prefix.* ]] && continue
11 COMPREPLY+=("${item#$prefix}")
12 done
13}
14complete -o filenames -F _fl_tmux_dev fl_tmux_dev
diff --git a/roles/contexts/fretlink/files/scripts/fl_getDump b/roles/contexts/fretlink/files/scripts/fl_getDump
new file mode 100644
index 0000000..808dc01
--- /dev/null
+++ b/roles/contexts/fretlink/files/scripts/fl_getDump
@@ -0,0 +1,3 @@
1#!/bin/bash
2
3s3cmd -c <(pass show Travail/Fretlink/S3) get "$1"
diff --git a/roles/contexts/fretlink/files/scripts/fl_tmux_dev b/roles/contexts/fretlink/files/scripts/fl_tmux_dev
new file mode 100644
index 0000000..ca89e27
--- /dev/null
+++ b/roles/contexts/fretlink/files/scripts/fl_tmux_dev
@@ -0,0 +1,36 @@
1#!/bin/bash
2
3type="${1:-bash}"
4if [ -n "$TMUX" ]; then
5 m=switch-client
6else
7 m=attach-session
8fi
9
10case "$type" in
11 "bash") start_dir="$HOME";;
12 "remote") start_dir="$HOME";;
13 "puppet") start_dir="/etc/puppetlabs/code"
14esac
15
16if tmux has-session -t "$type" 2>/dev/null; then
17 tmux $m -t "$type"
18else
19 if [ "$type" = "remote" ]; then
20 tmux new-session -d -c $start_dir -s "$type" mosh immae.eu \; \
21 $m -t "$type"
22 elif [ -n "$start_dir" ]; then
23 tmux new-session -d -c $start_dir -s "$type" \; \
24 $m -t "$type" \; \
25 new-window -c $start_dir
26 elif [ -d "$HOME/workdir/$type" ]; then
27 tmux new-session -d -c "$HOME/workdir/$type" -s "$type" \; \
28 $m -t "$type" \; \
29 send-keys "../start" C-m \; \
30 rename-window "running" \; \
31 new-window -c "$HOME/workdir/$type"
32 else
33 echo "Unknown session" >&2
34 exit 1
35 fi
36fi
diff --git a/roles/contexts/fretlink/files/scripts/fl_vpn b/roles/contexts/fretlink/files/scripts/fl_vpn
new file mode 100644
index 0000000..1d3bc36
--- /dev/null
+++ b/roles/contexts/fretlink/files/scripts/fl_vpn
@@ -0,0 +1,8 @@
1#!/bin/bash
2
3TMPFILE=$(mktemp /tmp/openvpn.XXXXXX)
4
5trap "rm -f $TMPFILE" EXIT
6
7pass show Travail/Fretlink/OpenVPN >> $TMPFILE
8sudo openvpn $TMPFILE
diff --git a/roles/contexts/fretlink/tasks/main.yml b/roles/contexts/fretlink/tasks/main.yml
index 4106bf1..ce69e02 100644
--- a/roles/contexts/fretlink/tasks/main.yml
+++ b/roles/contexts/fretlink/tasks/main.yml
@@ -90,3 +90,24 @@
90 scope: user 90 scope: user
91 name: remind@work.service 91 name: remind@work.service
92 enabled: true 92 enabled: true
93- name: scripts
94 block:
95 - name: completion directory
96 file:
97 state: directory
98 path: $XDG_DATA_HOME/bash_completion
99 - name: scripts
100 copy:
101 mode: 0755
102 src: "scripts/{{ item }}"
103 dest: "$HOME/.local/bin/{{ item }}"
104 loop:
105 - fl_tmux_dev
106 - fl_vpn
107 - fl_getDump
108 - name: completion scripts
109 copy:
110 src: "scripts/_{{ item }}"
111 dest: "$XDG_DATA_HOME/bash_completion/_{{ item }}"
112 loop:
113 - fl_tmux_dev
diff --git a/roles/shell/bash/templates/bashrc.j2 b/roles/shell/bash/templates/bashrc.j2
index bf5acfa..0dc80c0 100644
--- a/roles/shell/bash/templates/bashrc.j2
+++ b/roles/shell/bash/templates/bashrc.j2
@@ -33,16 +33,17 @@ alias info='info -v active-link-style=yellow,bold -v link-style=yellow'
33 33
34[[ -f /usr/share/stgit/completion/stgit-completion.bash ]] && . /usr/share/stgit/completion/stgit-completion.bash 34[[ -f /usr/share/stgit/completion/stgit-completion.bash ]] && . /usr/share/stgit/completion/stgit-completion.bash
35 35
36if [[ -d "$XDG_DATA_HOME/bash_completion" ]]; then
37 for i in $XDG_DATA_HOME/bash_completion/*; do
38 [[ -f "$i" && -r "$i" ]] && . "$i"
39 done
40fi
41
36{% if role.get(profile) == "fretlink" %} 42{% if role.get(profile) == "fretlink" %}
37##### Some Fretlink aliases 43##### Some Fretlink aliases
38alias getDump='s3cmd -c <(pass show Travail/Fretlink/S3) get ' 44alias vpn=fl_vpn
39 45alias tmux_dev=fl_tmux_dev
40function vpn() { 46complete -o filenames -F _fl_tmux_dev tmux_dev
41 TMPFILE=$(mktemp /tmp/openvpn.XXXXXX)
42 pass show Travail/Fretlink/OpenVPN >> $TMPFILE
43 sudo openvpn $TMPFILE
44 rm -f $TMPFILE
45}
46 47
47function dev_prompt() { 48function dev_prompt() {
48 if [ -n "$FRETLINK_ENV" ]; then 49 if [ -n "$FRETLINK_ENV" ]; then
@@ -50,56 +51,6 @@ function dev_prompt() {
50 fi 51 fi
51} 52}
52 53
53function tmux_dev() {
54 type="${1:-bash}"
55 if [ -n "$TMUX" ]; then
56 m=switch-client
57 else
58 m=attach-session
59 fi
60
61 case "$type" in
62 "bash") start_dir="$HOME";;
63 "remote") start_dir="$HOME";;
64 "puppet") start_dir="/etc/puppetlabs/code"
65 esac
66
67 if tmux has-session -t "$type" 2>/dev/null; then
68 tmux $m -t "$type"
69 else
70 if [ "$type" = "remote" ]; then
71 tmux new-session -d -c $start_dir -s "$type" mosh immae.eu \; \
72 $m -t "$type"
73 elif [ -n "$start_dir" ]; then
74 tmux new-session -d -c $start_dir -s "$type" \; \
75 $m -t "$type" \; \
76 new-window -c $start_dir
77 elif [ -d "$HOME/workdir/$type" ]; then
78 tmux new-session -d -c "$HOME/workdir/$type" -s "$type" \; \
79 $m -t "$type" \; \
80 send-keys "../start" C-m \; \
81 rename-window "running" \; \
82 new-window -c "$HOME/workdir/$type"
83 else
84 echo "Unknown session" >&2
85 false
86 fi
87 fi
88}
89
90_tmux_dev() {
91 COMPREPLY=()
92 local cur="${COMP_WORDS[COMP_CWORD]}"
93 prefix="$HOME/workdir/"
94 local IFS=$'\n'
95 local items=($(IFS=' ' compgen -W "bash remote puppet" -- $cur) $(compgen -d $prefix$cur))
96 for item in ${items[@]}; do
97 [[ $item == $prefix.* ]] && continue
98 COMPREPLY+=("${item#$prefix}")
99 done
100}
101complete -o filenames -F _tmux_dev tmux_dev
102
103if [ -n "$TMUX" ]; then 54if [ -n "$TMUX" ]; then
104 TMUX_SESSION_NAME=$(tmux display-message -p "#S") 55 TMUX_SESSION_NAME=$(tmux display-message -p "#S")
105 export HISTFILE="$XDG_STATE_HOME/bash/tmux_${TMUX_SESSION_NAME}_history" 56 export HISTFILE="$XDG_STATE_HOME/bash/tmux_${TMUX_SESSION_NAME}_history"
diff --git a/roles/tools/templates/tmux.conf.j2 b/roles/tools/templates/tmux.conf.j2
index 0313336..07e88b9 100644
--- a/roles/tools/templates/tmux.conf.j2
+++ b/roles/tools/templates/tmux.conf.j2
@@ -37,7 +37,7 @@ bind-key -T off F12 set-option -u prefix \; set-option -u key-table \; set-optio
37bind-key -T off C-M-PageDown switch-client -n 37bind-key -T off C-M-PageDown switch-client -n
38bind-key -T off C-M-PageUp switch-client -p 38bind-key -T off C-M-PageUp switch-client -p
39 39
40bind-key Tab command-prompt -p "which session?" "run-shell \"bash -i -c 'tmux_dev %1'\"" 40bind-key Tab command-prompt -p "which session?" "run-shell \"fl_tmux_dev %1\""
41 41
42# même hack que sur screen lorsqu'on veut profiter du scroll du terminal 42# même hack que sur screen lorsqu'on veut profiter du scroll du terminal
43# (xterm ...) 43# (xterm ...)