Skip to content

Commit

Permalink
Merge branch 'main' into list-gists
Browse files Browse the repository at this point in the history
  • Loading branch information
rawnly authored May 14, 2023
2 parents 31b076d + 13dc9cb commit 794b2f3
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,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.

You can also list your gists and edit their files on the fly.
```vim
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
2 changes: 1 addition & 1 deletion doc/gist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ 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.
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
17 changes: 12 additions & 5 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 Expand Up @@ -72,14 +79,14 @@ end
--
-- @return table A table with the configuration properties
function M.read_config()
local ok, values = pcall(vim.api.nvim_get_var, { "gist_is_private", "gist_clipboard" })

local is_private = ok and values[1] or false
local clipboard = ok and values[2] or "+"
local ok_private, private = pcall(vim.api.nvim_get_var, "gist_is_private")
local is_private = ok_private and private or false
local ok_clipboard, clipboard = pcall(vim.api.nvim_get_var, "gist_clipboard")
local clipboard_reg = ok_clipboard and clipboard or "+"

local config = {
is_private = is_private,
clipboard = clipboard,
clipboard = clipboard_reg,
}

return config
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 794b2f3

Please sign in to comment.