Skip to content

Commit 5750d07

Browse files
authored
Merge pull request #8 from Brayan-724/main
feat: Set filename as window title
2 parents 7e418c2 + cb6083a commit 5750d07

3 files changed

Lines changed: 15 additions & 4 deletions

File tree

lua/codeshot/init.lua

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,22 @@ local function run_sss_code(codeshot_options, opts)
1616

1717
local copy = false
1818

19-
if type(codeshot_options.copy) == 'string' and codeshot_options.copy ~= "%c" then
19+
if type(codeshot_options.copy) == 'string' and codeshot_options.copy ~= '%c' then
2020
copy = codeshot_options.copy
2121
output = 'raw'
2222
end
2323

24+
if codeshot_options.filename_as_window_title then
25+
local filename = vim.fn.expand('%:t')
26+
extra_args.window_title = filename
27+
end
28+
2429
local cmd = table.concat({
2530
codeshot_options.bin_path,
2631
table.concat(
2732
utils.obj_to_args(
2833
extra_args,
29-
{ 'bin_path', 'file', 'raw_input', 'use_current_theme', 'output', 'copy', 'silent' }
34+
{ 'bin_path', 'file', 'raw_input', 'use_current_theme', 'output', 'copy', 'silent', 'filename_as_window_title' }
3035
),
3136
' '
3237
),
@@ -64,20 +69,26 @@ end
6469
function codeshot.selected_lines()
6570
local curr = vim.fn.expand('%:p')
6671
local extension = vim.fn.expand('%:e')
72+
73+
vim.cmd([[execute "normal! \<ESC>"]])
6774
local s_start = vim.fn.getpos("'<")[2]
6875
local s_end = vim.fn.getpos("'>")[2]
6976
local lines = s_start .. '..' .. s_end
77+
7078
codeshot.take(curr, extension, lines, lines)
7179
end
7280

7381
function codeshot.focus_selected_lines()
7482
local curr = vim.fn.expand('%:p')
7583
local extension = vim.fn.expand('%:e')
84+
85+
vim.cmd([[execute "normal! \<ESC>"]])
7686
local s_start = vim.fn.getpos("'<")[2]
7787
local s_end = vim.fn.getpos("'>")[2]
7888
-- Calculate len of lines
7989
-- local n_lines = math.abs(s_end[2] - s_start[2]) + 1
8090
local hi_lines = s_start .. '..' .. s_end
91+
8192
codeshot.take(curr, extension, '..', hi_lines)
8293
end
8394

lua/codeshot/option.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ local defaults = {
66
bin_path = 'sss_code',
77

88
-- Screenshot flags
9-
copy = "%c",
9+
copy = '%c',
1010
silent = true,
1111
window_controls = false,
1212
shadow = false,
@@ -25,6 +25,7 @@ local defaults = {
2525
radius = 15,
2626
author = '',
2727
author_color = '#FFFFFF',
28+
filename_as_window_title = true,
2829
window_title = '',
2930
window_title_background = '',
3031
window_title_color = '#FFFFFF',

lua/codeshot/theme.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ function theme._theme_obj()
3737
'SpellBad',
3838
'Title',
3939
'MatchParen',
40-
'IndentBlanklineChar',
4140
'Number',
4241
'Character',
4342
'String',

0 commit comments

Comments
 (0)