orhnk / vimacs

Feature-full Neovim Experience - With Emacs, JetBrains features OOTB
GNU General Public License v3.0
324 stars 8 forks source link

neoproj looking can't find directory - Windows #24

Closed entailz closed 10 months ago

entailz commented 10 months ago

Neoproj attempts to create a folder in the root directory but fails. I tried to debug this for a lil' bit but couldn't find a proper solution. Might have to do with the commands being sent in neoproj.lua being incompatible with windows, or the change from backslash to forward.

Error executing vim.schedule lua callback: name/AppData/Local/nvim-data/lazy/neoproj/lua/neoproj.lua:92: Vim:E344: Can't find directory "C:\Users\name/Github/repos/unnamed" in cdpath
stack traceback:
        [C]: in function 'cd'
        name/AppData/Local/nvim-data/lazy/neoproj/lua/neoproj.lua:92: in function 'on_confirm'
        Local/nvim-data/lazy/dressing.nvim/lua/dressing/input.lua:135: in function 'fn'
        vim/_editor.lua:477: in function 'cb'
        vim/_editor.lua:263: in function <vim/_editor.lua:262>
denizbaba0 commented 10 months ago

neoproj is creating directories using !mkdir cmd relying on the system shell. You can send a PR for the neoproj plugin that will make it cross-platform


LINK TO NEOPROJ FILE

entailz commented 10 months ago

I ended up just fixing it myself, couple of slight differences but nothing crazy. The functions are written in an interesting way, almost obfuscated.

orhnk commented 10 months ago

I ended up just fixing it myself, couple of slight differences but nothing crazy. The functions are written in an interesting way, almost obfuscated.

I Definitely agree. This was just a fork from another repo (I find _2aconfig_2a odd too!)

Can you show me how you did fix it?

entailz commented 10 months ago

Not entirely sure what the intended functionality is, but this requires you to make a Github folder in the %HOMEPATH%, a templates folder inside of the Github folder as well as repos, this will be project_root. The way it works right now it pulls the git links from that custom/configs/neoproj.lua and drops them in templates folder C:\Users\user\Github\templates. Session still not really working properly and the actual template file needs to be moved from templates folder into the working directory manually. Sessions do work on Windows but for some reason M.save logic is broken for me.

Another note, in /custom/configs/neoproj

      project_path = os.getenv ("HOMEPATH") .. "\\Github\\repos" 

Here's neoproj.lua inside of lazy folder

--local new_home = os.getenv("HOMEPATH") .. "\\Github\\templates"
local _2aconfig_2a = { project_path = (vim.env.HOME .. "\\projects") }
local _2atemplates_2a = {}

local M = {}

M.create_project = function(template, opts)
  local url = "https://github.com/" .. template .. ".git"
  local cache_dir = os.getenv("HOMEPATH") .. "\\Github\\templates\\" .. template
  -- If the project template is not cached, clone it
  if vim.fn.empty(vim.fn.glob(cache_dir)) > 0 then
    print("Cloning " .. url .. " to " .. cache_dir)
    vim.fn.system("git clone " .. url .. " " .. cache_dir)
  end
  -- If the project template is cached and pulling enabled, pull it
  if opts then
    if opts.pull then
      print("Pulling " .. url .. " to " .. cache_dir)
      vim.fn.system("cd /d " .. cache_dir .. " && git pull")
    end
  end
    print("copying to current directory")-- Copy the cached project template to the current directory
    return "cp -r " .. cache_dir .. "/* ."
    --os.execute("cp -r " .. cache_dir .. "/*" .. " " .. ".") -- Copy the cached project template to the current directory
end

local function cd_project(project)
  local path = (_2aconfig_2a.project_path .. "\\" .. project)
  local session = (path .. "\\.nvim\\session.vim")
  do
    local dir_3f
    local function _1_(_241)
      return (1 == vim.fn.isdirectory(_241))
    end
    dir_3f = _1_
    assert(dir_3f(path), (project .. " is not a directory"))
  end
  if vim.loop.fs_access(session, "R") then
    vim.cmd.source(session)
  else
    vim.cmd.edit(path)
  end
  vim.cmd.cd(path)
  vim.g.project_root = path
  return nil
end

