Skip to content

Instantly share code, notes, and snippets.

@brainsik brainsik/gist:971526
Created May 13, 2011

Embed
What would you like to do?
sudo -H for Fabric
import fabric.api
from contextlib import contextmanager
@contextmanager
def shell(new_shell):
old_shell, env.shell = env.shell, new_shell
yield
env.shell = old_shell
def sudo(*args, **kwargs):
if not kwargs.get('use_home', True):
return fabric.api.sudo(*args, **kwargs)
# simulate 'sudo -H'
user = kwargs.get('user', 'root')
with shell("HOME=~%s %s" % (user, env.shell)):
return fabric.api.sudo(*args, **kwargs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.