"Have you any idea how they do it (looking from programmer's side) ?"
The name of the current directory is kept in a variable called CWD. Try:
You can use CWD in your script programs to refer to the current working directory. You can use PWD to print your current working directory.
Be prepared. Create a LifeBoat CD.