Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
rawnly committed Mar 14, 2023
1 parent 33f2d4e commit e195d84
Show file tree
Hide file tree
Showing 10 changed files with 173 additions and 298 deletions.
45 changes: 41 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,44 @@
# Scripto
# CreateGist.nvim

> Applescript playground inside NEOVIM
CreateGist.nvim is a Neovim plugin that allows you to create a GitHub Gist from the current file.
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.

```lua
use "rawnly/scripto.nvim"
## Installation

To use CreateGist.nvim, you need to have Neovim installed on your system.
You also need to have the gh command-line tool installed and configured with your GitHub account.

Once you have Neovim and gh installed, you can install CreateGist.nvim using your favorite plugin manager.
For example, if you are using vim-plug, you can add the following line to your init.vim file:

```
use "rawnly/gist.nvim"
```

## Usage

To create a Gist from the current file, use the `:CreateGist` command in Neovim.
The plugin will prompt you for a description and whether the Gist should be private or public.

```vim
:CreateGist
```

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.
You can then paste the URL into a browser to view the Gist.

## Configuration

`gist.nvim` provides a few configuration options that you can set as global params:

- `g:gist_is_private`: All the gists will be private and you won't be prompted again. Defaults to `false`
- `g:gist_clipboard`: The registry to use for copying the Gist URL. Defaults to `"+"`

## License

`gist.nvim` is released under MIT License. See [LICENSE](/LICENSE.md) for details.

## Contributing

If you find a bug or would like to contribute to `gist.nvim`, please open an issue or a pull request.
All contributions are welcome and appreciated!
18 changes: 18 additions & 0 deletions doc/gist.config.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
*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.
This is done by setting the `gist_clipboard` and `gist_privacy` variables in your `init.vim` file.

OPTIONS
None

EXAMPLES
`g:gist_clipboard = '0'` will set the clipboard to `no` by default.
`g:gist_is_private = true` will set the privacy to `secret` by default.

SEE ALSO
:help gist

AUTHOR
Federico Vitale <[email protected]>
26 changes: 26 additions & 0 deletions doc/gist.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
*gist.txt* CreateGist plugin

NAME
gist - Create a GitHub Gist from the current file

SYNOPSIS
:CreateGist

DESCRIPTION
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.

OPTIONS
None

EXAMPLES
To create a Gist from the current file, run the following command in Neovim:

:CreateGist

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.

SEE ALSO
:help gist.config

AUTHOR
Federico Vitale <[email protected]>
2 changes: 2 additions & 0 deletions doc/tags
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
gist.config.txt gist.config.txt /*gist.config.txt*
gist.txt gist.txt /*gist.txt*
55 changes: 55 additions & 0 deletions lua/gist/core/gh.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
local M = {}

--- Creates a Github gist with the specified filename and description
--
-- @param filename string The filename of the Gist
-- @param description string The description of the Gist
-- @param private boolean Wether the Gist should be private
-- @return string|nil The URL of the created Gist
-- @return number|nil The error of the command
function M.create_gist(filename, description, private)
local public_flag = private and "" or "--public"
local escaped_description = vim.fn.shellescape(description)

local cmd = string.format(
"gh gist create %s %s --filename %s -d %s",
vim.fn.expand("%"),
public_flag,
filename,
escaped_description
)

local handle = io.popen(cmd)

-- null check on handle
if handle == nil then
return nil
end

local output = handle:read("*a")
handle:close()

if vim.v.shell_error ~= 0 then
return output, vim.v.shell_error
end

local url = string.gsub(output, "\n", "")

return url, nil
end

--- Reads the configuration from the user's vimrc
-- @treturn table A table with the configuration properties
function M.read_config()
local is_private = vim.api.nvim_get_var("gist_is_private") or false
local clipboard = vim.api.nvim_get_var("gist_clipboard") or "+"

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

return config
end

return M
22 changes: 22 additions & 0 deletions lua/gist/init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
local core = require("gist.core.gh")

local M = {}

function M.create()
local config = core.read_config()

local filename = vim.fn.expand("%:t")
local description = vim.fn.input("Description: ")
local is_private = config.is_private or vim.fn.input("Create a private Gist? (y/n): ") == "y"

local url, err = core.create_gist(filename, description, is_private)

if err ~= nil then
vim.api.nvim_err_writeln("Error creating Gist: " .. err)
else
vim.api.nvim_echo({ { "URL (copied to clipboard): " .. url, "Identifier" } }, true, {})
vim.fn.setreg(config.clipboard, url)
end
end

return M
39 changes: 0 additions & 39 deletions lua/scripto/init.lua

This file was deleted.

9 changes: 9 additions & 0 deletions plugin/gist.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
local gist = require("gist")

vim.api.nvim_create_user_command("CreateGist", gist.create, {
bang = true,
desc = "Create a new gist from curretn file",
})

-- vim.cmd("helptag -n gist doc/gist.txt")
vim.cmd("helptag doc")
11 changes: 0 additions & 11 deletions plugin/scripto.lua

This file was deleted.

Loading

0 comments on commit e195d84

Please sign in to comment.