Opened 10 years ago

Closed 9 years ago

#46019 closed defect (fixed)

Bash completion fails when in tmux or screen

Reported by: Tatsh (Andrew Udvare) Owned by: raimue (Rainer Müller)
Priority: Normal Milestone:
Component: ports Version: 2.3.3
Keywords: Cc:
Port: bash-completion

Description

Using Terminal.app, bash-completion works without using tmux. I have . /opt/local/etc/profile.d/bash_completion.sh in ~/.bashrc. Terminal.app shell is set to /opt/local/bin/bash -l and I have Bash installed from MacPorts.

When I run screen or tmux, Bash completion stops working. Tried with no ~/.tmux.conf and same effect. I do not have an rc for screen.

Steps to reproduce:

  1. port install bash coreutils tmux bash-completion
  2. . /opt/local/etc/profile.d/bash_completion.sh
  3. Be sure ls --<tab> works
  4. tmux
  5. Try ls --<tab>

Attachments (2)

bashrc (5.0 KB) - added by Tatsh (Andrew Udvare) 10 years ago.
tmux.conf (634 bytes) - added by Tatsh (Andrew Udvare) 10 years ago.

Download all attachments as: .zip

Change History (11)

Changed 10 years ago by Tatsh (Andrew Udvare)

Attachment: bashrc added

Changed 10 years ago by Tatsh (Andrew Udvare)

Attachment: tmux.conf added

comment:1 Changed 10 years ago by larryv (Lawrence Velázquez)

Cc: raimue@… removed
Owner: changed from macports-tickets@… to raimue@…
Port: bash-completion added

comment:2 Changed 10 years ago by Tatsh (Andrew Udvare)

So it appears tmux and screen are invoking Bash differently, or a different (the system Bash?).

If I use this:

sudo dscl . -change /Users/tatsh UserShell /bin/bash /opt/local/bin/bash

I get what I want. However, I am not so sure this is really a good idea. If I need to re-build completely, at some point I may lose a working shell and I am not sure if OS X is just going to default to another one.

comment:3 Changed 10 years ago by Tatsh (Andrew Udvare)

I'm semi-okay with the 'fix' for now an decided to change my shell using the dscl command. However, if there is a cleaner way to do this (and not symlinking /bin/bash to MacPorts' version), I am all ears.

comment:4 in reply to:  3 Changed 10 years ago by larryv (Lawrence Velázquez)

OS X would not default to another shell, but it wouldn’t roll over and die, either. It’s trivial to change your Terminal settings to point to a different shell, or to run a shell using Shell > New Command….

If you’re still not comfortable with this for some reason, you can set default-shell in your .tmux.conf to whatever you please.

comment:5 Changed 10 years ago by neverpanic (Clemens Lang)

No need to go all dscl on this; the chsh utility does the same job without fiddling with directory services internals.

To find out whether you're getting the system bash, use echo $BASH_VERSION. If it's 3.x, that's your explanation for non-functional bash completion.

I assume tmux and screen just invoke the login binary to start a session and a shell, and that starts whatever the user's default shell is, which is why you're seeing this behaviour. You might be able to change that if you configure screen or tmux to not use the login command but rather start a shell directly.

comment:6 Changed 10 years ago by raimue (Rainer Müller)

tmux uses various ways to determine the shell to start, see the tmux(1) man page at the description of the default-shell option.

However, also note your .bashrc will never be read by a login shell, as bash executed as a login shell only evaluates .bash_profile. It is up to your own configuration to either source .bashrc from within .bash_profile, or copy the same instructions you currently use in your .bashrc also to your .bash_profile. This is explained in detail in the section INVOCATION in the bash(1) man page.

Unfortunately, I don't think there is much we can do about these peculiarities. Explaining all that in a note of the port would be too much information for most users. Maybe we could add some bits about default-shell for tmux in the additional documentation at howto/bash-completion and link to that from the notes.

comment:7 Changed 10 years ago by Tatsh (Andrew Udvare)

I opted to use tmux's default-shell option and that works for me.

I was going to say that having a message to change the shell or noting that some changes are necessary to the port notice but updating the Wiki is good too (default-shell, chsh, etc). Resolution to this ticket, to me, is documentation. I do not know if screen has an equivalent to default-shell, or any others.

comment:8 Changed 10 years ago by raimue (Rainer Müller)

For screen, you need to set shell /opt/local/bin/bash in your .screenrc. Or export SHELL=/opt/local/bin/bash in the environment, which is respected by both tmux and screen.

comment:9 Changed 9 years ago by raimue (Rainer Müller)

Resolution: fixed
Status: newclosed
Note: See TracTickets for help on using tickets.