Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Talagrip #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions vim_plugins/lua/talagrip.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
require('io')
require('os')


function strip(s)
s = string.gsub(s, '^%s+', '')
s = string.gsub(s, '%s+$', '')
s = string.gsub(s, '[\n\r]+', '')
return s
end

function get_query()
viml = [[
function! Get_query()
let [line_start, column_start] = getpos(.)[1:2]
let [line_end, column_end] = getpos("'>")[1:2]
let lines = getline(line_start, line_end)
if len(lines) == 0
return ''
endif
let lines[-1] = lines[-1][: column_end - (&selection == 'inclusive' ? 1 : 2)]
let lines[0] = lines[0][column_start - 1:]
return join(lines, "\n")
endfunction
]]
return vim.api.nvim_exec(viml, true)
end

function run()
query = get_query()
print(query)

config_path = os.getenv("HOME") .. "/.ssh/dev_db.config"

db_conf = {}
for config_line in io.lines(config_path) do
for k, v in string.gmatch(config_line, "(.+)=(.+)") do
db_conf[strip(k)] = strip(v)
end
end

--conn = db_conf["DB_TYPE"] .. "://" .. db_conf["USER_NAME"] .. ":" .. db_conf["PASSWORD"] .. "@" .. db_conf["URL"]
conn = string.format("%s://%s:%s@:%s", db_conf["DB_TYPE"], db_conf["USER_NAME"], db_conf["PASSWORD"], db_conf["URL"])
query = "SHOW DATABASES"
command = "DB " .. conn .. " " .. query

--vim.api.nvim_command(command)
end


test = [[
asdas
11111111
222222
333333
444444
]]


vim.api.nvim_set_keymap("n", "<CR>", ":lua require('talagrip').run()<CR>", { nowait = true, noremap = true, silent = true })

return {
run = run
}