From 801e514d781ae98d97bcbc6177c22ab39a83f816 Mon Sep 17 00:00:00 2001 From: Matthias Kretschmann Date: Fri, 25 Oct 2019 00:38:46 +0200 Subject: [PATCH] zsh ssh completion --- bin/install-brew.sh | 2 -- bin/install.sh | 5 +---- bin/update-dotfiles.sh | 7 ------- exports | 8 +------- zshrc | 42 ++++++++++++++++++++++++++---------------- 5 files changed, 28 insertions(+), 36 deletions(-) diff --git a/bin/install-brew.sh b/bin/install-brew.sh index 0f0499b..7428464 100755 --- a/bin/install-brew.sh +++ b/bin/install-brew.sh @@ -23,14 +23,12 @@ brew install \ wget \ gpg \ nvm \ - pandoc \ pinentry-mac \ openssl \ tor \ python \ rclone \ rsync \ - ruby \ shellcheck \ ipfs \ clamav diff --git a/bin/install.sh b/bin/install.sh index c07410b..eacb87d 100755 --- a/bin/install.sh +++ b/bin/install.sh @@ -51,7 +51,7 @@ echo "$(tput setaf 64)---------------------------------------------" echo " ✓ done$(tput sgr0)" # ---------------------------------------------------------------------- -# source what we just created +# Prompt # ---------------------------------------------------------------------- # Switch to using brew-installed zsh as default shell @@ -62,9 +62,6 @@ fi; npm i -g pure-prompt -# shellcheck source=/dev/null -source "$HOME/.zshrc" - echo "$(tput setaf 64)=============================================" echo " ✓ all done" echo "=============================================$(tput sgr0)" diff --git a/bin/update-dotfiles.sh b/bin/update-dotfiles.sh index 988f3bb..7d8124f 100755 --- a/bin/update-dotfiles.sh +++ b/bin/update-dotfiles.sh @@ -24,11 +24,4 @@ for FILE in $FILES; do done -# ---------------------------------------------------------------------- -# source what we just created -# ---------------------------------------------------------------------- - -# shellcheck source=/dev/null -source "$HOME/.zshrc" - exit diff --git a/exports b/exports index e2ce6b8..ac3b72f 100644 --- a/exports +++ b/exports @@ -6,7 +6,6 @@ export ARCHFLAGS="-arch x86_64" # Prefer US English and use UTF-8 export LC_ALL="en_US.UTF-8" export LANG="en_US" -#!/usr/bin/env bash # --------------------------------------------------- # PATH @@ -32,17 +31,12 @@ NODE_GLOBALS+=("nvm") load_nvm () { export NVM_DIR="$HOME/.nvm" - [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" + [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" } for cmd in "${NODE_GLOBALS[@]}"; do eval "${cmd}(){ unset -f ${NODE_GLOBALS}; load_nvm; ${cmd} \$@ }" done -# ---- -# if [ -s "$HOME/.nvm" ]; then -# export NVM_DIR="$HOME/.nvm" -# [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm -# fi # pip should only run if there is a virtualenv currently activated #export PIP_REQUIRE_VIRTUALENV=true diff --git a/zshrc b/zshrc index b5d1f91..670194e 100644 --- a/zshrc +++ b/zshrc @@ -6,20 +6,6 @@ PURE_GIT_DOWN_ARROW=↓ PURE_GIT_UP_ARROW=↑ prompt pure -# https://gist.github.com/ctechols/ca1035271ad134841284#gistcomment-2767420 -autoload -Uz compinit - -setopt EXTENDEDGLOB -for dump in $ZSH_COMPDUMP(#qN.m1); do - compinit - if [[ -s "$dump" && (! -s "$dump.zwc" || "$dump" -nt "$dump.zwc") ]]; then - zcompile "$dump" - fi - echo "Initializing Completions..." -done -unsetopt EXTENDEDGLOB -compinit -C - CASE_SENSITIVE="true" DISABLE_UPDATE_PROMPT="true" DISABLE_AUTO_TITLE="true" @@ -53,9 +39,32 @@ zstyle ':completion:*:*:*:*:*' menu select zstyle ':completion:*' matcher-list 'm:{a-zA-Z-_}={A-Za-z_-}' 'r:|=*' 'l:|=* r:|=*' zstyle ':completion::complete:*' use-cache 1 zstyle ':completion::complete:*' cache-path $ZSH_CACHE_DIR -zstyle ':completion:*' list-colors '' zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#) ([0-9a-z-]#)*=01;34=0=01' +# Highlight the current autocomplete option +zstyle ':completion:*' list-colors "${(s.:.)LS_COLORS}" + +# Better SSH/SCP/Rsync Autocomplete +h=() +if [[ -r ~/.ssh/config ]]; then + h=($h ${${${(@M)${(f)"$(cat ~/.ssh/config)"}:#Host *}#Host }:#*[*?]*}) +fi +if [[ -r ~/.ssh/known_hosts ]]; then + h=($h ${${${(f)"$(cat ~/.ssh/known_hosts{,2} || true)"}%%\ *}%%,*}) 2>/dev/null +fi +if [[ $#h -gt 0 ]]; then + zstyle ':completion:*:(ssh|scp|rsync|slogin):*' hosts $h +fi + +# https://gist.github.com/ctechols/ca1035271ad134841284#gistcomment-2767420 +autoload -Uz compinit +if [[ -n ~/.zcompdump(#qN.mh+24) ]]; then + compinit + touch ~/.zcompdump +else + compinit -C +fi + # Other setopt prompt_subst @@ -65,5 +74,6 @@ source ~/.aliases source ~/.private source /usr/local/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh source /usr/local/share/zsh-autosuggestions/zsh-autosuggestions.zsh +source <(kubectl completion zsh) -# zprof \ No newline at end of file +# zprof