Skip to content

Commit

Permalink
Merge e1399f1 into a1b1bc2
Browse files Browse the repository at this point in the history
  • Loading branch information
kalekundert committed Dec 28, 2018
2 parents a1b1bc2 + e1399f1 commit e2afe43
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion shlib/__init__.py
Expand Up @@ -10,7 +10,7 @@
set_prefs,

# filesystem utilities
cp, mv, rm, ln, touch, mkdir, cd, cwd, chmod, ls, lsd, lsf,
cp, mv, rm, ln, touch, mkdir, mount, umount, is_mounted, cd, cwd, chmod, ls, lsd, lsf,

# path expansion utilities
leaves, cartesian_product, brace_expand,
Expand Down
23 changes: 23 additions & 0 deletions shlib/shlib.py
Expand Up @@ -236,6 +236,29 @@ def mkdir(*paths):
if err.errno != errno.EEXIST or path.is_file():
raise

# mount/umount {{{2
class mount:

def __init__(self, path):
self.path = to_path(path)
self.mounted_externally = is_mounted(self.path)

if not self.mounted_externally:
Run(['mount', self.path])

def __enter__(self):
pass

def __exit__(self, exc_type, exc_value, exc_traceback):
if not self.mounted_externally:
umount(self.path)

def umount(path):
Run(['umount', path])

def is_mounted(path):
return Run(['mountpoint', '-q', path], '0,1').status == 0

# cd {{{2
class cd:
def __init__(self, path):
Expand Down

0 comments on commit e2afe43

Please sign in to comment.