Skip to content

Commit

Permalink
Merge pull request #7 from lnc3l0t/ask-confirmation
Browse files Browse the repository at this point in the history
Ask to confirm before creating the gist
  • Loading branch information
rawnly authored May 14, 2023
2 parents af4714a + a3a44a9 commit 13dc9cb
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion doc/gist.config.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
8 changes: 4 additions & 4 deletions doc/gist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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:

Expand Down
7 changes: 7 additions & 0 deletions lua/gist/core/gh.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions lua/gist/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 13dc9cb

Please sign in to comment.