From a3a44a94316645c602a4bc949404d02b6e894b90 Mon Sep 17 00:00:00 2001 From: lnc3l0t Date: Sat, 13 May 2023 11:17:17 +0200 Subject: [PATCH] feat: added confirmation prompt before creating gist The plugin by default doesn't create the gist if the user doens't type 'y' at the end of 'CreateGist' flow --- README.md | 2 +- doc/gist.config.txt | 2 +- doc/gist.txt | 8 ++++---- lua/gist/core/gh.lua | 7 +++++++ lua/gist/init.lua | 1 + 5 files changed, 14 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 939c717..9807920 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ Both the commands accept the same options which are `[description=]` and `[publi If you don't pass the `description` it will prompt to insert one later. If you pass `[public=true]` it won't prompt for privacy later. -After you enter the description and privacy settings, the plugin will create the Gist using the gh command-line tool and copy the Gist's URL to the given clipboard registry. +After you enter the description and privacy settings, the plugin ask for confirmation and will create the Gist using the gh command-line tool and copy the Gist's URL to the given clipboard registry. ## Configuration diff --git a/doc/gist.config.txt b/doc/gist.config.txt index 5fe79ad..5b7b6bf 100644 --- a/doc/gist.config.txt +++ b/doc/gist.config.txt @@ -1,7 +1,7 @@ *gist.config.txt* CreateGist configuration DESCRIPTION - The `:CreateGist` command can be configured to avoid prompting the user for the privacy settings of the Gist and target clipboard. + The `:CreateGist` command can be configured to avoid prompting the user for the privacy settings of the Gist and target clipboard. This is done by setting the `gist_clipboard` and `gist_privacy` variables in your `init.vim` file. OPTIONS diff --git a/doc/gist.txt b/doc/gist.txt index 46346a1..974fb95 100644 --- a/doc/gist.txt +++ b/doc/gist.txt @@ -8,8 +8,8 @@ SYNOPSIS :CreateGistFromFile DESCRIPTION - The `:CreateGist` command creates a GitHub Gist from the buffer selection using the `gh` command-line tool. - The `:CreateGistFile` command creates a GitHub Gist from the current file using the `gh` command-line tool. + The `:CreateGist` command creates a GitHub Gist from the buffer selection using the `gh` command-line tool. + The `:CreateGistFile` command creates a GitHub Gist from the current file using the `gh` command-line tool. The plugin prompts you for a description and privacy settings for the Gist, and then copies the URL of the created Gist to the system clipboard. @@ -22,8 +22,8 @@ EXAMPLES :CreateGistFile [description] [public=true] - The plugin will prompt you for a description and privacy settings for the Gist. - After you enter the description and privacy settings, the plugin will create the Gist using the `gh` command-line tool and copy the URL of the created Gist to the system clipboard. + The plugin will prompt you for a description and privacy settings for the Gist. + After you enter the description and privacy settings, the plugin will ask for confirmation and create the Gist using the `gh` command-line tool and copy the URL of the created Gist to the system clipboard. To Create a Gist from current selection, run the following command in Neovim: diff --git a/lua/gist/core/gh.lua b/lua/gist/core/gh.lua index 06d2a99..e240c0c 100644 --- a/lua/gist/core/gh.lua +++ b/lua/gist/core/gh.lua @@ -29,6 +29,13 @@ function M.create_gist(filename, content, description, private) ) end + local ans = vim.fn.input("Do you want to create gist " .. filename .. " (y/n)? ") + if ans ~= "y" then + vim.cmd.redraw() + vim.notify("Gist creation aborted", vim.log.levels.INFO) + return + end + local output = utils.exec(cmd, content) if vim.v.shell_error ~= 0 then diff --git a/lua/gist/init.lua b/lua/gist/init.lua index ba4fac1..3a8024a 100644 --- a/lua/gist/init.lua +++ b/lua/gist/init.lua @@ -29,6 +29,7 @@ local function create(content, ctx) local details = get_details(ctx) local url, err = core.create_gist(details.filename, content, details.description, details.is_private) + if not url then return end if err ~= nil then vim.api.nvim_err_writeln("Error creating Gist: " .. err)