From 60808e8e596f2dc93db746b3437caf6716387f7d Mon Sep 17 00:00:00 2001 From: Anatolii Kurotych Date: Mon, 17 Oct 2022 22:00:24 +0200 Subject: [PATCH] Add follow_url_fallback config option (#172) * Add follow_link_fallback config option * Update README.md * Rename follow_link_fallback to follow_url_fallback. Change logic of configuring --- README.md | 4 ++++ doc/telekasten.txt | 7 +++++++ lua/telekasten.lua | 8 ++++++++ 3 files changed, 19 insertions(+) diff --git a/README.md b/README.md index 50a2c8d..2adc171 100644 --- a/README.md +++ b/README.md @@ -411,6 +411,9 @@ require('telekasten').setup({ -- "telescope-media-files" if you have telescope-media-files.nvim installed -- "catimg-previewer" if you have catimg installed media_previewer = "telescope-media-files", + + -- A customizable fallback handler for urls. + follow_url_fallback = nil, }) END ``` @@ -475,6 +478,7 @@ END | `media_previewer` | how to preview media files | default: `telescope-media-files` | || - `telescope-media-files` if you have telescope-media-files.nvim installed | || - `catimg-previewer` if you have catimg installed | +| `follow_url_fallback ` | A customizable fallback handler for urls. | default: `nil` | The calendar support has its own options, contained in `calendar_opts`: diff --git a/doc/telekasten.txt b/doc/telekasten.txt index 303bf71..5ee6b14 100644 --- a/doc/telekasten.txt +++ b/doc/telekasten.txt @@ -418,6 +418,13 @@ telekasten.setup({opts}) Default: `telescope-media-files` + *telekasten.settings.follow_url_fallback* + follow_url_fallback:~ + A customizable fallback handler for urls. + When it set to nil, Telekasten will use `xdg-open` or `open` + + Default: `nil` + Example: `"call jobstart('firefox --new-window {{url}}')"` *telekasten.calendar_opts* ----------------------------------- Valid keys for {opts.calendar_opts} diff --git a/lua/telekasten.lua b/lua/telekasten.lua index d85f207..6a57dc0 100644 --- a/lua/telekasten.lua +++ b/lua/telekasten.lua @@ -156,6 +156,9 @@ local function defaultConfig(home) -- "catimg-previewer" if you have catimg installed -- "viu-previewer" if you have viu installed media_previewer = "telescope-media-files", + + -- A customizable fallback handler for urls. + follow_url_fallback = nil, } M.Cfg = cfg M.note_type_templates = { @@ -1473,6 +1476,11 @@ local function check_for_link_or_tag() end local function follow_url(url) + if M.Cfg.follow_url_fallback then + local cmd = string.gsub(M.Cfg.follow_url_fallback, "{{url}}", url) + return vim.cmd(cmd) + end + -- we just leave it to the OS's handler to deal with what kind of URL it is local function format_command(cmd) return 'call jobstart(["'