OmeGak / dotfiles

The ultimate bastion for my dotfiles and more
MIT License
6 stars 2 forks source link

Show only offending error logs #18

Closed OmeGak closed 9 years ago

OmeGak commented 9 years ago

Disclaimer. This is thoroughly explained so my future self remember the whole thing when he comes back to the issue I'm about to give up upon for today.

This is gonna be useful for debugging install and *-deps steps of dot command. I want to show at the end of each step the log files of the topics that failed.

My idea is to grep only the log files that contain the name of the failed topic:

find -L /tmp -maxdepth 1 -name *$logfile_suffix | grep '$error_topics'

For grep to grep for several words the following syntax is used:

grep 'a\|b'

Now it should simply be about joining with \| the array errors containing the failed topics, but well, this is Shell, so it's not gonna be so easy, apparently. I first have to resolve to defining a custom function.

function join { local IFS="$1"; shift; echo "$*"; }

This allows me to join the $errors into a string with a separator:

$ echo `join \| ${errors[@]}`
homebrew|whatever

The problem is that there is no way to use \| as separator as IFS only takes the first character | (since \ in the command is used to escape |) and so I have to sed the result to replace | for \|:

$ echo `join \| ${errors[@]}` | sed 's/|/\\|/g'
homebrew\|whatever

So far so good... Let's story this in a variable so that it can be used as initially intended by `grep

error_topics=`join \| ${errors[@]} | sed 's/|/\\|/g'`
echo $error_topics

And the output is:

homebrew|whatever

And I couldn't find any way to store it correctly. :'(

OmeGak commented 9 years ago

Implemented in 99a74dae82683d3c4ff66b973b9e95268671987f