require 'fusefs'

class HelloDir
  $files = ["command"]
  $dirs = []
  
  def contents(path)
    if (path == "/")
      ret =  $dirs = `ps aux |awk {'print $2'}`.split
    else
      for i in $dirs
        if (path == "/" + i)
          ret = $files
        end
      end
    end
    ret
  end
  def directory?(path)
    $dirs.include?(path.split("/")[-1])
  end

  def file?(path)
    $files.include?(path.split("/")[-1])
  end

  def read_file(path)
    if (path.split("/")[-1] == "command")
      cmd = "ps o cmd -p " + path.split("/")[1]
      ret = IO.popen(cmd).read.split[1].concat("\n")
    end
    ret
  end
  
  def can_delete?(path)
    true
  end
  
  def can_rmdir?(path)
    true
  end

  def rmdir(path)
    Process.kill(9, path.split("/")[1].to_i)
  end
end

hellodir = HelloDir.new
FuseFS.set_root( hellodir )

FuseFS.mount_under ARGV.shift
FuseFS.run

