Skip to content

Commit

Permalink
feat: add zellij support
Browse files Browse the repository at this point in the history
Very rudimentary, draft to support zellij.
  • Loading branch information
Maxim Onciul committed Mar 25, 2024
1 parent 649f079 commit c18d46d
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 8 deletions.
32 changes: 26 additions & 6 deletions autoload/tpipeline.vim
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,33 @@ endif
let s:exit_code = -1

func tpipeline#get_filepath()
" e.g. /tmp/tmux-1000/default-$0-vimbridge
let tmux = $TMUX
if empty(tmux)
let p = "/tmp/tmux-" . systemlist("id -u")[-1]

if !empty($ZELLIJ)
" e.g. /tmp/zjstatus-$UID/$SESSION_NAME-$PANE_ID-vimbridge
let p = "/tmp/zjstatus-" . systemlist("id -u")[-1]
silent! call mkdir(p)
let tmux = p . "/default,0,0"
let session = $ZELLIJ_SESSION_NAME
" TODO: wait for https://github.com/zellij-org/zellij/issues/2835
" so we can identify the currently active pane. Now I have to hardcode it
" to zjstatus - so no reason to use the variable here, yet.
" let paneid = $ZELLIJ_PANE_ID
let paneid = "0"
let p = p . "/"
let zellij = p . session . "-" . paneid . "-vimbridge"
return zellij
endif


if !empty($TMUX)
" e.g. /tmp/tmux-1000/default-$0-vimbridge
let tmux = $TMUX
if empty(tmux)
let p = "/tmp/tmux-" . systemlist("id -u")[-1]
silent! call mkdir(p)
let tmux = p . "/default,0,0"
endif
return strcharpart(tmux, 0, stridx(tmux, ",")) . '-$' . strcharpart(tmux, strridx(tmux, ",") + 1) . '-vimbridge'
endif
return strcharpart(tmux, 0, stridx(tmux, ",")) . '-$' . strcharpart(tmux, strridx(tmux, ",") + 1) . '-vimbridge'
endfunc

func tpipeline#build_hooks()
Expand Down Expand Up @@ -169,6 +188,7 @@ func tpipeline#exit_cb(job, code)
endfunc

func tpipeline#fork_job()
" TODO: for ZELLIJ, only do what is necessary
if g:tpipeline_restore
let s:restore_left = systemlist("sh -c 'echo \"\"; tmux display-message -p \"#{status-left}\"'")[-1]
let s:restore_right = systemlist("sh -c 'echo \"\"; tmux display-message -p \"#{status-right}\"'")[-1]
Expand Down
7 changes: 6 additions & 1 deletion autoload/tpipeline/util.vim
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ func tpipeline#util#left_justify(str)
endfunc

func tpipeline#util#set_size()
let g:tpipeline_size = str2nr(systemlist("sh -c 'echo \"\"; tmux display-message -p \"#{window_width}\"'")[-1])
if !empty($TMUX)
let g:tpipeline_size = str2nr(systemlist("sh -c 'echo \"\"; tmux display-message -p \"#{window_width}\"'")[-1])
elseif !empty($ZELLIJ)
" TODO: verify if this is reasonable.
let g:tpipeline_size = str2nr(systemlist("sh -c 'tput cols'")[-1])
endif
endfunc

func tpipeline#util#set_custom_size()
Expand Down
2 changes: 1 addition & 1 deletion plugin/tpipeline.vim
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
if exists('g:loaded_tpipeline') || (empty($TMUX) && !exists("g:tpipeline_refreshcmd")) || !(has('nvim-0.6') ? len(nvim_list_uis()) : (has('job') && has('patch-8.2.4650'))) || has('gui_running')
if exists('g:loaded_tpipeline') || (empty($ZELLIJ) && empty($TMUX) && !exists("g:tpipeline_refreshcmd")) || !(has('nvim-0.6') ? len(nvim_list_uis()) : (has('job') && has('patch-8.2.4650'))) || has('gui_running')
finish
endif
let g:loaded_tpipeline = 1
Expand Down

0 comments on commit c18d46d

Please sign in to comment.