From c39da95aec1a30a89c3e7b2fd8f160392cea2aa5 Mon Sep 17 00:00:00 2001 From: Pekka Helenius Date: Wed, 10 Oct 2018 19:21:10 +0300 Subject: [PATCH] bash.custom: do not hang if command returns stderr --- bash.custom | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/bash.custom b/bash.custom index 3bd61f6..5c52816 100644 --- a/bash.custom +++ b/bash.custom @@ -593,8 +593,6 @@ sudocheck() { # # NOTE: This does not work for nano or cd commands # -trap 'sudoperms' ERR - function sudoperms() { # Previous command (ERR) always returns value 1 which is not @@ -603,7 +601,6 @@ function sudoperms() { unset PROMPT_COMMAND local CMD="${BASH_COMMAND}" - local i=0 # WORKAROUND # rm command has an interactive prompt where @@ -616,23 +613,22 @@ function sudoperms() { CMD=$(printf "${CMD}" | sed -E 's/^rm/rm -f/') fi - while [[ $i < 1 ]]; do - - if [[ $(${CMD} 2>&1 > /dev/null | grep -E "${ERROR_MSGS}") ]]; then - printf "${INFO_MSG}\n" - sudocheck - if [[ $? -eq 0 ]]; then - INFO_SEP + if [[ $(${CMD} 2>&>1 > /dev/null | grep -E "${ERROR_MSGS}") ]]; then + printf "${INFO_MSG}\n" + sudocheck + if [[ $? -eq 0 ]]; then + INFO_SEP - # Execute the failed command with sudo and get its return code - sudo bash -c "${CMD}" && RETCODE - fi + # Execute the failed command with sudo and get its return code + sudo bash -c "${CMD}" && RETCODE fi - - let i++ - done - + fi + checkdone= } + +if [[ -z checkdone ]]; then + trap 'sudoperms' ERR +fi ####################################### # If nano doesn't have correct permissions, use sudo