From fb7c8c4064bbeb6153d5157471b874539ecca24e Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Fri, 26 Mar 2021 19:02:20 +0100 Subject: [PATCH] __fish_prepend_sudo: First insert history and then *toggle* Previously this would only ever insert sudo if it took a commandline from history, not remove it. So you would end up with sudo sudo apt install --- share/functions/__fish_prepend_sudo.fish | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/share/functions/__fish_prepend_sudo.fish b/share/functions/__fish_prepend_sudo.fish index c348d25f8..f514766df 100644 --- a/share/functions/__fish_prepend_sudo.fish +++ b/share/functions/__fish_prepend_sudo.fish @@ -1,9 +1,14 @@ function __fish_prepend_sudo -d "Prepend 'sudo ' to the beginning of the current commandline" + # If there is no commandline, insert the last item from history + # and *then* toggle + if not commandline | string length -q + commandline -r "$history[1]" + end + set -l cmd (commandline -po) set -l cursor (commandline -C) - if test -z "$cmd" - commandline -r "sudo $history[1]" - else if test "$cmd[1]" != sudo + + if test "$cmd[1]" != sudo commandline -C 0 commandline -i "sudo " commandline -C (math $cursor + 5)