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

feat: copy screenshot to clipboard #6

Merged
merged 1 commit into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
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
28 changes: 23 additions & 5 deletions lua/codeshot/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,47 @@ _G.codeshot_settings = {}

local function run_sss_code(codeshot_options, opts)
local extra_args = vim.tbl_extend('force', codeshot_options, opts)
local output = { output = utils.replace_placeholders(extra_args.output) }
local output = utils.replace_placeholders(extra_args.output)
local curr_theme = {}

if codeshot_options.use_current_theme then
curr_theme = { vim_theme = theme.get() }
end

local copy = false

if type(codeshot_options.copy) == 'string' and codeshot_options.copy ~= "%c" then
copy = codeshot_options.copy
output = 'raw'
end

local cmd = table.concat({
codeshot_options.bin_path,
table.concat(
utils.obj_to_args(extra_args, { 'bin_path', 'file', 'raw_input', 'use_current_theme', 'output' }),
utils.obj_to_args(
extra_args,
{ 'bin_path', 'file', 'raw_input', 'use_current_theme', 'output', 'copy', 'silent' }
),
' '
),
table.concat(utils.obj_to_args(curr_theme), ' '),
table.concat(utils.obj_to_args(output), ' '),
table.concat(utils.obj_to_args { output = output }, ' '),
-- TODO: support load code lines or file
opts.file,
}, ' ')
cmd = cmd:gsub('#', '\\#')

vim.notify(cmd)
if copy then
cmd = copy:gsub('%%c', cmd)
end

if codeshot_options.silent then
vim.cmd('silent !' .. cmd)
else
vim.cmd { cmd = '!', args = { cmd } }
end

vim.cmd { cmd = '!', args = { cmd } }
-- vim.fn.execute({ '!' .. cmd }, codeshot_options.silent and 'silent!' or '')
end

function codeshot.take(file, extension, lines, hi_lines)
Expand Down
3 changes: 2 additions & 1 deletion lua/codeshot/option.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ local defaults = {
bin_path = 'sss_code',

-- Screenshot flags
copy = false,
copy = "%c",
silent = true,
window_controls = false,
shadow = false,
shadow_image = false,
Expand Down
2 changes: 1 addition & 1 deletion lua/codeshot/theme.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function theme._theme_obj()
'SpellBad',
'Title',
'MatchParen',
'IdentBlanklineChar',
'IndentBlanklineChar',
'Number',
'Character',
'String',
Expand Down
Loading