Extend vim_rest_console_extensions with auto filename generation

pull/2/head
Ensar Sarajčić 2021-10-04 14:50:45 +02:00
parent f56683ae0f
commit e859bfc65d
3 changed files with 38 additions and 5 deletions

View File

@ -0,0 +1,19 @@
-------------------------------------------------------------------------------
-- - Common projects library -
-------------------------------------------------------------------------------
local M = {}
-- Gets project root directory based on projectionist
function M.get_project_root()
return vim.fn['projectionist#path']()
end
-- Get unique project ID based on git repository
function M.get_project_id()
local remote_url = vim.fn['fugitive#RemoteUrl']()
remote_url = remote_url:gsub("/", ":")
return remote_url
end
return M

View File

@ -42,12 +42,26 @@ function M.open_scratch_rest_console()
end end
-- Opens up a rest console which can be saved -- cached by name -- Opens up a rest console which can be saved -- cached by name
function M.open_cached_rest_console(name) function M.open_cached_rest_console(...)
local name = select(1, ...)
if (select('#', ...) == 0) then
name = require'common.projects'.get_project_id()
end
open_cached_rest_console(name)
end
-- Opens up a rest console which can be saved -- cached by name
function M.open_named_cached_rest_console(name)
name = require'common.projects'.get_project_id() .. name
open_cached_rest_console(name) open_cached_rest_console(name)
end end
-- Opens up a rest console based on local file path -- Opens up a rest console based on local file path
function M.open_rest_console(file) function M.open_local_rest_console(...)
local file = select(1, ...)
if (select('#', ...) == 0) then
file = 'default'
end
open_rest_console(file) open_rest_console(file)
end end

View File

@ -3,6 +3,6 @@
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
vim.cmd[[command! -nargs=0 ScratchRestConsole :lua require('vim_rest_console_extensions').open_scratch_rest_console()]] vim.cmd[[command! -nargs=0 ScratchRestConsole :lua require('vim_rest_console_extensions').open_scratch_rest_console()]]
vim.cmd[[command! -nargs=1 RestConsole :lua require('vim_rest_console_extensions').open_cached_rest_console(<f-args>)]] vim.cmd[[command! -nargs=? RestConsole :lua require('vim_rest_console_extensions').open_cached_rest_console(<f-args>)]]
vim.cmd[[command! -nargs=1 RestConsoleLocal :lua require('vim_rest_console_extensions').open_local_rest_console(<f-args>)]] vim.cmd[[command! -nargs=? RestConsoleLocal :lua require('vim_rest_console_extensions').open_local_rest_console(<f-args>)]]
vim.cmd[[command! -nargs=1 RestConsoleCached :lua require('vim_rest_console_extensions').open_cached_rest_console(<f-args>)]] vim.cmd[[command! -nargs=1 RestConsoleCached :lua require('vim_rest_console_extensions').open_named_cached_rest_console(<f-args>)]]