Change all whoami calls for $USER variable

This avoid spawning additional processes, as the $USER variable will
**always** contain the current logged-in user.
Change all pwd calls for $PWD variable

This avoids spawning additional processes as $PWD **always** contains
the current working directory.
Change all hostname calls for $HOST or $SHORT_HOST
Merge pull request #3223 from mcornella/use-special-vars

Use special variables where we can
Refactor similar functions into common sections
Fix take function

Before the modification, the `take` function will try to cd
into the created directory even if mkdir throws an error.

With this modification, if mkdir fails to create the directory,
cd won't run and the take function will return the mkdir exit
code.