2016-01-26 14:04:48 +01:00
|
|
|
# http://tmux.github.io/
|
|
|
|
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
|
2019-12-10 12:15:08 +01:00
|
|
|
# Tmux version >= 2 is required to use this module
|
2016-01-26 14:04:48 +01:00
|
|
|
|
2019-06-25 17:48:24 +02:00
|
|
|
hook global ModuleLoaded tmux %{
|
2019-03-13 22:00:59 +01:00
|
|
|
require-module tmux-repl
|
|
|
|
}
|
2019-01-18 14:42:04 +01:00
|
|
|
|
2019-03-13 22:00:59 +01:00
|
|
|
provide-module tmux-repl %{
|
2016-08-30 16:48:21 +02:00
|
|
|
|
2019-03-13 22:00:59 +01:00
|
|
|
declare-option -docstring "tmux pane id in which the REPL is running" str tmux_repl_id
|
2016-01-26 14:04:48 +01:00
|
|
|
|
2020-08-30 02:53:03 +02:00
|
|
|
define-command -hidden -params 1.. tmux-repl-impl %{
|
2018-05-06 23:29:52 +02:00
|
|
|
evaluate-commands %sh{
|
2016-01-26 14:04:48 +01:00
|
|
|
if [ -z "$TMUX" ]; then
|
2019-11-14 08:32:55 +01:00
|
|
|
echo 'fail This command is only available in a tmux session'
|
2016-01-26 14:04:48 +01:00
|
|
|
exit
|
|
|
|
fi
|
|
|
|
tmux_args="$1"
|
|
|
|
shift
|
2020-08-30 02:53:03 +02:00
|
|
|
tmux $tmux_args "$@"
|
2022-10-30 19:08:50 +01:00
|
|
|
printf "set-option current tmux_repl_id '%s'" $(tmux display-message -p '#{pane_id}')
|
2016-01-26 14:04:48 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-22 10:14:47 +01:00
|
|
|
define-command tmux-repl-vertical -params 0.. -docstring "Create a new vertical pane for repl interaction" %{
|
2016-01-26 14:04:48 +01:00
|
|
|
tmux-repl-impl 'split-window -v' %arg{@}
|
|
|
|
}
|
2022-07-20 08:32:03 +02:00
|
|
|
complete-command tmux-repl-vertical shell
|
2016-01-26 14:04:48 +01:00
|
|
|
|
2022-02-22 10:14:47 +01:00
|
|
|
define-command tmux-repl-horizontal -params 0.. -docstring "Create a new horizontal pane for repl interaction" %{
|
2016-01-26 14:04:48 +01:00
|
|
|
tmux-repl-impl 'split-window -h' %arg{@}
|
|
|
|
}
|
2022-07-20 08:32:03 +02:00
|
|
|
complete-command tmux-repl-horizontal shell
|
2016-01-26 14:04:48 +01:00
|
|
|
|
2022-02-22 10:14:47 +01:00
|
|
|
define-command tmux-repl-window -params 0.. -docstring "Create a new window for repl interaction" %{
|
2016-01-26 14:04:48 +01:00
|
|
|
tmux-repl-impl 'new-window' %arg{@}
|
|
|
|
}
|
2022-07-20 08:32:03 +02:00
|
|
|
complete-command tmux-repl-window shell
|
2016-01-26 14:04:48 +01:00
|
|
|
|
2021-08-22 16:57:09 +02:00
|
|
|
define-command -params 0..1 tmux-repl-set-pane -docstring %{
|
|
|
|
tmux-repl-set-pane [pane number]: Set an existing tmux pane for repl interaction
|
|
|
|
If the address of new pane is not given, next pane is used
|
|
|
|
(To get the pane number in tmux,
|
|
|
|
use 'tmux display-message -p '#{pane_id}'" in that pane)
|
|
|
|
} %{
|
|
|
|
evaluate-commands %sh{
|
|
|
|
if [ -z "$TMUX" ]; then
|
|
|
|
echo 'fail This command is only available in a tmux session'
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
if [ $# -eq 0 ]; then
|
|
|
|
curr_pane="$(tmux display-message -p '#{pane_id}')"
|
2022-10-30 21:12:17 +01:00
|
|
|
curr_pane_no="${curr_pane#%}"
|
2021-08-22 16:57:09 +02:00
|
|
|
tgt_pane=$((curr_pane_no+1))
|
|
|
|
else
|
|
|
|
tgt_pane="$1"
|
|
|
|
fi
|
|
|
|
curr_win="$(tmux display-message -p '#{window_id}')"
|
2022-10-30 21:12:17 +01:00
|
|
|
if tmux list-panes -t "$curr_win" -F \#D | grep -Fxq "%"$tgt_pane; then
|
2022-10-30 19:08:50 +01:00
|
|
|
printf "set-option current tmux_repl_id '%s'" %$tgt_pane
|
2021-08-22 16:57:09 +02:00
|
|
|
else
|
|
|
|
echo 'fail The correct pane is not there. Activate using tmux-terminal-* or some other way'
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-03 20:53:28 +01:00
|
|
|
define-command -hidden tmux-send-text -params 0..1 -docstring %{
|
2020-12-30 22:11:02 +01:00
|
|
|
tmux-send-text [text]: Send text to the REPL pane.
|
2020-02-03 20:53:28 +01:00
|
|
|
If no text is passed, then the selection is used
|
|
|
|
} %{
|
2022-10-30 18:52:02 +01:00
|
|
|
evaluate-commands %sh{
|
2019-03-13 22:00:59 +01:00
|
|
|
if [ $# -eq 0 ]; then
|
2020-12-30 22:11:02 +01:00
|
|
|
tmux set-buffer -b kak_selection -- "${kak_selection}"
|
2018-05-31 04:26:26 +02:00
|
|
|
else
|
2020-12-30 22:11:02 +01:00
|
|
|
tmux set-buffer -b kak_selection -- "$1"
|
2018-05-31 04:26:26 +02:00
|
|
|
fi
|
2022-10-30 18:52:02 +01:00
|
|
|
tmux paste-buffer -b kak_selection -t "$kak_opt_tmux_repl_id" ||
|
|
|
|
echo 'fail tmux-send-text: failed to send text, see *debug* buffer for details'
|
2016-01-26 14:04:48 +01:00
|
|
|
}
|
|
|
|
}
|
2016-06-23 19:07:51 +02:00
|
|
|
|
2020-09-01 12:30:34 +02:00
|
|
|
alias global repl-new tmux-repl-horizontal
|
|
|
|
alias global repl-send-text tmux-send-text
|
2019-03-13 22:00:59 +01:00
|
|
|
|
|
|
|
}
|