From 16c95b28866bb2634902dbbc8bdc22eb169a0961 Mon Sep 17 00:00:00 2001 From: meliurwen Date: Mon, 22 Aug 2022 17:07:35 +0200 Subject: [PATCH] zshrc: in colored manpages replaced subshells containing builtin printf with the actual strings --- zsh/.zshrc | 38 +++++++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/zsh/.zshrc b/zsh/.zshrc index 7e9ab54..ebca35b 100644 --- a/zsh/.zshrc +++ b/zsh/.zshrc @@ -135,19 +135,43 @@ zstyle ':completion:*:*:*:users' ignored-patterns \ # ... unless we really want to. zstyle '*' single-ignored show +# ssh/mosh completion +# source: https://serverfault.com/a/170481 +# ~/.ssh/known_hosts is disabled because hashed by default +# Tip to unhash it: https://unix.stackexchange.com/a/175199 +# TODO: handle case in ~/.ssh/config where `Host` has multiple entries +h=() +if [ -r ~/.ssh/config ]; then + h=($h ${${${(@M)${(f)"$(< ~/.ssh/config)"}:#Host *}#Host }:#*[*?]*}) +fi +if [ "$ZSH_THEME_SSH_KHOSTS" = "true" ] && [ -r ~/.ssh/known_hosts ]; then + h=($h ${${${(f)"$(< ~/.ssh/known_hosts{,2} || true)"}%%\ *}%%,*}) 2>/dev/null +fi +if [ $#h -gt 0 ]; then + zstyle ':completion:*:ssh:*' hosts $h + zstyle ':completion:*:slogin:*' hosts $h + zstyle ':completion:*:mosh:*' hosts $h + #zstyle ':completion:*:sftp:*' hosts $h +fi +unset h + # automatically load bash completion functions autoload -U +X bashcompinit && bashcompinit # Colored manpages +# See: +# - https://boredzo.org/blog/archives/2016-08-15/colorized-man-pages-understood-and-customized +# - https://unix.stackexchange.com/a/600214 +# Careful with "" char, it may appear as "^[" in some text editors! man() { env \ - LESS_TERMCAP_mb=$(printf "\e[1;31m") \ - LESS_TERMCAP_md=$(printf "\e[1;31m") \ - LESS_TERMCAP_me=$(printf "\e[0m") \ - LESS_TERMCAP_se=$(printf "\e[0m") \ - LESS_TERMCAP_so=$(printf "\e[45;93m") \ - LESS_TERMCAP_ue=$(printf "\e[0m") \ - LESS_TERMCAP_us=$(printf "\e[4;93m") \ + LESS_TERMCAP_mb="" \ + LESS_TERMCAP_md="" \ + LESS_TERMCAP_me="" \ + LESS_TERMCAP_se="" \ + LESS_TERMCAP_so="" \ + LESS_TERMCAP_ue="" \ + LESS_TERMCAP_us="" \ man "$@" }