Created
April 19, 2018 08:24
-
-
Save ryanford/3628ad22bc0f9ddd8878f53acf286637 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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