|
1 | | - |
2 | 1 | -- Actions.Lua |
3 | 2 |
|
4 | | -local Helpers = require( "tmux-compile.helpers" ) |
| 3 | +local Helpers = require("tmux-compile.helpers") |
5 | 4 |
|
6 | 5 | local Actions = {} |
7 | 6 |
|
8 | 7 | -- |
9 | 8 | -- run command in a new or existing tmux window |
10 | | -function Actions.new_window( aCmd, aWindowTitle, aErrorName ) |
| 9 | +function Actions.new_window(aCmd, aWindowName, aErrorName) |
11 | 10 | if not aCmd then |
12 | 11 | local lExtension = Helpers.get_file_extension() |
13 | | - print( "Error: " .. aErrorName .. " command not found for ." .. lExtension ) |
| 12 | + print("Error: " .. aErrorName .. " command not found for ." .. lExtension) |
14 | 13 |
|
15 | 14 | return 1 |
16 | 15 | end |
17 | 16 |
|
18 | | - if tmux_window_exists( aWindowName ) then |
19 | | - aCmd = Helpers.change_dir( aWindowName ) .. aCmd |
| 17 | + if Helpers.tmux_window_exists(aWindowName) then |
| 18 | + aCmd = Helpers.change_dir(aWindowName) .. aCmd |
20 | 19 |
|
21 | | - vim.fn.system( "tmux selectw -t " .. aWindowName .. " \\; send-keys '" .. aCmd .. "' C-m" ) |
| 20 | + vim.fn.system("tmux selectw -t " .. aWindowName .. " \\; send-keys '" .. aCmd .. "' C-m") |
22 | 21 | else |
23 | | - local lProjectDir = vim.fn.trim( |
24 | | - vim.fn.system("git rev-parse --show-toplevel 2>/dev/null || pwd") |
25 | | - ) .. " -n " |
| 22 | + local lProjectDir = vim.fn.trim(vim.fn.system("git rev-parse --show-toplevel 2>/dev/null || pwd")) .. " -n " |
26 | 23 |
|
27 | | - vim.fn.system( "tmux neww -c " .. lProjectDir .. aWindowName .. " '" .. aCmd .. "; zsh'") |
| 24 | + vim.fn.system("tmux neww -c " .. lProjectDir .. aWindowName .. " '" .. aCmd .. "; zsh'") |
28 | 25 | end |
29 | 26 | end |
30 | 27 |
|
31 | | - |
32 | 28 | -- |
33 | 29 | -- run command in an overlay pane |
34 | | -function Actions.overlay( aCmd, aSleepDuration, aWidth, aHeight, aErrorName ) |
| 30 | +function Actions.overlay(aCmd, aSleepDuration, aWidth, aHeight, aErrorName) |
35 | 31 | if not aCmd then |
36 | 32 | local lExtension = Helpers.get_file_extension() |
37 | | - print( "Error: " .. aErrorName .. " command not found for ." .. lExtension ) |
| 33 | + print("Error: " .. aErrorName .. " command not found for ." .. lExtension) |
38 | 34 |
|
39 | 35 | return 1 |
40 | 36 | end |
41 | 37 |
|
42 | | - local lProjectDir = vim.fn.trim( |
43 | | - vim.fn.system("git rev-parse --show-toplevel 2>/dev/null || pwd") |
44 | | - ) |
| 38 | + local lProjectDir = vim.fn.trim(vim.fn.system("git rev-parse --show-toplevel 2>/dev/null || pwd")) |
45 | 39 |
|
46 | | - local aCmdHead = "tmux display-popup -E -d" .. lProjectDir |
| 40 | + local aCmdHead = "tmux display-popup -E -d" .. lProjectDir |
47 | 41 | local lDimensions = " -w " .. aWidth .. "\\% -h " .. aHeight .. "\\% '" |
48 | 42 |
|
49 | | - local lSleep |
50 | | - if aSleepDuration < 0 then |
51 | | - lSleep = "; read'" |
52 | | - else |
53 | | - lSleep = "; sleep " .. aSleepDuration .. "'" |
54 | | - end |
| 43 | + local lSleep |
| 44 | + if aSleepDuration < 0 then |
| 45 | + lSleep = "; read'" |
| 46 | + else |
| 47 | + lSleep = "; sleep " .. aSleepDuration .. "'" |
| 48 | + end |
55 | 49 |
|
56 | | - vim.fn.system( aCmdHead .. lDimensions .. aCmd .. lSleep ) |
| 50 | + vim.fn.system(aCmdHead .. lDimensions .. aCmd .. lSleep) |
57 | 51 | end |
58 | 52 |
|
59 | | - |
60 | 53 | -- |
61 | 54 | -- run command in same window on a new pane |
62 | | -function Actions.split_window( aCmd, aSide, aWidth, aHeight, aNewPane, aErrorName ) |
| 55 | +function Actions.split_window(aCmd, aSide, aWidth, aHeight, aNewPane, aErrorName) |
63 | 56 | if not aCmd then |
64 | 57 | local lExtension = Helpers.get_file_extension() |
65 | | - print( "Error: " .. aErrorName .. " command not found for ." .. lExtension ) |
| 58 | + print("Error: " .. aErrorName .. " command not found for ." .. lExtension) |
66 | 59 |
|
67 | 60 | return 1 |
68 | 61 | end |
69 | 62 |
|
70 | 63 | local lDirectionLookup = { |
71 | 64 | v = "-D", |
72 | | - h = "-R" |
| 65 | + h = "-R", |
73 | 66 | } |
74 | 67 |
|
75 | 68 | local lLengthPercentage = { |
76 | 69 | v = aHeight, |
77 | | - h = aWidth |
| 70 | + h = aWidth, |
78 | 71 | } |
79 | 72 |
|
80 | | - local lCurrentPane = vim.fn.system( "tmux display -p '#{pane_id}'" ) |
81 | | - vim.fn.system( "tmux selectp " .. lDirectionLookup[aSide] ) |
82 | | - local lMovedPane = vim.fn.system( "tmux display -p '#{pane_id}'" ) |
| 73 | + local lCurrentPane = vim.fn.system("tmux display -p '#{pane_id}'") |
| 74 | + vim.fn.system("tmux selectp " .. lDirectionLookup[aSide]) |
| 75 | + local lMovedPane = vim.fn.system("tmux display -p '#{pane_id}'") |
83 | 76 |
|
84 | | - aCmd = Helpers.change_dir( vim.trim(lMovedPane) ) .. aCmd |
| 77 | + aCmd = Helpers.change_dir(vim.trim(lMovedPane)) .. aCmd |
85 | 78 |
|
86 | | - if ( vim.trim(lCurrentPane) == vim.trim(lMovedPane) or aNewPane ) then |
| 79 | + if vim.trim(lCurrentPane) == vim.trim(lMovedPane) or aNewPane then |
87 | 80 | local lParameters = aSide .. " -l " .. lLengthPercentage[aSide] .. "%" |
88 | 81 | vim.fn.system("tmux splitw -" .. lParameters .. " '" .. aCmd .. "; zsh'") |
89 | 82 | else |
90 | | - vim.fn.system( "tmux send -t " .. vim.trim(lMovedPane) .. " '" .. aCmd .. "' C-m" ) |
| 83 | + vim.fn.system("tmux send -t " .. vim.trim(lMovedPane) .. " '" .. aCmd .. "' C-m") |
91 | 84 | end |
92 | 85 |
|
93 | | - -- return to nvim pane |
94 | | - vim.fn.system( "tmux select-pane -l" ) |
| 86 | + -- return to nvim pane |
| 87 | + vim.fn.system("tmux select-pane -l") |
95 | 88 | end |
96 | 89 |
|
97 | | - |
98 | 90 | -- |
99 | 91 | -- run lazygit in an overlay pane |
100 | | -function Actions.lazygit( aWidth, aHeight ) |
101 | | - if vim.fn.executable( "lazygit" ) == 1 then |
102 | | - Actions.overlay( "lazygit", 0, aWidth, aHeight, aErrorName ) |
| 92 | +function Actions.lazygit(aWidth, aHeight, aErrorName) |
| 93 | + if vim.fn.executable("lazygit") == 1 then |
| 94 | + Actions.overlay("lazygit", 0, aWidth, aHeight, aErrorName) |
103 | 95 | else |
104 | | - print( "Error: lazygit not installed." ) |
| 96 | + print("Error: lazygit not installed.") |
105 | 97 | end |
106 | 98 | end |
107 | 99 |
|
108 | | - |
109 | 100 | return Actions |
110 | | - |
0 commit comments