mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2026-02-13 03:01:32 +01:00
Preserve cursor position when prepending sudo.
This commit is contained in:
parent
4ce7f0a37f
commit
714091279f
1 changed files with 13 additions and 4 deletions
|
|
@ -2,20 +2,29 @@
|
|||
# Description
|
||||
# -----------
|
||||
#
|
||||
# sudo will be inserted before the command
|
||||
# sudo will be inserted before the command and the cursor position will be
|
||||
# preserved. If the prompt is empty, the previously executed command will be
|
||||
# fetched from the history and prepended with "sudo ".
|
||||
#
|
||||
# ------------------------------------------------------------------------------
|
||||
# Authors
|
||||
# -------
|
||||
#
|
||||
# * Dongweiming <ciici123@gmail.com>
|
||||
# * Michael Fladischer <FladischerMichael@fladi.at>
|
||||
#
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
sudo_preserve_cursor=1
|
||||
|
||||
sudo-command-line() {
|
||||
[[ -z $BUFFER ]] && zle up-history
|
||||
[[ $BUFFER != sudo\ * ]] && BUFFER="sudo $BUFFER"
|
||||
zle end-of-line
|
||||
[[ -z $BUFFER ]] && zle up-history
|
||||
if [[ $sudo_preserve_cursor -eq 1 ]]; then
|
||||
[[ $LBUFFER != sudo\ * ]] && LBUFFER="sudo $LBUFFER"
|
||||
else
|
||||
[[ $BUFFER != sudo\ * ]] && BUFFER="sudo $BUFFER"
|
||||
zle end-of-line
|
||||
fi
|
||||
}
|
||||
zle -N sudo-command-line
|
||||
# Defined shortcut keys: [Esc] [Esc]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue