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