[GTALUG] SSH Host tab completion

Scott Sullivan scott at revident.net
Sun Jun 2 23:37:03 EDT 2019


I suspect you have indeed run into the difference between:

Interactive Login shell
Interactive Non-Login shell
Non-Interactive Login shell
Non-Interactive Non-Login shell

.bashrc is called in almost all cases, .bash_profile only in some and 
bash completions likely only in some. TMUX is lunching another shell 
that may be non-login shell / non-interactive. So the question is why 
load completions, if it's not a person the shell is responding to.

When I was learning about this I started adding checks like these:

***

# .bashrc
if [[ $- = *i* ]]; then
         echo 'Interactivity!'
fi

if shopt -q login_shell ; then
        echo 'Logged In!'
fi

***

# .bash_profile
echo ".bash_profile executed!"

***

https://unix.stackexchange.com/questions/38175/difference-between-login-shell-and-non-login-shell/46856#46856


On 5/31/19 4:54 PM, Giles Orr via talk wrote:
> I've had a very similar problem with ssh host tab completion - the 
> primary difference seemed to be that it worked on Mac and not on Linux.  
> (I never use console these days, so I couldn't tell you about that.)  I 
> solved it as you did - by a more specific call to the completion file(s) 
> in by bashrc.  Although I think I sourced the one specifically for SSH 
> hosts.
> 
> I can't remember if it was here (ie. TLUG) or somewhere else that I saw 
> a conversation about the incredibly tortuous routing of Bash startup.  
> It was months or even a couple years ago.  Essentially, someone had 
> attempted to map out the decision process behind what files got parsed 
> when Bash started depending on all the little check-boxes: is it 
> interactive, is it console, is it login, dozens of others.  The flow 
> chart created was enough to make a hardened system administrator cry.  
> So the direct route - add what you want to the bashrc - is definitely 
> preferred to trying to actually debug what happened.
> 
> On Fri, 31 May 2019 at 11:02, Daniel Wayne Armstrong via talk 
> <talk at gtalug.org <mailto:talk at gtalug.org>> wrote:
> 
>     Resolved the issue by adding ...
> 
>     source /etc/profile.d/bash_completion.sh
> 
>     ... to my ~/.bashrc, though I still don't know why it would
>     auto-complete OK inside tmux.
> 
>     On Thu, May 30, 2019 at 4:24 PM Daniel Wayne Armstrong
>     <daniel at circuidipity.com <mailto:daniel at circuidipity.com>> wrote:
> 
>         Hello all ... I am currently running Debian Buster and Bash
>         shell. I have a few Host aliases defined in my ~/.ssh/config.
>         Example: Host test-server. So when, in console, I type ...
> 
>         $ ssh tes
> 
>         ... and hit Tab, then auto-completion fills out ...
> 
>         $ ssh test-server
> 
>         When I try to do the same thing in a terminal (urxvt), tab
>         completion does *not* work. The complete host alias has to be
>         entered.
> 
>         *But* tab completion for ssh host aliases *does* work if entered
>         within tmux running in the terminal.
> 
>         Any idea how I can get tab completion working for ssh host
>         aliases in the terminal?
> 
>         -- 
>         Daniel Wayne Armstrong https://www.circuidipity.com
>         <http://www.circuidipity.com>
>         Accomplish the great task by a series of small acts. -- Lao Tzu
> 
> 
> 
>     -- 
>     Daniel Wayne Armstrong https://www.circuidipity.com
>     <http://www.circuidipity.com>
>     Accomplish the great task by a series of small acts. -- Lao Tzu
> 
>     ---
>     Talk Mailing List
>     talk at gtalug.org <mailto:talk at gtalug.org>
>     https://gtalug.org/mailman/listinfo/talk
> 
> 
> 
> -- 
> Giles
> https://www.gilesorr.com/
> gilesorr at gmail.com <mailto:gilesorr at gmail.com>
> 
> ---
> Talk Mailing List
> talk at gtalug.org
> https://gtalug.org/mailman/listinfo/talk
> 


-- 
Scott Sullivan


More information about the talk mailing list