From d933bb45c35014bf6427bbf1878333901af94989 Mon Sep 17 00:00:00 2001 From: Ira Abramov Date: Wed, 20 Nov 2024 00:01:06 +0200 Subject: [PATCH] fixing plugins/available/sudo.plugin.bash --- clean_files.txt | 1 + plugins/available/sudo.plugin.bash | 23 ++++++++++++----------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/clean_files.txt b/clean_files.txt index 62d2762da5..011cb9b8ab 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -130,6 +130,7 @@ plugins/available/pyenv.plugin.bash plugins/available/python.plugin.bash plugins/available/rbenv.plugin.bash plugins/available/ruby.plugin.bash +plugins/available/sudo.plugin.bash plugins/available/textmate.plugin.bash plugins/available/thefuck.plugin.bash plugins/available/todo.plugin.bash diff --git a/plugins/available/sudo.plugin.bash b/plugins/available/sudo.plugin.bash index eb155daa04..6451eb74c1 100644 --- a/plugins/available/sudo.plugin.bash +++ b/plugins/available/sudo.plugin.bash @@ -1,22 +1,23 @@ +# shellcheck shell=bash cite about-plugin about-plugin 'Toggle sudo at the beginning of the current or the previous command by hitting the ESC key twice' function sudo-command-line() { - about "toggle sudo at the beginning of the current or the previous command by hitting the ESC key twice" - group "sudo" + about "toggle sudo at the beginning of the current or the previous command by hitting the ESC key twice" + group "sudo" - [[ ${#READLINE_LINE} -eq 0 ]] && READLINE_LINE=$(fc -l -n -1 | xargs) - if [[ $READLINE_LINE == sudo\ * ]]; then - READLINE_LINE="${READLINE_LINE#sudo }" - else - READLINE_LINE="sudo $READLINE_LINE" - fi - READLINE_POINT=${#READLINE_LINE} + [[ ${#READLINE_LINE} -eq 0 ]] && READLINE_LINE=$(fc -l -n -1 | xargs) + if [[ $READLINE_LINE == sudo\ * ]]; then + READLINE_LINE="${READLINE_LINE#sudo }" + else + READLINE_LINE="sudo $READLINE_LINE" + fi + READLINE_POINT=${#READLINE_LINE} } # Define shortcut keys: [Esc] [Esc] # Readline library requires bash version 4 or later -if [ "${BASH_VERSINFO}" -ge 4 ]; then - bind -x '"\e\e": sudo-command-line' +if [ "${BASH_VERSINFO[0]}" -ge 4 ]; then + bind -x '"\e\e": sudo-command-line' fi