piotrmurach/tty

suggestion: file operations

gurgeous opened this issue · 2 comments

Perhaps we can add file operations? TTY could add a lot of value. There are some subtleties here that go beyond what FileUtils provides.

For one thing, it can echo the commands if verbose is set to true. Note the if_necessary variants - they only echo if the command is actually run. For example, mkdir_if_necessary("xyz") will only print "mkdir xyz" if that directory doesn't exist.

Also note that user and owner can be specified as strings instead of ids. etc.

Let me know if you are interested.

attr_accessor :verbose

def chmod(file, mode)
def chown(file, user)

def cp(src, dst, mkdir: false, owner: nil, mode: nil)
def ln(src, dst)
def mkdir(dir, owner: nil, mode: nil)
def mv(src, dst, mkdir: false)
def rm(file)

def rm_and_mkdir(dir)

def cp_if_necessary(src, dst, mkdir: false, owner: nil, mode: nil)
def ln_if_necessary(src, dst)
def mkdir_if_necessary(dir, owner: nil, mode: nil)
def rm_if_necessary(file)

Hi Adam, it took me a long time but I have finally managed to get to create tty-file that aims to include the above functionality and a tad more. Please check it out. It is nowhere finished but has all the core stuff.

Neat! I will check it out.