diff options
author | toonn <toonn@toonn.io> | 2020-06-16 11:53:05 +0200 |
---|---|---|
committer | toonn <toonn@toonn.io> | 2020-06-16 11:55:09 +0200 |
commit | c2ae8e63f953dd1122653fdbf3048b7b7980b396 (patch) | |
tree | 37a575e469f6dbf0f82d063b6e38ae1070c81178 | |
parent | 1654128f955b320354eea98a0bb6970a159ab16f (diff) | |
download | ranger-c2ae8e63f953dd1122653fdbf3048b7b7980b396.tar.gz |
:touch create missing directories
`:mkdir` creates directories recursively like `mkdir -p`. `:touch` failed when parent directories didn't exist, for convenience and consistency it now creates missing directories recursively. Fixes #1998
-rwxr-xr-x | ranger/config/commands.py | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/ranger/config/commands.py b/ranger/config/commands.py index 5defa677..d8456255 100755 --- a/ranger/config/commands.py +++ b/ranger/config/commands.py @@ -928,10 +928,14 @@ class touch(Command): """ def execute(self): - from os.path import join, expanduser, lexists + from os.path import join, expanduser, lexists, dirname + from os import makedirs fname = join(self.fm.thisdir.path, expanduser(self.rest(1))) + dirname = dirname(fname) if not lexists(fname): + if not lexists(dirname): + makedirs(dirname) open(fname, 'a').close() else: self.fm.notify("file/directory exists!", bad=True) |