cmderdev / cmder

Lovely console emulator package for Windows
https://cmder.app
MIT License
25.74k stars 2.02k forks source link

Autocompletion for .ssh/config in bash #2869

Open anutator opened 11 months ago

anutator commented 11 months ago

Version Information

Cmder version: 1.3.24.236
Operating system: Windows 11

Cmder Edition

Cmder Full (with Git)

Description of the issue

I have many connections configured in .ssh/config When I use cmd::Cmder type of terminal autocompletions works, I print ssh, press Tab and see all names of connections. But if I use bash::bash type of terminal, Tab shows folders in current folder:

λ ssh
bin/                config/             LICENSE             vendor/
Cmder.exe           icons/              opt/                Version 1.3.24.236

My environment settings:

set PATH=%ConEmuBaseDir%\Scripts;%PATH%
set LC_ALL=ru_RU.UTF-8
set LANG=ru_RU.UTF-8
set GH=C:\Users\besta\Downloads\cmder\vendor\git-for-windows
set PATH=%GH%\bin;%GH%\usr\bin;%GH%\mingw64\bin;%PATH

How to reproduce

Add any connections to .ssh/config in home directory.

Additional context

No response

Checklist

chrisant996 commented 11 months ago

Cmder comes with a small collection of completion scripts for the cmd shell. Cmder does not come with completion scripts for bash.

The scop/bash-completion repo contains a large collection of completion scripts for bash. Directions for installing it are here.

daxgames commented 11 months ago

@anutator I am sorry I thought I responded to this yesterday but I guess I never hit the Comment button.

While the instructions @chrisant996 pointed at may work for Cmder, I would recommend another approach for install in Cmder if you want to:

  1. Not have reconfigure this EVERY time you update Cmder to a new version. (Depending on how you do it.)
  2. Maintain the portability of Cmder.

or adapt those instructions using the info here. I just do not recommend putting the files inside the $cmder_root/vendor/git-for-windows folder.

daxgames commented 11 months ago

@anutator to specifically answer your question this is what I did:

296951@DESKTOP-V3893H0 ~
λ cd $cmder_root/

296951@DESKTOP-V3893H0 ~/cmderdev (more_speed_2)
λ cat config/profile.d/bash-completion.sh
. $cmder_root/config/bash-completion/scp
. $cmder_root/config/bash-completion/ssh

296951@DESKTOP-V3893H0 ~/cmderdev (more_speed_2)
λ cat config/bash-completion/*
_scp()
{
  local cur prev opts
    COMPREPLY=()
    cur="${COMP_WORDS[COMP_CWORD]}"
    prev="${COMP_WORDS[COMP_CWORD-1]}"
    opts=$(grep '^Host' ~/.ssh/config ~/.ssh/config.d/* 2>/dev/null | grep -v '[?*]' | cut -d ' ' -f 2-)

    COMPREPLY=( $(compgen -W "$opts" -- ${cur}): )
    return 0
}
complete -F _scp -o nospace scp

_ssh()
{
        local cur prev opts
        COMPREPLY=()
        cur="${COMP_WORDS[COMP_CWORD]}"
        prev="${COMP_WORDS[COMP_CWORD-1]}"
        opts=$(grep '^Host' ~/.ssh/config ~/.ssh/config.d/* 2>/dev/null | grep -v '[?*]' | cut -d ' ' -f 2-)

        COMPREPLY=( $(compgen -W "$opts" -- ${cur}) )
        return 0
}
complete -F _ssh ssh