Skip to content

Instantly share code, notes, and snippets.

@ryanford
Created April 19, 2018 08:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryanford/3628ad22bc0f9ddd8878f53acf286637 to your computer and use it in GitHub Desktop.
Save ryanford/3628ad22bc0f9ddd8878f53acf286637 to your computer and use it in GitHub Desktop.
-- luacheck: globals vim
local format = string.format
local name = vim.buffer().fname
local temp_name = os.tmpname()
local temp = io.open(temp_name, "w+")
local content
local ext = (name:match("%.%w+$") or ".txt"):sub(2):lower()
local dictionary = {
sh = "bash",
c = "c",
css = "css",
html = "html",
js = "js",
json = "json",
lua = "lua",
rb = "ruby"
}
ext = dictionary[ext] or "text"
vim.command(":%y")
content = vim.eval("@\"")
temp:write(content)
temp:seek("set", 0)
temp:close()
local status, err = assert(os.execute(format("pastebinit -f %s -i %s | xclip -selection clipboard", ext, temp_name)))
assert(os.execute("rm "..temp_name) == 0)
print(status == 0 and "OK" or err)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment