Skip to content

Commit 13dc9cb

Browse files
authored
Merge pull request #7 from lnc3l0t/ask-confirmation
Ask to confirm before creating the gist
2 parents af4714a + a3a44a9 commit 13dc9cb

File tree

5 files changed

+14
-6
lines changed

5 files changed

+14
-6
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Both the commands accept the same options which are `[description=]` and `[publi
3232
If you don't pass the `description` it will prompt to insert one later.
3333
If you pass `[public=true]` it won't prompt for privacy later.
3434

35-
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.
35+
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.
3636

3737
## Configuration
3838

doc/gist.config.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
*gist.config.txt* CreateGist configuration
22

33
DESCRIPTION
4-
The `:CreateGist` command can be configured to avoid prompting the user for the privacy settings of the Gist and target clipboard.
4+
The `:CreateGist` command can be configured to avoid prompting the user for the privacy settings of the Gist and target clipboard.
55
This is done by setting the `gist_clipboard` and `gist_privacy` variables in your `init.vim` file.
66

77
OPTIONS

doc/gist.txt

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ SYNOPSIS
88
:CreateGistFromFile
99

1010
DESCRIPTION
11-
The `:CreateGist` command creates a GitHub Gist from the buffer selection using the `gh` command-line tool.
12-
The `:CreateGistFile` command creates a GitHub Gist from the current file using the `gh` command-line tool.
11+
The `:CreateGist` command creates a GitHub Gist from the buffer selection using the `gh` command-line tool.
12+
The `:CreateGistFile` command creates a GitHub Gist from the current file using the `gh` command-line tool.
1313

1414
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.
1515

@@ -22,8 +22,8 @@ EXAMPLES
2222

2323
:CreateGistFile [description] [public=true]
2424

25-
The plugin will prompt you for a description and privacy settings for the Gist.
26-
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.
25+
The plugin will prompt you for a description and privacy settings for the Gist.
26+
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.
2727

2828
To Create a Gist from current selection, run the following command in Neovim:
2929

lua/gist/core/gh.lua

+7
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ function M.create_gist(filename, content, description, private)
2929
)
3030
end
3131

32+
local ans = vim.fn.input("Do you want to create gist " .. filename .. " (y/n)? ")
33+
if ans ~= "y" then
34+
vim.cmd.redraw()
35+
vim.notify("Gist creation aborted", vim.log.levels.INFO)
36+
return
37+
end
38+
3239
local output = utils.exec(cmd, content)
3340

3441
if vim.v.shell_error ~= 0 then

lua/gist/init.lua

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ local function create(content, ctx)
2929
local details = get_details(ctx)
3030

3131
local url, err = core.create_gist(details.filename, content, details.description, details.is_private)
32+
if not url then return end
3233

3334
if err ~= nil then
3435
vim.api.nvim_err_writeln("Error creating Gist: " .. err)

0 commit comments

Comments
 (0)