Steal the extract shell function from @boris-petrov