-
-
Notifications
You must be signed in to change notification settings - Fork 22
/
tmux.lua
47 lines (35 loc) · 1.04 KB
/
tmux.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
local T = {}
local TMUX = os.getenv('TMUX')
local TMUX_PANE = os.getenv('TMUX_PANE')
local tmux_directions = {
p = 'l',
h = 'L',
k = 'U',
l = 'R',
j = 'D',
}
-- Do we really using tmux
T.is_tmux = TMUX ~= nil
-- For getting tmux socket
function T.get_socket()
-- The socket path is the first value in the comma-separated list of $TMUX.
return vim.split(TMUX, ',')[1]
end
-- For executing a tmux command
function T.execute(arg)
local t_cmd = string.format('tmux -S %s %s', T.get_socket(), arg)
local handle = assert(io.popen(t_cmd), string.format('Navigator: Unable to execute > [%s]', t_cmd))
local result = handle:read()
handle:close()
return result
end
-- For execting `tmux select-pane` command
function T.change_pane(direction)
local arg = string.format("select-pane -t '%s' -%s", TMUX_PANE, tmux_directions[direction])
T.execute(arg)
end
function T.is_zoomed()
-- if result is 1 then tmux pane is zoomed
return T.execute("display-message -p '#{window_zoomed_flag}'") == '1'
end
return T