diff --git a/README.md b/README.md index 9af24e6..e238449 100644 --- a/README.md +++ b/README.md @@ -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! diff --git a/doc/gist.config.txt b/doc/gist.config.txt new file mode 100644 index 0000000..5fe79ad --- /dev/null +++ b/doc/gist.config.txt @@ -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 diff --git a/doc/gist.txt b/doc/gist.txt new file mode 100644 index 0000000..2e25b8c --- /dev/null +++ b/doc/gist.txt @@ -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 diff --git a/doc/tags b/doc/tags new file mode 100644 index 0000000..177564c --- /dev/null +++ b/doc/tags @@ -0,0 +1,2 @@ +gist.config.txt gist.config.txt /*gist.config.txt* +gist.txt gist.txt /*gist.txt* diff --git a/lua/gist/core/gh.lua b/lua/gist/core/gh.lua new file mode 100644 index 0000000..f15ebac --- /dev/null +++ b/lua/gist/core/gh.lua @@ -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 diff --git a/lua/gist/init.lua b/lua/gist/init.lua new file mode 100644 index 0000000..1eccad7 --- /dev/null +++ b/lua/gist/init.lua @@ -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 diff --git a/lua/scripto/init.lua b/lua/scripto/init.lua deleted file mode 100644 index 4f747b6..0000000 --- a/lua/scripto/init.lua +++ /dev/null @@ -1,39 +0,0 @@ -local bufn = -1 -local output_bufn = -1 - -local M = {} - -print("HELLO WORLD FROM SCRIPTO") - -local function open_buffer() - if bufn == -1 then - vim.api.nvim_command("botright vnew") - bufn = vim.api.nvim_get_current_buf() - end -end - -local function show_output(output) - if output_bufn == -1 then - vim.api.nvim_command("botright new") - output_bufn = vim.api.nvim_get_current_buf() - - vim.api.nvim_buf_set_lines(output_bufn, 0, -1, false, { output }) - end -end - -M.start = function() - open_buffer() -end - -local function get_content() - local content = vim.api.nvim_buf_get_lines(bufn, 0, vim.api.nvim_buf_line_count(0), false) - return table.concat(content, "\n") -end - -M.run = function() - local content = get_content() - local output = vim.api.nvim_exec("osascript -e " + content, true) - show_output(output) -end - -return M diff --git a/plugin/gist.lua b/plugin/gist.lua new file mode 100644 index 0000000..bd0ae92 --- /dev/null +++ b/plugin/gist.lua @@ -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") diff --git a/plugin/scripto.lua b/plugin/scripto.lua deleted file mode 100644 index 754ef2f..0000000 --- a/plugin/scripto.lua +++ /dev/null @@ -1,11 +0,0 @@ -local scripto = require("scripto") - -vim.api.nvim_create_user_command("ScriptoOpen", scripto.start, { - bang = true, - desc = "spawn a new playground", -}) - -vim.api.nvim_create_user_command("ScriptoRun", scripto.run, { - bang = true, - desc = "spawn a new playground", -}) diff --git a/syntax/applescript.vim b/syntax/applescript.vim deleted file mode 100644 index 9e02d06..0000000 --- a/syntax/applescript.vim +++ /dev/null @@ -1,244 +0,0 @@ -" Vim syntax file -" Language: AppleScript -" Maintainer: Jim Eberle -" Last Change: Mar 18, 2010 -" URL: http://www.fastnlight.com/syntax/applescript.vim - -" Use :syn w/in a buffer to see language element breakdown - -if version < 600 - syntax clear -elseif exists("b:current_syntax") - finish -endif - -" --- Statement --- -syn keyword scptStmt get set count copy run global local prop property -syn keyword scptStmt close put delete duplicate exists -syn keyword scptStmt launch open print quit make move reopen save -syn keyword scptStmt saving into -hi def link scptStmt Statement - -" --- Type --- -syn keyword scptType text string number integer real color date -hi def link scptType Type - -" --- Operator --- -syn keyword scptOp div mod not and or as -syn match scptOp "[-+*/^&]" -" MacRoman single char :- (divide) -exec 'syn match scptOp "'.nr2char(214).'"' -syn match scptOp "\<\(a \)\?\(ref\( to\)\?\|reference to\)\>" -hi def link scptOp Operator - -" Containment -syn match scptIN "\" -syn match scptIN "\" -syn match scptIN "\" -syn match scptIN "\" -syn match scptIN "\" -syn match scptIN "\" -syn match scptIN "\" -syn match scptIN "\" -syn match scptIN "\" -syn match scptIN "\" -syn match scptIN "\" -hi def link scptIN scptOp - -" Equals -syn match scptEQ "=" -syn match scptEQ "\" -syn match scptEQ "\" -syn match scptEQ "\" -syn match scptEQ "\" -syn match scptEQ "\" -hi def link scptEQ scptOp - -" Not Equals -syn match scptNE "\" -syn match scptNE "\" -syn match scptNE "\" -syn match scptNE "\" -syn match scptNE "\" -syn match scptNE "\" -hi def link scptNE scptOp -" MacRoman single char /= -exec 'syn match scptNE "'.nr2char(173).'"' - -" Less Than -syn match scptLT "<" -syn match scptLT "\" -syn match scptLT "\(is \)\?less than" -syn match scptLT "\" -syn match scptLT "\" -hi def link scptLT scptOp - -" Greater Than -syn match scptGT ">" -syn match scptGT "\" -syn match scptGT "\(is \)\?greater than" -syn match scptGT "\" -syn match scptGT "\" -hi def link scptGT scptOp - -" Less Than or Equals -syn match scptLE "<=" -syn match scptLE "\" -syn match scptLE "\" -syn match scptLE "\(is \)\?less than or equal\( to\)\?" -syn match scptLE "\" -syn match scptLE "\" -hi def link scptLE scptOp -" MacRoman single char <= -exec 'syn match scptLE "'.nr2char(178).'"' - -" Greater Than or Equals -syn match scptGE ">=" -syn match scptGE "\" -syn match scptGE "\" -syn match scptGE "\(is \)\?greater than or equal\( to\)\?" -syn match scptGE "\" -syn match scptGE "\" -hi def link scptGE scptOp -" MacRoman single char >= -exec 'syn match scptGE "'.nr2char(179).'"' - -" --- Constant String --- -syn region scptString start=+"+ skip=+\\\\\|\\"+ end=+"+ -hi def link scptString String - -" --- Constant Number --- -syn match scptNumber "\<-\?\d\+\>" -hi def link scptNumber Number - -" --- Constant Float --- -syn match scptFloat display contained "\d\+\.\d*\(e[-+]\=\d\+\)\=" -syn match scptFloat display contained "\.\d\+\(e[-+]\=\d\+\)\=\>" -syn match scptFloat display contained "\d\+e[-+]\>" -hi def link scptFloat Float - -" --- Constant Boolean --- -syn keyword scptBoolean true false yes no ask -hi def link scptBoolean Boolean - -" --- Other Constants --- -syn keyword scptConst it me version pi result space tab anything -syn match scptConst "\" - -" Considering and Ignoring -syn match scptConst "\" -syn match scptConst "\" -syn match scptConst "\" -syn keyword scptConst case diacriticals expansion hyphens punctuation -hi def link scptConst Constant - -" Style -syn match scptStyle "\" -syn match scptStyle "\" -syn match scptStyle "\" -syn keyword scptStyle bold condensed expanded hidden italic outline plain -syn keyword scptStyle shadow strikethrough subscript superscript underline -hi def link scptStyle scptConst - -" Day -syn keyword scptDay Mon Tue Wed Thu Fri Sat Sun -syn keyword scptDay Monday Tuesday Wednesday Thursday Friday Saturday Sunday -syn keyword scptDay weekday -hi def link scptDay scptConst - -" Month -syn keyword scptMonth Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec -syn keyword scptMonth January February March -syn keyword scptMonth April May June -syn keyword scptMonth July August September -syn keyword scptMonth October November December -syn keyword scptMonth month -hi def link scptMonth scptConst - -" Time -syn keyword scptTime minutes hours days weeks -hi def link scptTime scptConstant - -" --- Conditional --- -syn keyword scptCond if then else -syn match scptCond "\" -hi def link scptCond Conditional - -" --- Repeat --- -syn keyword scptRepeat repeat with from to by continue -syn match scptRepeat "\" -syn match scptRepeat "\" -syn match scptRepeat "\" -syn match scptRepeat "\" -hi def link scptRepeat Repeat - -" --- Exception --- -syn keyword scptException try error -syn match scptException "\" -syn match scptException "\" -syn match scptException "\" -hi def link scptException Exception - -" --- Keyword --- -syn keyword scptKeyword end tell times exit -syn keyword scptKeyword application file alias activate -syn keyword scptKeyword script on return without given -syn keyword scptKeyword considering ignoring items delimiters -syn keyword scptKeyword some each every whose where id index item its -syn keyword scptKeyword first second third fourth fifth sixth seventh -syn keyword scptKeyword eighth ninth tenth container -syn match scptKeyword "\d\+\(st\|nd\|rd\|th\)" -syn keyword scptKeyword last front back middle named thru through -syn keyword scptKeyword before after in of the -syn match scptKeyword "\" -syn match scptKeyword "\" -syn match scptKeyword "\" -syn match scptKeyword "\" -syn match scptKeyword "\" -syn match scptKeyword "\" -syn match scptKeyword "\" -syn match scptKeyword "\" -syn match scptKeyword "\" -syn match scptKeyword "'s" -hi def link scptKeyword Keyword - -" US Units -syn keyword scptUnitUS quarts gallons ounces pounds inches feet yards miles -syn match scptUnitUS "\" -syn match scptUnitUS "\" -syn match scptUnitUS "\" -syn match scptUnitUS "\" -syn match scptUnitUS "\" -syn match scptUnitUS "\" -syn match scptUnitUS "\" -hi def link scptUnitUS scptKey - -" British Units -syn keyword scptUnitBT litres centimetres metres kilometres -syn match scptUnitBT "\" -syn match scptUnitBT "\" -syn match scptUnitBT "\" -syn match scptUnitBT "\" -hi def link scptUnitBT scptKey - -" Metric Units -syn keyword scptUnitMT liters centimeters meters kilometers grams kilograms -syn match scptUnitMT "\" -syn match scptUnitMT "\" -syn match scptUnitMT "\" -syn match scptUnitMT "\" -syn match scptUnitMT "\" -syn match scptUnitMT "\" -hi def link scptUnitMT scptKey - -" --- Comment --- -syn match scptComment "--.*" -syn match scptComment "#.*" -syn region scptComment start="(\*" end="\*)" -hi def link scptComment Comment - -" --- Todo --- -syn keyword scptTodo contained TODO FIXME XXX -hi def link scptTodo Todo - -let b:current_syntax = "applescript"