Change the current working directory within this context.
    
    Preserves the previous working directory and can be applied to remote
    connections that offer @getcwd@ and @chdir@ methods using the @on@
    argument.

def cd(path, on=os):
    """Change the current working directory within this context.
    
    Preserves the previous working directory and can be applied to remote
    connections that offer @getcwd@ and @chdir@ methods using the @on@
    argument.
    """
    
    original = on.getcwd()
    on.chdir(path)
    
    yield
    
    on.chdir(original)