Skip to content

Commit

Permalink
Run tmux only right after sshd/login
Browse files Browse the repository at this point in the history
This prevents tmux-inside-tmux for common use cases like `su -'.

Signed-off-by: Jiri Jaburek <jjaburek@redhat.com>
  • Loading branch information
Jiri Jaburek committed Oct 3, 2019
1 parent c71298a commit 92a9936
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
# platform = multi_platform_fedora,Red Hat Enterprise Linux 8,Oracle Linux 8

LINE='[ -n "$PS1" -a -z "$TMUX" ] && exec tmux'
if ! tail -1 /etc/bashrc | grep -x "$LINE" ; then
echo "$LINE" >> /etc/bashrc
if ! grep -x ' case "$name" in sshd|login) exec tmux ;; esac' /etc/bashrc; then
cat >> /etc/bashrc <<'EOF'
if [ "$PS1" ]; then
parent=$(ps -o ppid= -p $$)
name=$(ps -o comm= -p $parent)
case "$name" in sshd|login) exec tmux ;; esac
fi
EOF
fi

Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
<ind:textfilecontent54_object id="obj_configure_bashrc_exec_tmux" version="1">
<ind:behaviors singleline="true" multiline="false" />
<ind:filepath>/etc/bashrc</ind:filepath>
<ind:pattern operation="pattern match">([^\n]+)\s*$</ind:pattern>
<ind:pattern operation="pattern match">^(.*)$</ind:pattern>
<ind:instance datatype="int">1</ind:instance>
</ind:textfilecontent54_object>
<ind:textfilecontent54_state id="state_configure_bashrc_exec_tmux" version="1">
<ind:subexpression datatype="string" operation="equals">[ -n "$PS1" -a -z "$TMUX" ] &amp;&amp; exec tmux</ind:subexpression>
<ind:subexpression datatype="string" operation="pattern match">if \[ "\$PS1" \]; then\n\s+parent=\$\(ps -o ppid= -p \$\$\)\n\s+name=\$\(ps -o comm= -p \$parent\)\n\s+case "\$name" in sshd\|login\) exec tmux ;; esac\nfi</ind:subexpression>
</ind:textfilecontent54_state>
</def-group>
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,12 @@ ocil_clause: 'exec tmux is not present at the end of bashrc'
ocil: |-
To verify that tmux is configured to execute,
run the following command:
<pre>$ tail -1 /etc/bashrc</pre>
<pre>$ grep -A1 -B3 "case ..name. in sshd|login) exec tmux ;; esac" /etc/bashrc</pre>
The output should return the following:
<pre>[ -n "$PS1" -a -z "$TMUX" ] &amp;&amp; exec tmux</pre>
<pre>if [ "$PS1" ]; then
parent=$(ps -o ppid= -p $$)
name=$(ps -o comm= -p $parent)
case "$name" in sshd|login) exec tmux ;; esac
fi</pre>
platform: machine

0 comments on commit 92a9936

Please sign in to comment.