From 301b488b987b629add14c8a4831d237387ac5d28 Mon Sep 17 00:00:00 2001 From: hut Date: Thu, 14 Jan 2010 19:32:02 +0100 Subject: commands: added touch, improved mkdir --- ranger/commands.py | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/ranger/commands.py b/ranger/commands.py index 411408eb..07c0a8d7 100644 --- a/ranger/commands.py +++ b/ranger/commands.py @@ -264,11 +264,34 @@ class mkdir(Command): """ def execute(self): + from os.path import join, expanduser, lexists + from os import mkdir + line = parse(self.line) - try: - self.fm.mkdir(line.rest(1)) - except IndexError: - pass + dirname = join(self.fm.env.pwd.path, expanduser(line.rest(1))) + if not lexists(dirname): + mkdir(dirname) + else: + self.fm.notify("file/directory exists!", bad=True) + + +class touch(Command): + """ + :touch + + Creates a file with the name . + """ + + def execute(self): + from os.path import join, expanduser, lexists + from os import mkdir + + line = parse(self.line) + fname = join(self.fm.env.pwd.path, expanduser(line.rest(1))) + if not lexists(fname): + open(fname, 'a') + else: + self.fm.notify("file/directory exists!", bad=True) class edit(Command): -- cgit 1.4.1-2-gfad0