kiwi.nvim icon indicating copy to clipboard operation
kiwi.nvim copied to clipboard

Duplication of path on new entry creation (MacOS)

Open avastmick opened this issue 10 months ago • 11 comments

While this plugin looks promising, I cannot get it work as expected with more than one notes location.

My configuration:

return {
    'serenevoid/kiwi.nvim',
    dependencies = {
        "nvim-lua/plenary.nvim"
    },
    opts = {
        {
            name = "work",
            path = "/Users/avastmick/notes/edu-docs"
        },
        {
            name = "personal",
            path = "/Users/avastmick/notes/local-notes"
        }
    },
    keys = {
        { "<leader>kw", ":lua require(\"kiwi\").open_wiki_index(\"work\")<cr>",     desc = "Open Wiki index" },
        { "<leader>kp", ":lua require(\"kiwi\").open_wiki_index(\"personal\")<cr>", desc = "Open index of personal wiki" },
        { "T",          ":lua require(\"kiwi\").todo.toggle()<cr>",                 desc = "Toggle Markdown Task" }
    },
    lazy = true
}

Usage:

I open the personal and add in a line 'Daily Plan', select words and <CR>, I get the following path (see the status line)

image

I hit Ctrl+o to return to index.md, hovered link does not show duplicated path elements:

image

If I remove the leading ./ from the new link, <CR> navigates to a new file in the directory I opened nvim.

avastmick avatar Apr 28 '24 22:04 avastmick

Sorry, update, the behaviour is now regardless of the number of wiki locations: I thought it was working for one, but it was actually creating files in the wrong place.

avastmick avatar Apr 28 '24 22:04 avastmick

Hi @avastmick! Thanks for reporting this issue. I have two questions though.

  • Is the index file created in the correct location for these two wiki locations?
  • This path trimming is failing only when the notes are created from the wiki note?

serenevoid avatar Apr 30 '24 08:04 serenevoid

Hi @avastmick! Thanks for reporting this issue. I have two questions though.

  • Is the index file created in the correct location for these two wiki locations?
  • This path trimming is failing only when the notes are created from the wiki note?

Firstly, yes, an index.md is created. Secondly, yes, when I create a new note the path is duplicated as per the screenshot in the OP.

I spent a bit of time trying to reproduce and when I create two empty wiki, the path handling is consistent with your GH README. In fact, I thought that the issue was resolved and all good. However, when I return to either wiki with an index.md created (say in a new nvim session), any new pages show the path duplication issue.

The path issue only occurs on an existing wiki. The behaviour is consistent. Have an index.md, create a new page, and the page is created in a nonexistent path that is duplicated.

Could this be a plugin clash? My list of plugins are as follows:

.
├── alpha-nvim.lua
├── cmp.lua
├── db-ui.lua
├── harpoon.lua
├── init.lua
├── kiwi.lua
├── leap.lua
├── lsp.lua
├── lualine.lua
├── neogit.lua
├── no-neck-pain.lua
├── noice.lua
├── oil.lua
├── rustaceanvim.lua
├── surround.lua
├── telescope.lua
├── themes.lua
├── todo-comments.lua
├── treesitter.lua
├── undotree.lua
└── which-key.lua

Thanks for the work on this and getting back so promptly on the issue I raised. The issue may be found between the computer and the chair 😀

avastmick avatar Apr 30 '24 20:04 avastmick

Thank you for the details! I could reproduce the issue. Will update the plugin soon! And to answer your questions,

  • No, its not caused by your plugins clashing since I could reproduce it
  • Yes, the plugin is currently meant for flat directory structure since that is easier for fast wiki note creation. But you could create a custom wiki link by typing the proper path relative to the wiki directory and use it as normal. You can't create notes in custom subdirectories. That's all

serenevoid avatar May 01 '24 03:05 serenevoid

Thanks for resolving. Great stuff!

avastmick avatar May 01 '24 03:05 avastmick

@avastmick

It seems the variable "relative_path" includes "config.path", which is the absolute path to each wiki, such as "path like path = '/Users/testuser/personal-wiki'" on Mac. Therefore, "relative_path" works as an absolute path.

To bypass this issue for now, I overwrote the method "utils.get_relative_path" as shown below in "init.vim". (Of course, you can simplify it further by returning empty strings without an if clause.)

lua << EOF
-- https://github.com/serenevoid/kiwi.nvim/issues/21
local utils = require'kiwi.utils'

local is_windows = vim.loop.os_uname().version:match('Windows')

utils.get_relative_path = function (config)
    local relative_path = vim.fs.dirname(vim.fn.expand('%:p'))
    if is_windows then
        -- For Windows, replace backslashes with forward slashes in the config path
        return relative_path:gsub(config.path:gsub("\\", "/"), "")
    else
        -- For macOS, return the relative path directly
        return ""
    end
end
EOF

tarurata avatar Jun 23 '24 07:06 tarurata

@avastmick @tarurata I have added a new commit for fixing this issue. Please have a look when you find time. Hope to hear from you soon.

serenevoid avatar Jul 04 '24 09:07 serenevoid

The latest change broke my setup using Obsidian and iCloud. I think this line in ensure_directories:

props.path = props.path:gsub("$HOME", get_home()):gsub("~", get_home())

conflicts with my config:

local wikiPath = '/Users/mwarner/Library/Mobile Documents/iCloud~md~obsidian/Documents/my_notes'
require('kiwi').setup({
    {
        name = 'personal',
        path = wikiPath,
    },
})

mlwarner avatar Jul 06 '24 16:07 mlwarner

@mlwarner Thanks for your response. I have rolled back the plugin. Please try updating the plugin again. If update fails, try reinstalling the plugin.

serenevoid avatar Jul 06 '24 16:07 serenevoid

Thanks! I unpinned the commit and it is working as expected.

I think you are looking for path expansion here rather than a substitution. Quick scan through vim help docs has vim.fn.expand. Testing with :lua =vim.fn.expand("/Users/mwarner/Library/Mobile Documents/iCloud~md~obsidian/Documents/my_notes") yields the same path, and :lua =vim.fn.expand("~/wiki") also works as expected.

mlwarner avatar Jul 06 '24 16:07 mlwarner

I do not know if this is the right place for this issue, as I am not on MacOS. However, I seem to have the same issue: If I create links to new notes inside my index.md, I can not save the new notes because the path to my wiki is dublicated. image

maximilianZenke avatar Aug 02 '24 12:08 maximilianZenke