Last active
February 22, 2021 15:38
-
-
Save pfitzseb/a6529654c1d6faf2ba144aa8616a31aa to your computer and use it in GitHub Desktop.
edit in existing tmux pane that runs `vim`
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# put this in your startup.jl | |
using InteractiveUtils | |
let | |
tmuxsession = nothing | |
sessions = split(String(read(`tmux list-panes -a -F '#{pane_tty} #{session_name}'`)), '\n') | |
io = IOBuffer() | |
run(pipeline(`tty`, stdout=io)) | |
tty = chomp(String(take!(io))) | |
for session in sessions | |
if occursin(tty, session) | |
tmuxsession = split(session)[2] | |
break | |
end | |
end | |
if tmuxsession ≠ nothing | |
InteractiveUtils.eval(quote | |
function InteractiveUtils.edit(path::AbstractString, line::Integer=0) | |
tmuxsession = $(tmuxsession) | |
tmuxpanes = split(chomp(String(read(`tmux list-panes -F '#{pane_id} #{pane_current_command}'`))), '\n') | |
pane = nothing | |
for tpane in tmuxpanes | |
pane_id, program = split(tpane) | |
if occursin("vim", program) | |
pane = pane_id | |
break | |
end | |
end | |
if endswith(path, ".jl") | |
f = Base.find_source_file(path) | |
f !== nothing && (path = f) | |
end | |
run(`tmux send-keys -t $(tmuxsession).$(pane) Escape :edit Space $(path) Enter :$(line) Enter`) | |
nothing | |
end | |
end) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment