Skip to content

Add a pushd context - #206

Closed
ppannuto wants to merge 1 commit into
amoffat:masterfrom
ppannuto:master
Closed

ppannuto wants to merge 1 commit into
amoffat:masterfrom
ppannuto:master

Conversation

@ppannuto

Copy link
Copy Markdown
Contributor

I find that I write this little boilerplate all the time and I think
other sh users would find it useful as well. This simply creates a
context to run commands in another directory and ensures that the
original working directory will be returned to.

Usage:

from sh import pushd, pwd

pwd()
with pushd('/tmp'):
    pwd()
pwd()

I find that I write this little boilerplate all the time and I think
other sh users would find it useful as well. This simply creates a
context to run commands in another directory and ensures that the
original working directory will be returned to.

Usage:

```python
from sh import pushd, pwd

pwd()
with pushd('/tmp'):
    pwd()
pwd()
```
@amoffat

amoffat commented Dec 23, 2014

Copy link
Copy Markdown
Owner

thanks Pat. merged into release-1.10. i generalized it a bit more so that the with-context can work with any special keyword argument, but i left in the pushd alias because it will probably be used the most:

from sh import args, pwd, pushd

print pwd()
with args(_cwd="/tmp"): # or pushd("/tmp")
    pwd()
print pwd()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants