From: a-wing <1@233.email> Date: Mon, 17 May 2021 14:27:51 +0000 (+0800) Subject: zshrc: change sudo-command-line switch 'sudo' X-Git-Tag: v0.19.0~2^2~1 X-Git-Url: http://git.grml.org/?p=grml-etc-core.git;a=commitdiff_plain;h=e7927a8e2a3600fbf33cdb70aa53ebdb988af275 zshrc: change sudo-command-line switch 'sudo' fix add 'sudo' plugin zsh-syntax-highlighting error --- diff --git a/etc/zsh/zshrc b/etc/zsh/zshrc index 5a74fee..38571fd 100644 --- a/etc/zsh/zshrc +++ b/etc/zsh/zshrc @@ -1200,10 +1200,15 @@ zle -N grml-zsh-fg # run command line as user root via sudo: function sudo-command-line () { [[ -z $BUFFER ]] && zle up-history - if [[ $BUFFER != sudo\ * ]]; then - BUFFER="sudo $BUFFER" - CURSOR=$(( CURSOR+5 )) + local cmd="sudo " + if [[ ${BUFFER:0:${#cmd}} == ${cmd} ]]; then + CURSOR=$(( CURSOR-${#cmd} )) + BUFFER="${BUFFER:${#cmd}}" + else + BUFFER="${cmd}${BUFFER}" + CURSOR=$(( CURSOR+${#cmd} )) fi + zle reset-prompt } zle -N sudo-command-line