You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I find idea when see your cd-project.nvim.json file
I think it will useful for someone need it - I call it "CdProjectAddCurrentDir" -> it will automatically add current directory that currently loading into cd-project.nvim.json with current path and name.
-- Define a wrapper function for CdProjectAddfunctionCdProjectAddCurrentDir()
-- Get the directory of the current filelocalcurrent_file_directory=vim.fn.expand('%:p:h')
-- Call CdProjectAdd with the current file directory as an argumentCdProjectAdd(current_file_directory)
end-- Define CdProjectAdd functionfunctionCdProjectAdd(directory)
-- Read existing projects from cd-project.nvim.jsonlocalprojects_config_filepath=vim.fn.stdpath("config") .."/cd-project.nvim.json"localfile=io.open(projects_config_filepath, "r")
localcontent=file:read("*all")
file:close()
-- Decode JSON content if it's not empty, otherwise initialize projects as an empty tablelocalprojects=content~="" andvim.fn.json_decode(content) or {}
-- Prepare the new project objectlocalproject= {}
project["path"] =directoryproject["name"] =directory:match("([^/\\]*)$")
-- Check if the project already exists in the projects tablefor_, existing_projectinipairs(projects) doifexisting_project["path"] ==project["path"] then-- The project already exists, so we return without adding itrequire("notify")("Project already exists: " ..project["path"], 'Notice')
returnendend-- Add the new project object to projectstable.insert(projects, project)
-- Encode projects back to JSONlocalnew_content=vim.fn.json_encode(projects)
-- Write updated JSON content back to cd-project.nvim.jsonfile=io.open(projects_config_filepath, "w")
file:write(new_content)
file:close()
-- Display a notificationrequire("notify")("Project is saved: " ..project["path"] .." as " ..project["name"], 'Notice')
end-- Set key mapping for CdProjectAddCurrentDir functionvim.api.nvim_set_keymap('n', 'pa', '<cmd>lua CdProjectAddCurrentDir()<CR>', {noremap=true, silent=true})
The text was updated successfully, but these errors were encountered:
I find idea when see your cd-project.nvim.json file
I think it will useful for someone need it - I call it "CdProjectAddCurrentDir" -> it will automatically add current directory that currently loading into cd-project.nvim.json with current path and name.
Required: vim.notifiy plugin
The text was updated successfully, but these errors were encountered: