[I still would like to know if there is a better answear.]
I found a way that works, and the prompt will be kept on a single line:
at the end of your ~/.bashrc
add this:
function FUNCsudoOn() {
if sudo -n uptime 2>/dev/null 1>/dev/null; then
echo -ne "\E[0m\E[93m\E[41m\E[1m\E[5m SUDO \E[0m";
#echo #without newline, the terminal seems to bugout with lines that are too big... discomment this if you find any problems...
fi;
}
function FUNCpromptCommand () {
FUNCsudoOn
}
export PROMPT_COMMAND=FUNCpromptCommand
#export PS1="\`FUNCsudoOn\`$PS1" #this also works, use instead of PROMPT_COMMAND
EDIT: I found that sudo -n uptime
will update the sudo timeout, so everytime you hit the Enter key, that sudo time will be updated... That makes knowing the remaining time useless, as it will always be the configured one, defaulting to 15min...
and to find the best colors formatting for you taste you can use ScriptEchoColor with --escapedchars
option like:
echoc --escapedchars "@{nRlyo} SUDO " #that outputs below...
echo -e "\E[0m\E[93m\E[41m\E[1m\E[5m SUDO \E[0m"
to just stop the blinking remove \E[5m
like in \E[0m\E[93m\E[41m\E[1m SUDO \E[0m
Not knowing exactly what's being done, I can only speak generally:
- Reads are simply reads from memory or disk.
- Writes have to check constraints, action triggers and then write to disk. Usually within a transaction that needs to be setup, actioned committed and then cleaned up. And then there's cache invalidation.
- Most disks (and their filesystems) read much faster than they write.
I'm not surprised a restore takes longer than a backup but if you really think it's erroneously long, benchmark your queries and work out what the problem is.
Best Answer
Hi I found this answer on another question - The problem is if your hostname is not in your hosts file.
basically, type "hostname" in your terminal. That will tell you what your hostname is.
Next, type:
and add:
then save - and you are done! Sudo should be fast now!