2017-09-23 16:26:57 +02:00
|
|
|
# http://gnu.org/software/screen/
|
|
|
|
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
|
2018-11-28 10:39:15 +01:00
|
|
|
|
2017-09-23 16:26:57 +02:00
|
|
|
|
2019-03-13 19:15:59 +01:00
|
|
|
provide-module screen %{
|
|
|
|
|
2020-07-05 04:02:59 +02:00
|
|
|
# ensure that we're running under screen
|
|
|
|
evaluate-commands %sh{
|
2020-07-06 13:55:54 +02:00
|
|
|
[ -z "${kak_opt_windowing_modules}" ] || [ -n "$STY" ] || echo 'fail screen not detected'
|
2020-07-05 04:02:59 +02:00
|
|
|
}
|
|
|
|
|
2018-12-21 18:14:28 +01:00
|
|
|
define-command screen-terminal-impl -hidden -params 3.. %{
|
2018-12-02 13:59:45 +01:00
|
|
|
nop %sh{
|
2017-09-23 16:26:57 +02:00
|
|
|
tty="$(ps -o tty ${kak_client_pid} | tail -n 1)"
|
2018-12-02 13:59:45 +01:00
|
|
|
screen -X eval "$1" "$2"
|
2018-12-21 18:14:28 +01:00
|
|
|
shift 2
|
|
|
|
# see x11.kak for what this achieves
|
|
|
|
args=$(
|
|
|
|
for i in "$@"; do
|
2022-11-20 02:13:34 +01:00
|
|
|
printf "'%s' " "$(printf %s "$i" | sed "s|'|'\\\\''|g")"
|
2018-12-21 18:14:28 +01:00
|
|
|
done
|
|
|
|
)
|
|
|
|
screen -X screen sh -c "${args} ; screen -X remove" < "/dev/$tty"
|
2017-09-23 16:26:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-22 10:14:47 +01:00
|
|
|
define-command screen-terminal-vertical -params 1.. -docstring '
|
2018-12-21 18:14:28 +01:00
|
|
|
screen-terminal-vertical <program> [<arguments>] [<arguments>]: create a new terminal as a screen pane
|
2018-12-02 13:59:45 +01:00
|
|
|
The current pane is split into two, left and right
|
2018-12-21 18:14:28 +01:00
|
|
|
The program passed as argument will be executed in the new terminal' \
|
2018-12-02 13:59:45 +01:00
|
|
|
%{
|
|
|
|
screen-terminal-impl 'split -v' 'focus right' %arg{@}
|
2017-09-23 16:26:57 +02:00
|
|
|
}
|
2022-02-22 10:14:47 +01:00
|
|
|
complete-command screen-terminal-vertical shell
|
|
|
|
|
|
|
|
define-command screen-terminal-horizontal -params 1.. -docstring '
|
2018-12-21 18:14:28 +01:00
|
|
|
screen-terminal-horizontal <program> [<arguments>]: create a new terminal as a screen pane
|
2018-12-02 13:59:45 +01:00
|
|
|
The current pane is split into two, top and bottom
|
2018-12-21 18:14:28 +01:00
|
|
|
The program passed as argument will be executed in the new terminal' \
|
2018-12-02 13:59:45 +01:00
|
|
|
%{
|
|
|
|
screen-terminal-impl 'split -h' 'focus down' %arg{@}
|
|
|
|
}
|
2022-02-22 10:14:47 +01:00
|
|
|
complete-command screen-terminal-horizontal shell
|
|
|
|
|
|
|
|
define-command screen-terminal-window -params 1.. -docstring '
|
2018-12-21 18:14:28 +01:00
|
|
|
screen-terminal-window <program> [<arguments>]: create a new terminal as a screen window
|
|
|
|
The program passed as argument will be executed in the new terminal' \
|
2018-12-02 13:59:45 +01:00
|
|
|
%{
|
2018-05-06 23:29:52 +02:00
|
|
|
nop %sh{
|
2017-09-23 16:26:57 +02:00
|
|
|
tty="$(ps -o tty ${kak_client_pid} | tail -n 1)"
|
2018-12-21 18:14:28 +01:00
|
|
|
screen -X screen "$@" < "/dev/$tty"
|
2017-09-23 16:26:57 +02:00
|
|
|
}
|
|
|
|
}
|
2022-02-22 10:14:47 +01:00
|
|
|
complete-command screen-terminal-window shell
|
2017-09-23 16:26:57 +02:00
|
|
|
|
2022-02-22 10:14:47 +01:00
|
|
|
define-command screen-focus -params ..1 -docstring '
|
2018-12-02 13:59:45 +01:00
|
|
|
screen-focus [<client>]: focus the given client
|
|
|
|
If no client is passed then the current one is used' \
|
|
|
|
%{
|
|
|
|
evaluate-commands %sh{
|
2017-09-23 16:26:57 +02:00
|
|
|
if [ $# -eq 1 ]; then
|
|
|
|
printf %s\\n "
|
2017-11-17 20:40:42 +01:00
|
|
|
evaluate-commands -client '$1' focus
|
|
|
|
"
|
2017-11-15 15:42:37 +01:00
|
|
|
elif [ -n "${kak_client_env_STY}" ]; then
|
2017-09-23 16:26:57 +02:00
|
|
|
tty="$(ps -o tty ${kak_client_pid} | tail -n 1)"
|
2017-11-17 20:40:42 +01:00
|
|
|
screen -X select "${kak_client_env_WINDOW}" < "/dev/$tty"
|
2017-09-23 16:26:57 +02:00
|
|
|
fi
|
2018-12-02 13:59:45 +01:00
|
|
|
}
|
|
|
|
}
|
2022-07-19 15:56:05 +02:00
|
|
|
complete-command -menu screen-focus client
|
2019-03-13 19:15:59 +01:00
|
|
|
|
|
|
|
alias global focus screen-focus
|
|
|
|
alias global terminal screen-terminal-vertical
|
|
|
|
|
|
|
|
}
|