Skip to content

Commit e195d84

Browse files
committed
first commit
1 parent 33f2d4e commit e195d84

File tree

10 files changed

+173
-298
lines changed

10 files changed

+173
-298
lines changed

README.md

+41-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,44 @@
1-
# Scripto
1+
# CreateGist.nvim
22

3-
> Applescript playground inside NEOVIM
3+
CreateGist.nvim is a Neovim plugin that allows you to create a GitHub Gist from the current file.
4+
The plugin uses the gh command-line tool to create the Gist and provides a simple interface for specifying the Gist's description and privacy settings.
45

5-
```lua
6-
use "rawnly/scripto.nvim"
6+
## Installation
7+
8+
To use CreateGist.nvim, you need to have Neovim installed on your system.
9+
You also need to have the gh command-line tool installed and configured with your GitHub account.
10+
11+
Once you have Neovim and gh installed, you can install CreateGist.nvim using your favorite plugin manager.
12+
For example, if you are using vim-plug, you can add the following line to your init.vim file:
13+
14+
```
15+
use "rawnly/gist.nvim"
16+
```
17+
18+
## Usage
19+
20+
To create a Gist from the current file, use the `:CreateGist` command in Neovim.
21+
The plugin will prompt you for a description and whether the Gist should be private or public.
22+
23+
```vim
24+
:CreateGist
725
```
26+
27+
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 system clipboard.
28+
You can then paste the URL into a browser to view the Gist.
29+
30+
## Configuration
31+
32+
`gist.nvim` provides a few configuration options that you can set as global params:
33+
34+
- `g:gist_is_private`: All the gists will be private and you won't be prompted again. Defaults to `false`
35+
- `g:gist_clipboard`: The registry to use for copying the Gist URL. Defaults to `"+"`
36+
37+
## License
38+
39+
`gist.nvim` is released under MIT License. See [LICENSE](/LICENSE.md) for details.
40+
41+
## Contributing
42+
43+
If you find a bug or would like to contribute to `gist.nvim`, please open an issue or a pull request.
44+
All contributions are welcome and appreciated!

doc/gist.config.txt

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
*gist.config.txt* CreateGist configuration
2+
3+
DESCRIPTION
4+
The `:CreateGist` command can be configured to avoid prompting the user for the privacy settings of the Gist and target clipboard.
5+
This is done by setting the `gist_clipboard` and `gist_privacy` variables in your `init.vim` file.
6+
7+
OPTIONS
8+
None
9+
10+
EXAMPLES
11+
`g:gist_clipboard = '0'` will set the clipboard to `no` by default.
12+
`g:gist_is_private = true` will set the privacy to `secret` by default.
13+
14+
SEE ALSO
15+
:help gist
16+
17+
AUTHOR
18+
Federico Vitale <[email protected]>

doc/gist.txt

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
*gist.txt* CreateGist plugin
2+
3+
NAME
4+
gist - Create a GitHub Gist from the current file
5+
6+
SYNOPSIS
7+
:CreateGist
8+
9+
DESCRIPTION
10+
The `:CreateGist` 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.
11+
12+
OPTIONS
13+
None
14+
15+
EXAMPLES
16+
To create a Gist from the current file, run the following command in Neovim:
17+
18+
:CreateGist
19+
20+
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.
21+
22+
SEE ALSO
23+
:help gist.config
24+
25+
AUTHOR
26+
Federico Vitale <[email protected]>

doc/tags

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
gist.config.txt gist.config.txt /*gist.config.txt*
2+
gist.txt gist.txt /*gist.txt*

lua/gist/core/gh.lua

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
local M = {}
2+
3+
--- Creates a Github gist with the specified filename and description
4+
--
5+
-- @param filename string The filename of the Gist
6+
-- @param description string The description of the Gist
7+
-- @param private boolean Wether the Gist should be private
8+
-- @return string|nil The URL of the created Gist
9+
-- @return number|nil The error of the command
10+
function M.create_gist(filename, description, private)
11+
local public_flag = private and "" or "--public"
12+
local escaped_description = vim.fn.shellescape(description)
13+
14+
local cmd = string.format(
15+
"gh gist create %s %s --filename %s -d %s",
16+
vim.fn.expand("%"),
17+
public_flag,
18+
filename,
19+
escaped_description
20+
)
21+
22+
local handle = io.popen(cmd)
23+
24+
-- null check on handle
25+
if handle == nil then
26+
return nil
27+
end
28+
29+
local output = handle:read("*a")
30+
handle:close()
31+
32+
if vim.v.shell_error ~= 0 then
33+
return output, vim.v.shell_error
34+
end
35+
36+
local url = string.gsub(output, "\n", "")
37+
38+
return url, nil
39+
end
40+
41+
--- Reads the configuration from the user's vimrc
42+
-- @treturn table A table with the configuration properties
43+
function M.read_config()
44+
local is_private = vim.api.nvim_get_var("gist_is_private") or false
45+
local clipboard = vim.api.nvim_get_var("gist_clipboard") or "+"
46+
47+
local config = {
48+
is_private = is_private,
49+
clipboard = clipboard,
50+
}
51+
52+
return config
53+
end
54+
55+
return M

lua/gist/init.lua

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
local core = require("gist.core.gh")
2+
3+
local M = {}
4+
5+
function M.create()
6+
local config = core.read_config()
7+
8+
local filename = vim.fn.expand("%:t")
9+
local description = vim.fn.input("Description: ")
10+
local is_private = config.is_private or vim.fn.input("Create a private Gist? (y/n): ") == "y"
11+
12+
local url, err = core.create_gist(filename, description, is_private)
13+
14+
if err ~= nil then
15+
vim.api.nvim_err_writeln("Error creating Gist: " .. err)
16+
else
17+
vim.api.nvim_echo({ { "URL (copied to clipboard): " .. url, "Identifier" } }, true, {})
18+
vim.fn.setreg(config.clipboard, url)
19+
end
20+
end
21+
22+
return M

lua/scripto/init.lua

-39
This file was deleted.

plugin/gist.lua

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
local gist = require("gist")
2+
3+
vim.api.nvim_create_user_command("CreateGist", gist.create, {
4+
bang = true,
5+
desc = "Create a new gist from curretn file",
6+
})
7+
8+
-- vim.cmd("helptag -n gist doc/gist.txt")
9+
vim.cmd("helptag doc")

plugin/scripto.lua

-11
This file was deleted.

0 commit comments

Comments
 (0)