Skip to content

Ask to confirm before creating the gist #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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