Skip to content

Commit 794b2f3

Browse files
authored
Merge branch 'main' into list-gists
2 parents 31b076d + 13dc9cb commit 794b2f3

File tree

5 files changed

+16
-8
lines changed

5 files changed

+16
-8
lines changed

README.md

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

62-
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.
62+
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.
6363

6464
You can also list your gists and edit their files on the fly.
6565
```vim

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ EXAMPLES
2525
:CreateGistFile [description] [public=true]
2626

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

3030
To Create a Gist from current selection, run the following command in Neovim:
3131

lua/gist/core/gh.lua

+12-5
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
@@ -72,14 +79,14 @@ end
7279
--
7380
-- @return table A table with the configuration properties
7481
function M.read_config()
75-
local ok, values = pcall(vim.api.nvim_get_var, { "gist_is_private", "gist_clipboard" })
76-
77-
local is_private = ok and values[1] or false
78-
local clipboard = ok and values[2] or "+"
82+
local ok_private, private = pcall(vim.api.nvim_get_var, "gist_is_private")
83+
local is_private = ok_private and private or false
84+
local ok_clipboard, clipboard = pcall(vim.api.nvim_get_var, "gist_clipboard")
85+
local clipboard_reg = ok_clipboard and clipboard or "+"
7986

8087
local config = {
8188
is_private = is_private,
82-
clipboard = clipboard,
89+
clipboard = clipboard_reg,
8390
}
8491

8592
return config

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)