Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autocompletion for .ssh/config in bash #2869

Open
4 tasks done
anutator opened this issue Aug 23, 2023 · 3 comments
Open
4 tasks done

Autocompletion for .ssh/config in bash #2869

anutator opened this issue Aug 23, 2023 · 3 comments

Comments

@anutator
Copy link

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

  • I have read the documentation.
  • I have searched for similar issues and found none that describe my issue.
  • I have reproduced the issue on the latest version of Cmder.
  • I am certain my issues are not related to ConEmu, Clink, or other third-party tools that Cmder uses.
@chrisant996
Copy link
Contributor

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
Copy link
Member

daxgames commented Aug 24, 2023

@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.
  • Add any bash auto completion files to a folder called $cmder_root/config/bash-completion that you create.

  • Create a file $cmder_root/config/profile.d/bash-completion.sh and source the files you want to use in this file.

    . $cmder_root/config/bash-completion/ssh
    . $cmder_root/config/bash-completion/scp
    

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
Copy link
Member

daxgames commented Aug 24, 2023

@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

@DRSDavidSoft DRSDavidSoft changed the title autocomplition for .ssh/config in bash Autocompletion for .ssh/config in bash Aug 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants