I made a custom PS1 variable, which is a tremendously confusing. Here is the one that is closest to being fully working:
PS1="\n[\e[1;31m]\u@\H[\e[35m] \@ [\e[32m] PWD: \w [\e[1;34m]This folder has \$(/bin/ls -1 | /usr/bin/wc -l | /bin/sed 's: ::g') files [\e[1;33m]A total of \$(/bin/ls -lah | /bin/grep -m 1 total | /bin/sed 's/total //')b\n`if [ \$? = 0 ]; then echo [\e[32m]^_^ [\e[0m] Worked - [\e[0m]; else echo [\e[31m]O_O[\e[0m]Didn't worked - ; fi`"
This is the same code as the previous code sample, but it has been separated into blocks and commented for better readability:
#User@Host [Red] \n\[\e[1;31m\]\u@\H #Hour [Purple] \[\e[35m\] \@ #PWD [Green] \[\e[32m\] PWD: \w #Number of files in PWD [Blue] \[\e[1;34m\]This folder has \$(/bin/ls -1 | /usr/bin/wc -l | /bin/sed 's: ::g') files #Amount of space the PWD files take, also line break [Yellow] \[\e[1;33m\]A total of \$(/bin/ls -lah | /bin/grep -m 1 total | /bin/sed 's/total //')b\n #Malfunctioning condition, should smile if the instruction went right, or poker-face if not [green and red] \`if [ \$? = 0 ]; then echo \[\e[32m\]^_^ \[\e[0m\]\[\e[0m\]Worked - \[\e[0m\]; else echo \[\e[31m\]O_O\[\e[0m\] Didn't worked - ; fi\`
Trying to explain the problem:
iflooks for a condition that can no longer be false after running for (eg.)
"This folder has \$(/bin/ls -1 | /usr/bin/wc -l | /bin/sed 's: ::g') files", as it is true if the latest statement had a clean end.
How can I make it work while at same time keep the output in that same position? If the if is moved to before the first command executed, it works fine.
I thought of assigning a variable with that
if condition at the start of the PS1. Then other
if at this one's position would judge the alternative variable that would not change. But unfortunately I have no skill at all with Bash. I have already tried unsuccessfully to do it a thousand or so times.
Something like this (but well written):
PS1="`if [ \$? = 0 ];then echo "prev_err=0"; else prev_err=0; fi\` ...[Some more code in between]... `if [ \$prev_err = 0 ] then echo "No error" else echo "There was an error in the statement." fi\`"
Some ` (backtick characters) are in the wrong places or omitted in the previous code block.