forked from Archives/vimux
Compare commits
78 Commits
Author | SHA1 | Date |
---|---|---|
spike | a62c16c8c3 | 2 years ago |
spike | 3c0a1708dc | 2 years ago |
Michael van der Kamp | 616fcb4799 | 2 years ago |
Michael van der Kamp | 2344b96fed | 2 years ago |
Michael van der Kamp | 076e13b77c | 2 years ago |
Michael van der Kamp | 740320b798 | 2 years ago |
Michael van der Kamp | 3daa0e91f0 | 2 years ago |
Matthias Bilger | 89604a4464 | 3 years ago |
Michael van der Kamp | 028897b6fb | 3 years ago |
Matthias Bilger | 031cc6208e | 3 years ago |
Samuel Walladge | 853646aef3 | 3 years ago |
Michael van der Kamp | 55a470dc0d | 3 years ago |
Michael van der Kamp | a1650d5f9b | 3 years ago |
John Bredall | ee0dfae330 | 3 years ago |
Caleb Maclennan | ee3075ad30 | 3 years ago |
Caleb Maclennan | 96a47f7895 | 3 years ago |
Caleb Maclennan | 708ce200d5 | 3 years ago |
jaspertandy | a70218b30c | 3 years ago |
jaspertandy | 59b1d28f80 | 3 years ago |
jaspertandy | 784b2834c7 | 3 years ago |
Caleb Maclennan | 29d46f6bc1 | 3 years ago |
Michael van der Kamp | 7d977a2954 | 3 years ago |
Michael van der Kamp | c4adf57f6e | 3 years ago |
Michael van der Kamp | 54d24d1694 | 3 years ago |
Gerhard Hellmann | 5b1791673c | 3 years ago |
Caleb Maclennan | 3bfe0ea285 | 3 years ago |
Caleb Maclennan | 9dd1b68b59 | 3 years ago |
Caleb Maclennan | f02fa9c161 | 3 years ago |
Caleb Maclennan | fb43fcbc16 | 3 years ago |
Caleb Maclennan | 1b38911c40 | 3 years ago |
Caleb Maclennan | 9214bf9578 | 3 years ago |
Caleb Maclennan | f293536dd5 | 3 years ago |
Caleb Maclennan | f1c27deeaa | 3 years ago |
Caleb Maclennan | cac9d11158 | 3 years ago |
Caleb Maclennan | 8cc4fe9678 | 3 years ago |
Caleb Maclennan | f4df4c9b5b | 3 years ago |
Caleb Maclennan | 29c5b39545 | 3 years ago |
Caleb Maclennan | 576b24c7a0 | 3 years ago |
Caleb Maclennan | 992d525ef9 | 3 years ago |
Caleb Maclennan | 566833e291 | 3 years ago |
Caleb Maclennan | 43681e9f91 | 3 years ago |
Caleb Maclennan | 601749152e | 3 years ago |
Michael van der Kamp | b13568ea1b | 3 years ago |
Michael van der Kamp | 748b54b885 | 3 years ago |
Caleb Maclennan | 5f999f4dc4 | 3 years ago |
Caleb Maclennan | 3a1aad8752 | 3 years ago |
Caleb Maclennan | a2ab8880a1 | 3 years ago |
Caleb Maclennan | ed12df373a | 3 years ago |
Caleb Maclennan | efe04f05dc | 3 years ago |
Caleb Maclennan | 486ac1bd6e | 3 years ago |
Caleb Maclennan | 0e3ebca98b | 3 years ago |
Caleb Maclennan | bde8b4cb37 | 3 years ago |
Caleb Maclennan | c212352f93 | 3 years ago |
Caleb Maclennan | f589e21472 | 3 years ago |
Caleb Maclennan | a5a17b8e32 | 3 years ago |
Caleb Maclennan | e6fb662bf1 | 3 years ago |
Caleb Maclennan | 925ae23b42 | 3 years ago |
Matthias Bilger | 3693ec6f12 | 3 years ago |
Matthias Bilger | af602e362d | 3 years ago |
Caleb Maclennan | 0f5fd2ce49 | 3 years ago |
Thales Mello | 57bbdc4478 | 3 years ago |
Caleb Maclennan | cce8466613 | 3 years ago |
Caleb Maclennan | 71f28c8296 | 3 years ago |
Caleb Maclennan | 48b541b1a4 | 3 years ago |
Philipp Moers | ef5622f225 | 3 years ago |
Caleb Maclennan | 7f15726b07 | 3 years ago |
Caleb Maclennan | 9c05307141 | 3 years ago |
Giuseppe Rota | 46377b8ab9 | 3 years ago |
Thomas Mayfield | 8fa6ca92c0 | 3 years ago |
Eugene Yunak | 1dec7164ca | 3 years ago |
saubhik | fff2f1a686 | 3 years ago |
Eugene Yunak | f48360cea6 | 3 years ago |
Jonathan Barratt | 02315b02c4 | 3 years ago |
Michael vanderKamp | 67bd945586 | 4 years ago |
Michael vanderKamp | 556a2d692b | 4 years ago |
Michael vanderKamp | 3fdafcfd60 | 4 years ago |
lyuts | 9f81329f60 | 7 years ago |
lyuts | 0a560ba419 | 7 years ago |
@ -0,0 +1,43 @@
|
||||
name: Check
|
||||
on: [push, pull_request]
|
||||
jobs:
|
||||
check:
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
osFlavor: [ubuntu-20.04, ubuntu-18.04]
|
||||
vimFlavor: [neovim, vim]
|
||||
vimVersion: [stable, unstable]
|
||||
exclude:
|
||||
- vimFlavor: vim
|
||||
vimVersion: unstable
|
||||
runs-on: ${{ matrix.osFlavor }}
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
- name: Enable Universe package repository
|
||||
run: |
|
||||
sudo add-apt-repository ${{ matrix.vimVersion == 'stable' && 'universe' || 'ppa:neovim-ppa/unstable' }}
|
||||
sudo apt-get update
|
||||
- name: Install tmux and ${{ matrix.vimFlavor }}
|
||||
run: |
|
||||
sudo apt-get install tmux ${{ matrix.vimFlavor }}
|
||||
- name: Review versions
|
||||
run: |
|
||||
tmux -V
|
||||
${{ matrix.vimFlavor == 'neovim' && 'nvim' || 'vim' }} --version
|
||||
# This tests looks for two thigs:
|
||||
# * That VIM doesn't hang. If it succedes it will quit quickly. If 5
|
||||
# seconds later the tmux session is still running either the runner pane
|
||||
# didn't get closed or (more likely) we threw some error and VIM is
|
||||
# sitting there expecting us to acknowledge the message(s).
|
||||
# * That VIM exited normally. This check isn't very useful since :qa
|
||||
# never bubbles up an error, but if someday we use :cq for a test being
|
||||
# ready to check the exit code seems like a good thing.
|
||||
- name: "Try Vimux"
|
||||
run: |
|
||||
ec="$(mktemp)"
|
||||
tmux new -s ci -d "${{ matrix.vimFlavor == 'neovim' && 'nvim -u /dev/null --headless' || 'vim' }} -i NONE \"+so plugin/vimux.vim\" \"+VimuxRunCommand('date')\" \"+VimuxCloseRunner | qa\"; echo \$? > '$ec'"
|
||||
sleep 5
|
||||
tmux kill-session -t ci && exit 1
|
||||
exit "$(cat $ec)"
|
@ -0,0 +1,13 @@
|
||||
name: Reviewdog
|
||||
on: [pull_request]
|
||||
jobs:
|
||||
vint:
|
||||
name: vint
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: vint
|
||||
uses: reviewdog/action-vint@v1
|
||||
with:
|
||||
github_token: ${{ secrets.github_token }}
|
||||
reporter: github-pr-review
|
@ -0,0 +1,15 @@
|
||||
name: Vint
|
||||
on: [push]
|
||||
jobs:
|
||||
vint:
|
||||
name: vint
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v2
|
||||
- name: Setup dependencies
|
||||
run: pip install vim-vint
|
||||
- name: Lint Vimscript
|
||||
run: vint .
|
@ -0,0 +1,5 @@
|
||||
cmdargs:
|
||||
severity: style_problem
|
||||
color: true
|
||||
env:
|
||||
neovim: false
|
@ -0,0 +1,40 @@
|
||||
# Vimux: easily interact with tmux from vim
|
||||
|
||||
[![Vint](https://github.com/preservim/vimux/workflows/Vint/badge.svg)](https://github.com/preservim/vimux/actions?workflow=Vint)
|
||||
[![Check](https://github.com/preservim/vimux/workflows/Check/badge.svg)](https://github.com/preservim/vimux/actions?workflow=Check)
|
||||
|
||||
![vimux](https://www.braintreepayments.com/blog/content/images/blog/vimux3.png)
|
||||
|
||||
Vimux was originally inspired by [tslime.vim](https://github.com/jgdavey/tslime.vim/network), a plugin that lets you send input to tmux. While tslime.vim works well, it wasn't optimized for the use case of having a smaller tmux pane used to run tests or play with a REPL. The goal of Vimux is to make interacting with tmux from vim effortless.
|
||||
|
||||
By default, when you call `VimuxRunCommand` vimux will create a 20% tall horizontal pane under your current tmux pane and execute a command in it without losing the focus on vim. Once that pane exists, whenever you call `VimuxRunCommand` again the command will be executed in that pane. A frequent use case is wanting to rerun commands over and over. An example of this is running the current file through rspec. Rather than typing that over and over `VimuxRunLastCommand` will execute the last command called with `VimuxRunCommand`.
|
||||
|
||||
## Installation
|
||||
|
||||
With **[vim-bundle](https://github.com/preservim/vim-bundle)**: `vim-bundle install preservim/vimux`
|
||||
With **[Vundle](https://github.com/gmarik/Vundle.vim)**: `Plugin 'preservim/vimux'` in your .vimrc
|
||||
|
||||
Otherwise download the latest [tarball](https://github.com/preservim/vimux/tarball/master), extract it and move `plugin/vimux.vim` inside `~/.vim/plugin`. If you're using [pathogen](https://github.com/tpope/vim-pathogen), then move the entire folder extracted from the tarball into `~/.vim/bundle`.
|
||||
|
||||
_Notes:_
|
||||
|
||||
* Vimux assumes a reasonably new version of tmux. Some older versions might work but it is recommended to use the latest stable release.
|
||||
|
||||
## Usage
|
||||
|
||||
The full documentation is available [online](https://raw.github.com/preservim/vimux/master/doc/vimux.txt) and accessible inside vim via `:help vimux`
|
||||
|
||||
## Platform-specific Plugins
|
||||
|
||||
* [vim-vroom](https://github.com/skalnik/vim-vroom) runner for rspec, cucumber and test/unit; vimux support via `g:vroom_use_vimux`
|
||||
* [vimux-ruby-test](https://github.com/pgr0ss/vimux-ruby-test) a set of commands to easily run ruby tests
|
||||
* [vimux-cucumber](https://github.com/cloud8421/vimux-cucumber) run Cucumber Features through Vimux
|
||||
* [vim-turbux](https://github.com/jgdavey/vim-turbux) Turbo Ruby testing with tmux
|
||||
* [vimux-pyutils](https://github.com/julienr/vimux-pyutils) A set of functions for vimux that allow to run code blocks in ipython
|
||||
* [vimux-nose-test](https://github.com/pitluga/vimux-nose-test) Run nose tests in vimux
|
||||
* [vimux-golang](https://github.com/benmills/vimux-golang) Run go tests in vimux
|
||||
* [vimux-zeus](https://github.com/jingweno/vimux-zeus) Run zeus commands in vimux
|
||||
* [vimix](https://github.com/spiegela/vimix) Run Elixir mix commands in vimux
|
||||
* [vimux-cargo](https://github.com/jtdowney/vimux-cargo) run rust tests and projects using cargo and vimux
|
||||
* [vimux-bazel-test](https://github.com/pgr0ss/vimux-bazel-test) Run bazel tests in vimux
|
||||
* [vimux-jest-test](https://github.com/tyewang/vimux-jest-test) Run jest tests in vimux
|
@ -1,41 +0,0 @@
|
||||
# vimux
|
||||
|
||||
Easily interact with tmux from vim.
|
||||
|
||||
![vimux](https://www.braintreepayments.com/blog/content/images/blog/vimux3.png)
|
||||
|
||||
What inspired me to write vimux was [tslime.vim](https://github.com/kikijump/tslime.vim), a plugin that lets you send input to tmux. While tslime.vim works well, I felt it wasn't optimized for my primary use case which was having a smaller tmux pane that I would use to run tests or play with a REPL.
|
||||
|
||||
My goal with vimux is to make interacting with tmux from vim effortless. By default when you call `VimuxRunCommand` vimux will create a 20% tall horizontal pane under your current tmux pane and execute a command in it without losing focus of vim. Once that pane exists whenever you call `VimuxRunCommand` again the command will be executed in that pane. As I was using vimux myself I wanted to rerun commands over and over. An example of this was running the current file through rspec. Rather than typing that over and over I wrote `VimuxRunLastCommand` that will execute the last command you called with `VimuxRunCommand`.
|
||||
|
||||
Other auxiliary functions and the ones I talked about above can be found bellow with a full description and example key binds for your vimrc.
|
||||
|
||||
## Installation
|
||||
|
||||
With **[vim-bundle](https://github.com/benmills/vim-bundle)**: `vim-bundle install benmills/vimux`
|
||||
With **[Vundle](https://github.com/gmarik/Vundle.vim)**: 'Plugin benmills/vimux' in your .vimrc
|
||||
|
||||
Otherwise download the latest [tarball](https://github.com/benmills/vimux/tarball/master), extract it and move `plugin/vimux.vim` inside `~/.vim/plugin`. If you're using [pathogen](https://github.com/tpope/vim-pathogen), then move the entire folder extracted from the tarball into `~/.vim/bundle`.
|
||||
|
||||
_Notes:_
|
||||
|
||||
* Vimux assumes a tmux version >= 1.5. Some older versions might work but it is recommeded to use at least version 1.5.
|
||||
|
||||
## Platform-specific Plugins
|
||||
|
||||
* [vim-vroom](https://github.com/skalnik/vim-vroom) runner for rspec, cucumber and test/unit; vimux support via `g:vroom_use_vimux`
|
||||
* [vimux-ruby-test](https://github.com/pgr0ss/vimux-ruby-test) a set of commands to easily run ruby tests
|
||||
* [vimux-cucumber](https://github.com/cloud8421/vimux-cucumber) run Cucumber Features through Vimux
|
||||
* [vim-turbux](https://github.com/jgdavey/vim-turbux) Turbo Ruby testing with tmux
|
||||
* [vimux-pyutils](https://github.com/julienr/vimux-pyutils) A set of functions for vimux that allow to run code blocks in ipython
|
||||
* [vimux-nose-test](https://github.com/pitluga/vimux-nose-test) Run nose tests in vimux
|
||||
* [vimux-golang](https://github.com/benmills/vimux-golang) Run go tests in vimux
|
||||
* [vimux-zeus](https://github.com/jingweno/vimux-zeus) Run zeus commands in vimux
|
||||
* [vimix](https://github.com/spiegela/vimix) Run Elixir mix commands in vimux
|
||||
* [vimux-cargo](https://github.com/jtdowney/vimux-cargo) run rust tests and projects using cargo and vimux
|
||||
* [vimux-bazel-test](https://github.com/pgr0ss/vimux-bazel-test) Run bazel tests in vimux
|
||||
* [vimux-jest-test](https://github.com/tyewang/vimux-jest-test) Run jest tests in vimux
|
||||
|
||||
## Usage
|
||||
|
||||
The full documentation is available [online](https://raw.github.com/benmills/vimux/master/doc/vimux.txt) and accessible inside vim `:help vimux`
|
@ -1,203 +1,321 @@
|
||||
if exists("g:loaded_vimux") || &cp
|
||||
if exists('g:loaded_vimux') || &compatible
|
||||
finish
|
||||
endif
|
||||
let g:loaded_vimux = 1
|
||||
|
||||
" Set up all global options with defaults right away, in one place
|
||||
let g:VimuxDebug = get(g:, 'VimuxDebug', v:false)
|
||||
let g:VimuxHeight = get(g:, 'VimuxHeight', 20)
|
||||
let g:VimuxOpenExtraArgs = get(g:, 'VimuxOpenExtraArgs', '')
|
||||
let g:VimuxOrientation = get(g:, 'VimuxOrientation', 'v')
|
||||
let g:VimuxPromptString = get(g:, 'VimuxPromptString', 'Command? ')
|
||||
let g:VimuxResetSequence = get(g:, 'VimuxResetSequence', 'q C-u')
|
||||
let g:VimuxRunnerName = get(g:, 'VimuxRunnerName', '')
|
||||
let g:VimuxRunnerType = get(g:, 'VimuxRunnerType', 'pane')
|
||||
let g:VimuxRunnerQuery = get(g:, 'VimuxRunnerQuery', {})
|
||||
let g:VimuxTmuxCommand = get(g:, 'VimuxTmuxCommand', 'tmux')
|
||||
let g:VimuxUseNearest = get(g:, 'VimuxUseNearest', v:true)
|
||||
let g:VimuxExpandCommand = get(g:, 'VimuxExpandCommand', v:false)
|
||||
let g:VimuxCloseOnExit = get(g:, 'VimuxCloseOnExit', v:false)
|
||||
let g:VimuxCommandShell = get(g:, 'VimuxCommandShell', v:true)
|
||||
|
||||
function! VimuxOption(name) abort
|
||||
return get(b:, a:name, get(g:, a:name))
|
||||
endfunction
|
||||
|
||||
if !executable(VimuxOption('VimuxTmuxCommand'))
|
||||
echohl ErrorMsg | echomsg 'Failed to find executable '.VimuxOption('VimuxTmuxCommand') | echohl None
|
||||
finish
|
||||
endif
|
||||
|
||||
command -nargs=* VimuxRunCommand :call VimuxRunCommand(<args>)
|
||||
command VimuxRunLastCommand :call VimuxRunLastCommand()
|
||||
command VimuxCloseRunner :call VimuxCloseRunner()
|
||||
command VimuxZoomRunner :call VimuxZoomRunner()
|
||||
command VimuxInspectRunner :call VimuxInspectRunner()
|
||||
command VimuxScrollUpInspect :call VimuxScrollUpInspect()
|
||||
command VimuxScrollDownInspect :call VimuxScrollDownInspect()
|
||||
command VimuxInterruptRunner :call VimuxInterruptRunner()
|
||||
command -bar VimuxRunLastCommand :call VimuxRunLastCommand()
|
||||
command -bar VimuxOpenRunner :call VimuxOpenRunner()
|
||||
command -bar VimuxCloseRunner :call VimuxCloseRunner()
|
||||
command -bar VimuxZoomRunner :call VimuxZoomRunner()
|
||||
command -bar VimuxInspectRunner :call VimuxInspectRunner()
|
||||
command -bar VimuxScrollUpInspect :call VimuxScrollUpInspect()
|
||||
command -bar VimuxScrollDownInspect :call VimuxScrollDownInspect()
|
||||
command -bar VimuxInterruptRunner :call VimuxInterruptRunner()
|
||||
command -nargs=? VimuxPromptCommand :call VimuxPromptCommand(<args>)
|
||||
command VimuxClearRunnerHistory :call VimuxClearRunnerHistory()
|
||||
command VimuxTogglePane :call VimuxTogglePane()
|
||||
|
||||
function! VimuxRunCommandInDir(command, useFile)
|
||||
let l:file = ""
|
||||
if a:useFile ==# 1
|
||||
let l:file = shellescape(expand('%:t'), 1)
|
||||
endif
|
||||
call VimuxRunCommand("(cd ".shellescape(expand('%:p:h'), 1)." && ".a:command." ".l:file.")")
|
||||
command -bar VimuxClearTerminalScreen :call VimuxClearTerminalScreen()
|
||||
command -bar VimuxClearRunnerHistory :call VimuxClearRunnerHistory()
|
||||
command -bar VimuxTogglePane :call VimuxTogglePane()
|
||||
|
||||
augroup VimuxAutocmds
|
||||
au!
|
||||
autocmd VimLeave * call s:autoclose()
|
||||
augroup END
|
||||
|
||||
function! VimuxRunCommandInDir(command, useFile) abort
|
||||
let l:file = ''
|
||||
if a:useFile ==# 1
|
||||
let l:file = shellescape(expand('%:t'), 1)
|
||||
endif
|
||||
call VimuxRunCommand('(cd '.shellescape(expand('%:p:h'), 1).' && '.a:command.' '.l:file.')')
|
||||
endfunction
|
||||
|
||||
function! VimuxRunLastCommand()
|
||||
if exists("g:VimuxRunnerIndex")
|
||||
function! VimuxRunLastCommand() abort
|
||||
if exists('g:VimuxLastCommand')
|
||||
call VimuxRunCommand(g:VimuxLastCommand)
|
||||
else
|
||||
echo "No last vimux command."
|
||||
echo 'No last vimux command.'
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! VimuxRunCommand(command, ...)
|
||||
if !exists("g:VimuxRunnerIndex") || _VimuxHasRunner(g:VimuxRunnerIndex) == -1
|
||||
function! VimuxRunCommand(command, ...) abort
|
||||
if !exists('g:VimuxRunnerIndex') || s:hasRunner(g:VimuxRunnerIndex) ==# -1
|
||||
call VimuxOpenRunner()
|
||||
endif
|
||||
|
||||
let l:autoreturn = 1
|
||||
if exists("a:1")
|
||||
if exists('a:1')
|
||||
let l:autoreturn = a:1
|
||||
endif
|
||||
|
||||
let resetSequence = _VimuxOption("g:VimuxResetSequence", "q C-u")
|
||||
let resetSequence = VimuxOption('VimuxResetSequence')
|
||||
let g:VimuxLastCommand = a:command
|
||||
|
||||
call VimuxSendKeys(resetSequence)
|
||||
call VimuxSendText(a:command)
|
||||
|
||||
if l:autoreturn == 1
|
||||
call VimuxSendKeys("Enter")
|
||||
if l:autoreturn ==# 1
|
||||
call VimuxSendKeys('Enter')
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! VimuxSendText(text)
|
||||
call VimuxSendKeys('"'.escape(a:text, '\"$`').'"')
|
||||
function! VimuxSendText(text) abort
|
||||
call VimuxSendKeys(shellescape(substitute(a:text, '\n$', ' ', '')))
|
||||
endfunction
|
||||
|
||||
function! VimuxSendKeys(keys)
|
||||
if exists("g:VimuxRunnerIndex")
|
||||
call _VimuxTmux("send-keys -t ".g:VimuxRunnerIndex." ".a:keys)
|
||||
function! VimuxSendKeys(keys) abort
|
||||
if exists('g:VimuxRunnerIndex')
|
||||
call VimuxTmux('send-keys -t '.g:VimuxRunnerIndex.' '.a:keys)
|
||||
else
|
||||
echo "No vimux runner pane/window. Create one with VimuxOpenRunner"
|
||||
echo 'No vimux runner pane/window. Create one with VimuxOpenRunner'
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! VimuxOpenRunner()
|
||||
let nearestIndex = _VimuxNearestIndex()
|
||||
|
||||
if _VimuxOption("g:VimuxUseNearest", 1) == 1 && nearestIndex != -1
|
||||
let g:VimuxRunnerIndex = nearestIndex
|
||||
function! VimuxOpenRunner() abort
|
||||
let existingId = s:existingRunnerId()
|
||||
if existingId !=# ''
|
||||
let g:VimuxRunnerIndex = existingId
|
||||
else
|
||||
if _VimuxRunnerType() == "pane"
|
||||
let height = _VimuxOption("g:VimuxHeight", 20)
|
||||
let orientation = _VimuxOption("g:VimuxOrientation", "v")
|
||||
call _VimuxTmux("split-window -p ".height." -".orientation)
|
||||
elseif _VimuxRunnerType() == "window"
|
||||
call _VimuxTmux("new-window")
|
||||
let extraArguments = VimuxOption('VimuxOpenExtraArgs')
|
||||
if VimuxOption('VimuxRunnerType') ==# 'pane'
|
||||
call VimuxTmux('split-window '.s:vimuxPaneOptions().' '.extraArguments)
|
||||
elseif VimuxOption('VimuxRunnerType') ==# 'window'
|
||||
call VimuxTmux('new-window '.extraArguments)
|
||||
endif
|
||||
|
||||
let g:VimuxRunnerIndex = _VimuxTmuxIndex()
|
||||
call _VimuxTmux("last-"._VimuxRunnerType())
|
||||
let g:VimuxRunnerIndex = s:tmuxIndex()
|
||||
call s:setRunnerName()
|
||||
call VimuxTmux('last-'.VimuxOption('VimuxRunnerType'))
|
||||
sleep 100m
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! VimuxCloseRunner()
|
||||
if exists("g:VimuxRunnerIndex")
|
||||
call _VimuxTmux("kill-"._VimuxRunnerType()." -t ".g:VimuxRunnerIndex)
|
||||
function! VimuxCloseRunner() abort
|
||||
if exists('g:VimuxRunnerIndex')
|
||||
call VimuxTmux('kill-'.VimuxOption('VimuxRunnerType').' -t '.g:VimuxRunnerIndex)
|
||||
unlet g:VimuxRunnerIndex
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! VimuxTogglePane()
|
||||
if exists("g:VimuxRunnerIndex")
|
||||
if _VimuxRunnerType() == "window"
|
||||
call _VimuxTmux("join-pane -d -s ".g:VimuxRunnerIndex." -p "._VimuxOption("g:VimuxHeight", 20))
|
||||
let g:VimuxRunnerType = "pane"
|
||||
elseif _VimuxRunnerType() == "pane"
|
||||
let g:VimuxRunnerIndex=substitute(_VimuxTmux("break-pane -d -t ".g:VimuxRunnerIndex." -P -F '#{window_index}'"), "\n", "", "")
|
||||
let g:VimuxRunnerType = "window"
|
||||
function! VimuxTogglePane() abort
|
||||
if exists('g:VimuxRunnerIndex')
|
||||
if VimuxOption('VimuxRunnerType') ==# 'window'
|
||||
call VimuxTmux('join-pane -s '.g:VimuxRunnerIndex.' '.s:vimuxPaneOptions())
|
||||
let g:VimuxRunnerType = 'pane'
|
||||
let g:VimuxRunnerIndex = s:tmuxIndex()
|
||||
call VimuxTmux('last-'.VimuxOption('VimuxRunnerType'))
|
||||
elseif VimuxOption('VimuxRunnerType') ==# 'pane'
|
||||
let g:VimuxRunnerIndex=substitute(
|
||||
\ VimuxTmux('break-pane -d -s '.g:VimuxRunnerIndex." -P -F '#{window_id}'"),
|
||||
\ '\n',
|
||||
\ '',
|
||||
\ ''
|
||||
\)
|
||||
let g:VimuxRunnerType = 'window'
|
||||
endif
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! VimuxZoomRunner()
|
||||
if exists("g:VimuxRunnerIndex")
|
||||
if _VimuxRunnerType() == "pane"
|
||||
call _VimuxTmux("resize-pane -Z -t ".g:VimuxRunnerIndex)
|
||||
elseif _VimuxRunnerType() == "window"
|
||||
call _VimuxTmux("select-window -t ".g:VimuxRunnerIndex)
|
||||
function! VimuxZoomRunner() abort
|
||||
if exists('g:VimuxRunnerIndex')
|
||||
if VimuxOption('VimuxRunnerType') ==# 'pane'
|
||||
call VimuxTmux('resize-pane -Z -t '.g:VimuxRunnerIndex)
|
||||
elseif VimuxOption('VimuxRunnerType') ==# 'window'
|
||||
call VimuxTmux('select-window -t '.g:VimuxRunnerIndex)
|
||||
endif
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! VimuxInspectRunner()
|
||||
call _VimuxTmux("select-"._VimuxRunnerType()." -t ".g:VimuxRunnerIndex)
|
||||
call _VimuxTmux("copy-mode")
|
||||
function! VimuxInspectRunner() abort
|
||||
call VimuxTmux('select-'.VimuxOption('VimuxRunnerType').' -t '.g:VimuxRunnerIndex)
|
||||
call VimuxTmux('copy-mode')
|
||||
endfunction
|
||||
|
||||
function! VimuxScrollUpInspect()
|
||||
function! VimuxScrollUpInspect() abort
|
||||
call VimuxInspectRunner()
|
||||
call _VimuxTmux("last-"._VimuxRunnerType())
|
||||
call VimuxSendKeys("C-u")
|
||||
call VimuxTmux('last-'.VimuxOption('VimuxRunnerType'))
|
||||
call VimuxSendKeys('C-u')
|
||||
endfunction
|
||||
|
||||
function! VimuxScrollDownInspect()
|
||||
function! VimuxScrollDownInspect() abort
|
||||
call VimuxInspectRunner()
|
||||
call _VimuxTmux("last-"._VimuxRunnerType())
|
||||
call VimuxSendKeys("C-d")
|
||||
call VimuxTmux('last-'.VimuxOption('VimuxRunnerType'))
|
||||
call VimuxSendKeys('C-d')
|
||||
endfunction
|
||||
|
||||
function! VimuxInterruptRunner()
|
||||
call VimuxSendKeys("^c")
|
||||
function! VimuxInterruptRunner() abort
|
||||
call VimuxSendKeys('^c')
|
||||
endfunction
|
||||
|
||||
function! VimuxClearRunnerHistory()
|
||||
if exists("g:VimuxRunnerIndex")
|
||||
call _VimuxTmux("clear-history -t ".g:VimuxRunnerIndex)
|
||||
function! VimuxClearTerminalScreen() abort
|
||||
if exists('g:VimuxRunnerIndex')
|
||||
call VimuxSendKeys('C-l')
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! VimuxPromptCommand(...)
|
||||
let command = a:0 == 1 ? a:1 : ""
|
||||
let l:command = input(_VimuxOption("g:VimuxPromptString", "Command? "), command)
|
||||
function! VimuxClearRunnerHistory() abort
|
||||
if exists('g:VimuxRunnerIndex')
|
||||
call VimuxTmux('clear-history -t '.g:VimuxRunnerIndex)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! VimuxPromptCommand(...) abort
|
||||
let command = a:0 ==# 1 ? a:1 : ''
|
||||
if VimuxOption('VimuxCommandShell')
|
||||
let l:command = input(VimuxOption('VimuxPromptString'), command, 'shellcmd')
|
||||
else
|
||||
let l:command = input(VimuxOption('VimuxPromptString'), command)
|
||||
endif
|
||||
if VimuxOption('VimuxExpandCommand')
|
||||
let l:command = join(map(split(l:command, ' '), 'expand(v:val)'), ' ')
|
||||
endif
|
||||
call VimuxRunCommand(l:command)
|
||||
endfunction
|
||||
|
||||
function! _VimuxTmux(arguments)
|
||||
let l:command = _VimuxOption("g:VimuxTmuxCommand", "tmux")
|
||||
return system(l:command." ".a:arguments)
|
||||
function! VimuxTmux(arguments) abort
|
||||
if VimuxOption('VimuxDebug')
|
||||
echom VimuxOption('VimuxTmuxCommand').' '.a:arguments
|
||||
endif
|
||||
if has_key(environ(), 'TMUX')
|
||||
return system(VimuxOption('VimuxTmuxCommand').' '.a:arguments)
|
||||
else
|
||||
throw 'Aborting, because not inside tmux session.'
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! _VimuxTmuxSession()
|
||||
return _VimuxTmuxProperty("#S")
|
||||
function! s:tmuxSession() abort
|
||||
return s:tmuxProperty('#S')
|
||||
endfunction
|
||||
|
||||
function! _VimuxTmuxIndex()
|
||||
if _VimuxRunnerType() == "pane"
|
||||
return _VimuxTmuxPaneIndex()
|
||||
function! s:tmuxIndex() abort
|
||||
if VimuxOption('VimuxRunnerType') ==# 'pane'
|
||||
return s:tmuxPaneId()
|
||||
else
|
||||
return _VimuxTmuxWindowIndex()
|
||||
return s:tmuxWindowId()
|
||||
end
|
||||
endfunction
|
||||
|
||||
function! _VimuxTmuxPaneIndex()
|
||||
return _VimuxTmuxProperty("#I.#P")
|
||||
function! s:tmuxPaneId() abort
|
||||
return s:tmuxProperty('#{pane_id}')
|
||||
endfunction
|
||||
|
||||
function! _VimuxTmuxWindowIndex()
|
||||
return _VimuxTmuxProperty("#I")
|
||||
function! s:tmuxWindowId() abort
|
||||
return s:tmuxProperty('#{window_id}')
|
||||
endfunction
|
||||
|
||||
function! _VimuxNearestIndex()
|
||||
let views = split(_VimuxTmux("list-"._VimuxRunnerType()."s"), "\n")
|
||||
function! s:vimuxPaneOptions() abort
|
||||
let height = VimuxOption('VimuxHeight')
|
||||
let orientation = VimuxOption('VimuxOrientation')
|
||||
return '-l '.height.'% -'.orientation
|
||||
endfunction
|
||||
|
||||
""
|
||||
" @return a string of the form '%4', the ID of the pane or window to use,
|
||||
" or '' if no nearest pane or window is found.
|
||||
function! s:existingRunnerId() abort
|
||||
let runnerType = VimuxOption('VimuxRunnerType')
|
||||
let query = get(VimuxOption('VimuxRunnerQuery'), runnerType, '')
|
||||
if empty(query)
|
||||
if empty(VimuxOption('VimuxUseNearest'))
|
||||
return ''
|
||||
else
|
||||
return s:nearestRunnerId()
|
||||
endif
|
||||
endif
|
||||
" Try finding the runner using the provided query
|
||||
let currentId = s:tmuxIndex()
|
||||
let message = VimuxTmux('select-'.runnerType.' -t '.query.'')
|
||||
if message ==# ''
|
||||
" A match was found. Make sure it isn't the current vim pane/window
|
||||
" though!
|
||||
let runnerId = s:tmuxIndex()
|
||||
if runnerId !=# currentId
|
||||
" Success!
|
||||
call VimuxTmux('last-'.runnerType)
|
||||
return runnerId
|
||||
endif
|
||||
endif
|
||||
return ''
|
||||
endfunction
|
||||
|
||||
function! s:nearestRunnerId() abort
|
||||
" Try finding the runner in the current window/session, optionally using a
|
||||
" name/title filter
|
||||
let runnerType = VimuxOption('VimuxRunnerType')
|
||||
let filter = s:getTargetFilter()
|
||||
let views = split(
|
||||
\ VimuxTmux(
|
||||
\ 'list-'.runnerType.'s'
|
||||
\ ." -F '#{".runnerType.'_active}:#{'.runnerType."_id}'"
|
||||
\ .filter),
|
||||
\ '\n')
|
||||
" '1:' is the current active pane (the one with vim).
|
||||
" Find the first non-active pane.
|
||||
for view in views
|
||||
if match(view, "(active)") == -1
|
||||
return split(view, ":")[0]
|
||||
if match(view, '1:') ==# -1
|
||||
return split(view, ':')[1]
|
||||
endif
|
||||
endfor
|
||||
|
||||
return -1
|
||||
return ''
|
||||
endfunction
|
||||
|
||||
function! _VimuxRunnerType()
|
||||
return _VimuxOption("g:VimuxRunnerType", "pane")
|
||||
function! s:getTargetFilter() abort
|
||||
let targetName = VimuxOption('VimuxRunnerName')
|
||||
if targetName ==# ''
|
||||
return ''
|
||||
endif
|
||||
let runnerType = VimuxOption('VimuxRunnerType')
|
||||
if runnerType ==# 'window'
|
||||
return " -f '#{==:#{window_name},".targetName."}'"
|
||||
elseif runnerType ==# 'pane'
|
||||
return " -f '#{==:#{pane_title},".targetName."}'"
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! _VimuxOption(option, default)
|
||||
if exists(a:option)
|
||||
return eval(a:option)
|
||||
else
|
||||
return a:default
|
||||
function! s:setRunnerName() abort
|
||||
let targetName = VimuxOption('VimuxRunnerName')
|
||||
if targetName ==# ''
|
||||
return
|
||||
endif
|
||||
let runnerType = VimuxOption('VimuxRunnerType')
|
||||
if runnerType ==# 'window'
|
||||
call VimuxTmux('rename-window '.targetName)
|
||||
elseif runnerType ==# 'pane'
|
||||
call VimuxTmux('select-pane -T '.targetName)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! s:tmuxProperty(property) abort
|
||||
return substitute(VimuxTmux("display -p '".a:property."'"), '\n$', '', '')
|
||||
endfunction
|
||||
|
||||
function! _VimuxTmuxProperty(property)
|
||||
return substitute(_VimuxTmux("display -p '".a:property."'"), '\n$', '', '')
|
||||
function! s:hasRunner(index) abort
|
||||
let runnerType = VimuxOption('VimuxRunnerType')
|
||||
return match(VimuxTmux('list-'.runnerType."s -F '#{".runnerType."_id}'"), a:index)
|
||||
endfunction
|
||||
|
||||
function! _VimuxHasRunner(index)
|
||||
return match(_VimuxTmux("list-"._VimuxRunnerType()."s -a"), a:index.":")
|
||||
function! s:autoclose() abort
|
||||
if VimuxOption('VimuxCloseOnExit')
|
||||
call VimuxCloseRunner()
|
||||
endif
|
||||
endfunction
|
||||
|
Loading…
Reference in New Issue