Skip to content

Commit 17577d1

Browse files
committed
Ghostty support
1 parent 19fb26f commit 17577d1

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

plugin/terminaldocument.vim

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,18 @@ autocmd BufEnter,BufFilePost * call s:update_document(0)
66
" these events might change the nature of the file,
77
" so we try to refresh its icon
88
autocmd BufWritePost,FileChangedShellPost,ShellCmdPost * call s:update_document(1)
9-
autocmd VimLeave * call s:set_osc6('')
9+
10+
if &term != 'xterm-ghostty'
11+
" For ghostty setting this to empty results in the path being set to "/"
12+
" At least before https://github.com/ghostty-org/ghostty/pull/3399
13+
autocmd VimLeave * call s:set_osc('')
14+
endif
1015

1116
function! s:update_document(refresh)
1217
let path = expand('%:p')
13-
if empty(path) || !filereadable(path)
18+
if empty(path)
1419
" unnamed/unsaved file being edited
15-
call s:set_osc6('')
20+
call s:set_osc('')
1621
else
1722
let path = s:urlencode(path)
1823
if a:refresh
@@ -21,14 +26,18 @@ function! s:update_document(refresh)
2126
" reference to the same file
2227
" (better than the flickering that happens when we temporarily set
2328
" to empty)
24-
call s:set_osc6('file://' . path)
29+
call s:set_osc('file://localhost' . path)
2530
endif
26-
call s:set_osc6('file://' . hostname() . path)
31+
call s:set_osc('file://' . hostname() . path)
2732
endif
2833
endfunction
2934

30-
function! s:set_osc6(pt)
31-
call system('printf "\e]6;%s\a" >/dev/tty ' . shellescape(a:pt))
35+
function! s:set_osc(pt)
36+
let osc = '6'
37+
if &term == 'xterm-ghostty'
38+
let osc = '7'
39+
endif
40+
call system('printf "\e]' . osc . ';%s\a" >/dev/tty ' . shellescape(a:pt))
3241
endfunction
3342

3443

0 commit comments

Comments
 (0)