Skip to content

Instantly share code, notes, and snippets.

@LewisGet
Last active August 19, 2025 12:53
Show Gist options
  • Save LewisGet/bcde5beae47119c8ea42caf20b82bfc3 to your computer and use it in GitHub Desktop.
Save LewisGet/bcde5beae47119c8ea42caf20b82bfc3 to your computer and use it in GitHub Desktop.
# 懶得裝 zsh 跟整套 oh my 時,塞上去 bash 版本
_my_ssh_autocomplete() {
local cur=${COMP_WORDS[COMP_CWORD]}
if [[ $cur =~ ^[0-9]{1,3}$ ]]; then
local full_ip="[email protected].${cur}"
COMPREPLY=( $(compgen -W "$full_ip" -- "$cur") )
fi
}
complete -F _my_ssh_autocomplete ssh
# zsh 自動完成註冊方法不同,直接放到 oh my zsh custom 內就好
_my_ssh_complete() {
local cur=${words[CURRENT]}
local -a completions
if [[ $cur =~ ^[0-9]{1,3}$ ]]; then
completions=( "[email protected].${cur}" )
fi
_describe 'ssh completions' completions
}
compdef _my_ssh_complete ssh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment