diff options
| author | Mike Vink <mike1994vink@gmail.com> | 2023-03-17 21:22:14 +0100 |
|---|---|---|
| committer | Mike Vink <mike1994vink@gmail.com> | 2023-03-17 21:22:25 +0100 |
| commit | e4781b5b08d96be1a224a2e90b519f2b749acd92 (patch) | |
| tree | e964ee010c057d86732dc43c5f38a39d82595b48 | |
| parent | 4361670912463016c2435c6b8828d7aa7b637816 (diff) | |
add weird cmd script
| -rw-r--r-- | fnl/conf/cmd.fnl | 64 | ||||
| -rw-r--r-- | fnl/conf/init.fnl | 2 |
2 files changed, 66 insertions, 0 deletions
diff --git a/fnl/conf/cmd.fnl b/fnl/conf/cmd.fnl new file mode 100644 index 0000000..b7e96ae --- /dev/null +++ b/fnl/conf/cmd.fnl @@ -0,0 +1,64 @@ +(var buf nil) +(var channel nil) + +(var static-buf nil) +(var static-channel nil) + +(fn show-buf [b split] + (local split-cmd split) + (vim.cmd split-cmd) + (local w (vim.api.nvim_get_current_win)) + (vim.api.nvim_win_set_buf w b) + w) + +(fn hide-buf [b] + (local wlist (vim.fn.win_findbuf b)) + (each [_ w (pairs wlist)] + (vim.api.nvim_win_close w false))) + +(fn visible? [b] + (if (or (= nil b) (not (vim.api.nvim_buf_is_valid b))) false) + (local wlist (vim.fn.win_findbuf b)) + (print (vim.inspect wlist)) + (< 0 (length wlist))) + +(fn open-terminal [opts] + (if (or (= nil buf) (not (vim.api.nvim_buf_is_valid buf))) + (let [b (vim.api.nvim_create_buf false true)] + (match b + 0 :error + _ (set buf b)))) + (show-buf (. opts :splitcmd)) + (if (= nil channel) + (let [c (vim.fn.termopen [vim.o.shell] + {:on_exit (fn [] + (set buf nil) + (set channel nil))})] + (match c + 0 :error + _ (set channel c))))) + +(fn cmd [cmd opts] + (if (not (visible?)) (open-terminal {:splitcmd "vertical bo split"})) + (vim.fn.chansend channel (.. cmd "\r"))) + +(fn job [opts] + (if (or (= nil static-buf) (not (vim.api.nvim_buf_is_valid static-buf))) + (let [b (vim.api.nvim_create_buf false true)] + (match b + 0 :error + _ (set static-buf b)))) + (if (= nil static-channel) + (let [c (vim.api.nvim_open_term static-buf + {:on_input (fn [] + (print :on_input))})] + (match c + 0 :error + _ (set static-channel c)))) + (local command (or (. opts :cmd) (.. vim.o.shell " -c \"echo 'hi three'\""))) + (if (not (visible? static-buf)) (show-buf static-buf "vertical bo split")) + (vim.fn.chansend static-channel (.. command "\r"))) + +(job {}) +(print static-buf) +(print static-channel) diff --git a/fnl/conf/init.fnl b/fnl/conf/init.fnl index 93e26cf..b1a0af1 100644 --- a/fnl/conf/init.fnl +++ b/fnl/conf/init.fnl @@ -8,6 +8,8 @@ (require :conf.lsp) (require :conf.events) +;; (require :conf.cmd) + (require :conf.diagnostic) ;; TODO: make a function that sets this autocommand: au BufWritePost currentfile :!curl -X POST -d "{\"previewRun\": true, \"yamlOverride\": \"$(cat % | yq -P)\", \"resources\": {\"repositories\": {\"self\": {\"refName\": \"refs/heads/branch\"}}}}" -s -H "Content-Type: application/json" -H "Authorization: Basic $WORK_AZDO_GIT_AUTH" "$WORK_AZDO_GIT_ORG_URL/Stater/_apis/pipelines/pipelineid/preview?api-version=7.1-preview.1" | jq -r '.finalYaml // .' > scratch.yaml |
