LoginSignup
2
2

More than 5 years have passed since last update.

mkseldir - mkdir して、さらにそれを選択するコマンド

Last updated at Posted at 2012-09-04

デフォルトの :mkdir コマンドの改良版。
mkdir した後に、そのディレクトリを選択します。

作者からコメントをもらったので更新

commands-mkseldir2.py
from ranger.api.commands import *
class mkseldir(Command):
  """
  :mkseldir <dirname>

  Creates a directory with the name <dirname>, and select it.
  """

  def execute(self):
    from os.path import join, expanduser, lexists
    dirname = join(self.fm.thisdir.path, expanduser(self.rest(1)))
    if not lexists(dirname):
      self.fm.mkdir(dirname)
      if lexists(dirname):
        self.fm.thisdir.load_content(schedule=False)
        self.fm.select_file(dirname)
      else:
        self.fm.notify("Failed to mkdir!", bad=True)
    else:
      self.fm.notify("file/directory exists!", bad=True)

以下は古いバージョン

commands.py
from ranger.api.commands import *

class mkseldir(Command):
  """
  :mkseldir <dirname>

  Creates a directory with the name <dirname>, and select it.
  """

  def execute(self):
    from os.path import join, expanduser, lexists
    dirname = join(self.fm.thisdir.path, expanduser(self.rest(1)))
    if not lexists(dirname):
      self.fm.mkdir(dirname)
      if lexists(dirname):
        item = ranger.fsobject.directory.Directory(dirname, path_is_abs=True)
        item.load()
        self.fm.thisdir.files.append(item)
        self.fm.select_file(dirname)
      else:
        self.fm.notify("Failed to mkdir!", bad=True)
    else:
      self.fm.notify("file/directory exists!", bad=True)

Veedrac さんに教えてもらいました!!!
https://bbs.archlinux.org/viewtopic.php?pid=1155529#p1155529

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2