M.open_project = function(project)
  if ("" == project) or (nil == project) then
    local projects
    do
      local tbl_17_auto = {}
      local i_18_auto = #tbl_17_auto
      for p in vim.fs.dir(_2aconfig_2a.project_path) do
        local val_19_auto = p
        if nil ~= val_19_auto then
          i_18_auto = (i_18_auto + 1)
          do
          end
          (tbl_17_auto)[i_18_auto] = val_19_auto
        else
        end
      end
      projects = tbl_17_auto
    end
    local function _4_(project0)
      if nil == project0 then
        return nil
      else
        return cd_project(project0)
      end
    end
    return vim.ui.select(
      projects,
      { prompt = "Select project:", kind = "project" },
      _4_
    )
  else
    return cd_project(project)
  end
end

local function expand_template(_7_)
  local _arg_8_ = _7_
  local expand = _arg_8_["expand"]
  local function _9_(_241)
    if nil == _241 then
      return nil
    else
      local path = (_2aconfig_2a.project_path .. "\\" .. _241)
      -- assert((1 == vim.fn.mkdir(path)), "Failed to create directory")
      -- vim.cmd("silent !mkdir -p " .. path)
      os.execute("mkdir" .. path .. " \\p")
      vim.cmd.cd(path)
      vim.g.project_root = path
      do
        local _10_ = type(expand)
        if _10_ == "string" then
          os.execute(expand)
        elseif _10_ == "function" then
          expand(_241, path)
        else
        end
      end
      return vim.cmd.edit(path)
    end
  end
  return vim.ui.input(
    { prompt = "Enter project name:", default = "unnamed" },
    _9_
  )
end

M.new_project = function()
  local function _13_(_241)
    return _241.name
  end
  local function _14_(_241)
    if nil == _241 then
      return nil
    else
      return expand_template(_241)
    end
  end
  return vim.ui.select(_2atemplates_2a, {
    prompt = "Select template",
    kind = "project-template",
    format_item = _13_,
  }, _14_)
end

M.save_session = function()
  assert(
    (("string" == type(vim.g.project_root)) and ("" ~= vim.g.project_root)),
    "Not in project"
  )
  local nvim_dir = (vim.g.project_root .. "\\.nvim")
  if 0 == vim.fn.isdirectory(nvim_dir) then
    -- assert((1 == vim.fn.mkdir(nvim_dir)), "Failed to save session")
    -- vim.cmd("silent !mkdir -p " .. nvim_dir)
     os.execute("mkdir " .. nvim_dir .. " \\p")
  else
  end
  return vim.cmd(("mksession! " .. nvim_dir .. "\\session.vim"))
end

M.setup = function(config)
  assert(("table" == type(config)), "config: expected table")
  _2aconfig_2a = vim.tbl_deep_extend("force", _2aconfig_2a, config)
  return nil
end

M.register_template = function(template)
  assert(("string" == type(template.name)), "name: expected string")
  do
    local t = type(template.expand)
    assert(
      (("string" == t) or ("function" == t)),
      "expand: expected string|function"
    )
  end
  return table.insert(_2atemplates_2a, template)
end

return M
entailz commented 10 months ago

okay i figured it out, if you call HOMEPATH env variable it doesn't prepend "C:" lol, this is all I had to change from what I posted above. Now it imports the template into project directory.

local _2aconfig_2a = { project_path = (vim.env.HOMEPATH .. "/projects") }
local _2atemplates_2a = {}

local M = {}

M.create_project = function(template, opts)
  local url = "https://github.com/" .. template .. ".git"
  local cache_dir = os.getenv("HOMEPATH") .. "/.cache/vimacs/projects/" .. template
  -- If the project template is not cached, clone it
  if vim.fn.empty(vim.fn.glob(cache_dir)) > 0 then
    print("Cloning " .. url .. " to " .. cache_dir)
    vim.fn.system("git clone " .. url .. " " .. cache_dir)
  end
  -- If the project template is cached and pulling enabled, pull it
  if opts then
    if opts.pull then
      print("Pulling " .. url .. " to " .. cache_dir)
      vim.fn.system("cd /d " .. cache_dir .. " && git pull")
    end
  end
    print("copying to current directory")-- Copy the cached project template to the current directory
    --return "cp -r " .. cache_dir .. "/* ."
    os.execute("cp -r " .. "C:" .. cache_dir .. "/*" .. " " .. ".") -- Copy the cached project template to the current directory
end
orhnk commented 10 months ago

@entailz does the $HOME variable come with a C: prefix?

entailz commented 10 months ago

HOME doesn't work, it's not a windows environment variable.

entailz commented 10 months ago

image

entailz commented 10 months ago

Works fine now though. Only other thing I had to change was sniprun, I changed the daemonizer made it compatible with windows and compiled. image