diff options
-rw-r--r-- | roles/contexts/fretlink/files/scripts/_fl_tmux_dev | 14 | ||||
-rw-r--r-- | roles/contexts/fretlink/files/scripts/fl_getDump | 3 | ||||
-rw-r--r-- | roles/contexts/fretlink/files/scripts/fl_tmux_dev | 36 | ||||
-rw-r--r-- | roles/contexts/fretlink/files/scripts/fl_vpn | 8 | ||||
-rw-r--r-- | roles/contexts/fretlink/tasks/main.yml | 21 | ||||
-rw-r--r-- | roles/shell/bash/templates/bashrc.j2 | 67 | ||||
-rw-r--r-- | roles/tools/templates/tmux.conf.j2 | 2 |
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 | } | ||
14 | complete -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 | |||
3 | s3cmd -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 | |||
3 | type="${1:-bash}" | ||
4 | if [ -n "$TMUX" ]; then | ||
5 | m=switch-client | ||
6 | else | ||
7 | m=attach-session | ||
8 | fi | ||
9 | |||
10 | case "$type" in | ||
11 | "bash") start_dir="$HOME";; | ||
12 | "remote") start_dir="$HOME";; | ||
13 | "puppet") start_dir="/etc/puppetlabs/code" | ||
14 | esac | ||
15 | |||
16 | if tmux has-session -t "$type" 2>/dev/null; then | ||
17 | tmux $m -t "$type" | ||
18 | else | ||
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 | ||
36 | fi | ||
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 | |||
3 | TMPFILE=$(mktemp /tmp/openvpn.XXXXXX) | ||
4 | |||
5 | trap "rm -f $TMPFILE" EXIT | ||
6 | |||
7 | pass show Travail/Fretlink/OpenVPN >> $TMPFILE | ||
8 | sudo 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 | ||
36 | if [[ -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 | ||
40 | fi | ||
41 | |||
36 | {% if role.get(profile) == "fretlink" %} | 42 | {% if role.get(profile) == "fretlink" %} |
37 | ##### Some Fretlink aliases | 43 | ##### Some Fretlink aliases |
38 | alias getDump='s3cmd -c <(pass show Travail/Fretlink/S3) get ' | 44 | alias vpn=fl_vpn |
39 | 45 | alias tmux_dev=fl_tmux_dev | |
40 | function vpn() { | 46 | complete -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 | ||
47 | function dev_prompt() { | 48 | function 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 | ||
53 | function 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 | } | ||
101 | complete -o filenames -F _tmux_dev tmux_dev | ||
102 | |||
103 | if [ -n "$TMUX" ]; then | 54 | if [ -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 | |||
37 | bind-key -T off C-M-PageDown switch-client -n | 37 | bind-key -T off C-M-PageDown switch-client -n |
38 | bind-key -T off C-M-PageUp switch-client -p | 38 | bind-key -T off C-M-PageUp switch-client -p |
39 | 39 | ||
40 | bind-key Tab command-prompt -p "which session?" "run-shell \"bash -i -c 'tmux_dev %1'\"" | 40 | bind-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 ...) |