diff --git a/README.md b/README.md index a147810..48892af 100644 --- a/README.md +++ b/README.md @@ -208,6 +208,7 @@ To avoid the most common Windows issue: - Second best option: try WSL2 on Windows and pretend you're on Linux - if you **must** use Windows, use `/Users/myname/zettelkasten` instead of `~/zettelkasten` - **NEVER** use `C:\Users\myname` style paths +- Using `vim.fn.expand("~/zettelkasten")` should work now but mileage will vary with anything outside of finding and opening files ```lua lua << END @@ -217,6 +218,7 @@ local home = vim.fn.expand("~/zettelkasten") -- - try WSL2 on Windows and pretend you're on Linux -- - if you **must** use Windows, use "/Users/myname/zettelkasten" instead of "~/zettelkasten" -- - NEVER use "C:\Users\myname" style paths +-- - Using `vim.fn.expand("~/zettelkasten")` should work now but mileage will vary with anything outside of finding and opening files require('telekasten').setup({ home = home, @@ -336,6 +338,7 @@ END | | - try WSL2 on Windows and pretend you're on Linux | | | | - if you **must** use Windows, use `/Users/myname/zettelkasten` instead of `~/zettelkasten` | | | | - **NEVER** use `C:\Users\myname` style paths | | +| | - Using `vim.fn.expand("~/zettelkasten")` should work now but mileage will vary with anything outside of finding and opening files | | | **`take_over_my_home`** | if set to `true` (default), telekasten will take over your home. Any notes from the configured `home` directory will receive a `set filetype=telekasten`, no matter if opened by telekasten or another way. | true | | `dailies` | path where your daily notes go | ~/zettelkasten/daily | | `weeklies` | path where your weekly notes go | ~/zettelkasten/weekly | diff --git a/doc/telekasten.txt b/doc/telekasten.txt index 3f34ff4..8cb9c60 100644 --- a/doc/telekasten.txt +++ b/doc/telekasten.txt @@ -16,6 +16,10 @@ daily note (or cancel out and keep browsing your calendar). The daily note will be created if it doesn't exist. Days with daily notes get marked in the calendar. +For Windows users, many of the functions that require navigating file folders +do not work. This is due to how Telescope handles paths and the odd way that +Windows structures its paths. It is advised you don't use Windows. + To find out more: https://github.com/renerocksai/telekasten.nvim @@ -138,6 +142,20 @@ telekasten.setup({opts}) Default: '~/zettelkasten' + ---------------------- + Note to Windows users: + + If you must use Windows, avoid using the drive path. You may use it, + but telekasten will ignore the drive name and create your main markdown + / zettelkasten folder in the same drive that neovim executes from. This + is because of how Telescope handles files paths. Windows paths must be + stripped of the drive name or else the path will not be read correctly. + This is done automatically but is advised that you avoid adding it. + + It is recommended that if your path is not the default to write it + like a Unix path with '/' instead of '\', or to escape the '\' as '\\'. + ---------------------- + *telekasten.settings.take_over_my_home* take_over_my_home: ~ If set to `true`, telekasten.nvim will take over your home. Any notes diff --git a/lua/telekasten.lua b/lua/telekasten.lua index 9ed77f4..9b4d4f2 100644 --- a/lua/telekasten.lua +++ b/lua/telekasten.lua @@ -23,10 +23,35 @@ local Path = require("plenary.path") -- declare locals for the nvim api stuff to avoid more lsp warnings local vim = vim +-- Cleans home path for Windows users +-- Needs to be before default config, else with no user config +-- home will not be cleaned and issues will still occur +local function CleanPath(path) + -- File path delimeter for Windows machines + local windows_delim = "\\" + -- Returns the path delimeter for the machine + -- '\\' for Windows, '/' for Unix + local system_delim = package.config:sub(1, 1) + local new_path_start + + -- Removes portion of path before '\\' for Windows machines + -- since Telescope does not like that + if system_delim == windows_delim then + new_path_start = path:find(windows_delim) -- Find the first '\\' + if new_path_start ~= nil then + path = path:sub(new_path_start) -- Start path at the first '\\' + end + end + + -- Returns cleaned path + return path +end + -- ---------------------------------------------------------------------------- -- DEFAULT CONFIG -- ---------------------------------------------------------------------------- local home = vim.fn.expand("~/zettelkasten") +home = CleanPath(home) local M = {} M.Cfg = { @@ -2696,6 +2721,9 @@ local function Setup(cfg) -- merge everything but calendar opts -- they will be merged later if k ~= "calendar_opts" then + if k == "home" then + v = CleanPath(v) + end M.Cfg[k] = v if debug then print(