HackerTrans
TopNewTrendsCommentsPastAskShowJobs

hielke

no profile record

comments

hielke
·vor 5 Monaten·discuss
With exec you can open file descriptors of your current process.

  if [[ ! -e /proc/$$/fd/3 ]]; then
      # check if fd 3 already open and if not open, open it to /dev/null
      exec 3>/dev/null
  fi
  >&3 echo "will print on fd 3"
This will fix the error you are describing while keeping the functionality intact.

Now with that exec trick the fun only gets started. Because you can redirect to subshells and subshells inherit their redirection of the parent:

  set -x # when debugging, print all commands ran prefixed with CMD:
  PID=$$
  BASH_XTRACEFD=7
  LOG_FILE=/some/place/to/your/log/or/just/stdout
  exec 3> >(gawk '!/^RUN \+ echo/{ print strftime("[%Y-%m-%d %H:%M:%S] <PID:'$PID'> "), $0; fflush() }' >> $LOG_FILE)
  exec > >(sed -u 's/^/INFO:  /' >&3)
  exec 2> >(sed -u 's/^/ERROR: /' >&3)
  exec 7> >(sed -u 's/^/CMD:   /' >&3)
  exec 8>&1 #normal stdout with >&8
  exec 9>&2 #normal stderr with >&9
And now your bash script will have a nice log with stdout and stderr prefixed with INFO and ERROR and has timestamps with the PID.

Now the disclaimer is that you will not have gaurantees that the order of stdout and stderr will be correct unfortunately, even though we run it unbuffered (-u and fflush).
hielke
·vor 2 Jahren·discuss
The phrase in the title is also not from Frank Herbert. It is from Lynch's movie adaptation of the books.
hielke
·vor 2 Jahren·discuss
>Do modules actually make compilation appreciably faster in msvc?

For a small toy example, about 10x times faster. Don't know how that looks in real life projects.
hielke
·vor 2 Jahren·discuss
In modern C++ there will be modules (C++20). Even std will be available as a module (C++23). This will likely bring down compile times massively. But so far the only compiler with support for this today is MSVC.
hielke
·vor 3 Jahren·discuss
I was stuck on the same struggles, but eventually managed to bodge something together:

https://github.com/hwalinga/dotfiles/blob/master/CapsLockCtr...

It also implements the double feature functionality of CapsLock that now functions as Ctrl when pressed with another key, and just Esc when tapped.