summaryrefslogtreecommitdiff
path: root/config/nvim/lua/compile.lua
diff options
context:
space:
mode:
authorRaghuram Subramani <raghus2247@gmail.com>2024-01-27 12:45:54 +0530
committerRaghuram Subramani <raghus2247@gmail.com>2024-01-27 12:45:54 +0530
commit05f9bc5afd5ac5f671f1dcd3d20774b0987545ec (patch)
treeaa1a9fbe816b5217f6827ae2a41481f762c6c7f4 /config/nvim/lua/compile.lua
parentcc5a352e65e533cc84358a546c9ee6f1d5a47908 (diff)
refactor dotfiles, and use nix
Diffstat (limited to 'config/nvim/lua/compile.lua')
-rw-r--r--config/nvim/lua/compile.lua38
1 files changed, 38 insertions, 0 deletions
diff --git a/config/nvim/lua/compile.lua b/config/nvim/lua/compile.lua
new file mode 100644
index 0000000..f529b90
--- /dev/null
+++ b/config/nvim/lua/compile.lua
@@ -0,0 +1,38 @@
+local openTerminal = function(command)
+ local Terminal = require('toggleterm.terminal').Terminal
+ local term = Terminal:new({
+ cmd = command,
+ direction = 'horizontal'
+ })
+ term:toggle()
+end
+
+local path = vim.fn.getcwd() .. '/.compile'
+
+local run = function()
+ local file_exists = os.rename(path, path)
+
+ if file_exists then
+ openTerminal(
+ 'echo "Directory: $(pwd)"; echo "Compilation started at $(date +"%H:%M:%S")"; echo; '
+ .. 'bash ' .. path ..
+ '; echo; echo "Compilation finished at $(date +"%H:%M:%S")"; read'
+ )
+ return
+ end
+
+ local file = io.open(path, 'w')
+
+ file:seek('set')
+ file:write([[#!/bin/sh
+set -xe
+]]
+ )
+ file:close()
+ print('Created ' .. path)
+ return nil
+end
+
+vim.keymap.set('n', 'zz', function()
+ run()
+end)