2019-03-13 19:15:59 +01:00
|
|
|
# x11
|
|
|
|
|
|
|
|
provide-module x11 %{
|
|
|
|
|
2020-07-05 04:02:59 +02:00
|
|
|
# ensure that we're running in the right environment
|
|
|
|
evaluate-commands %sh{
|
2020-07-06 13:55:54 +02:00
|
|
|
[ -z "${kak_opt_windowing_modules}" ] || [ -n "$DISPLAY" ] || echo 'fail DISPLAY is not set'
|
2020-07-05 04:02:59 +02:00
|
|
|
}
|
|
|
|
|
2018-04-19 19:28:32 +02:00
|
|
|
# termcmd should be set such as the next argument is the whole
|
2014-04-10 20:40:52 +02:00
|
|
|
# command line to execute
|
2017-11-03 08:34:41 +01:00
|
|
|
declare-option -docstring %{shell command run to spawn a new terminal
|
2018-04-19 19:28:32 +02:00
|
|
|
A shell command is appended to the one set in this option at runtime} \
|
2017-05-16 13:35:43 +02:00
|
|
|
str termcmd %sh{
|
2017-06-08 19:02:44 +02:00
|
|
|
for termcmd in 'alacritty -e sh -c' \
|
2018-06-19 09:38:15 +02:00
|
|
|
'kitty sh -c' \
|
2017-06-08 19:02:44 +02:00
|
|
|
'termite -e ' \
|
2015-11-06 08:14:50 +01:00
|
|
|
'urxvt -e sh -c' \
|
|
|
|
'rxvt -e sh -c' \
|
2019-06-07 21:16:49 +02:00
|
|
|
'st -e sh -c' \
|
2015-11-06 08:14:50 +01:00
|
|
|
'xterm -e sh -c' \
|
|
|
|
'roxterm -e sh -c' \
|
|
|
|
'mintty -e sh -c' \
|
2017-07-25 10:26:52 +02:00
|
|
|
'sakura -x ' \
|
2015-11-06 08:14:50 +01:00
|
|
|
'gnome-terminal -e ' \
|
2021-07-08 03:44:17 +02:00
|
|
|
'xfce4-terminal -x sh -c' \
|
2019-03-06 10:58:57 +01:00
|
|
|
'konsole -e '; do
|
2015-11-06 08:14:50 +01:00
|
|
|
terminal=${termcmd%% *}
|
2017-05-16 14:18:45 +02:00
|
|
|
if command -v $terminal >/dev/null 2>&1; then
|
2018-05-06 23:29:52 +02:00
|
|
|
printf %s\\n "$termcmd"
|
2015-11-06 08:14:50 +01:00
|
|
|
exit
|
|
|
|
fi
|
|
|
|
done
|
2012-12-26 17:52:17 +01:00
|
|
|
}
|
|
|
|
|
2022-02-22 10:14:47 +01:00
|
|
|
define-command x11-terminal -params 1.. -docstring '
|
2021-06-13 04:12:03 +02:00
|
|
|
x11-terminal <program> [<arguments>]: create a new terminal as an X11 window
|
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
|
|
|
%{
|
2020-01-13 05:23:35 +01:00
|
|
|
evaluate-commands -save-regs 'a' %{
|
|
|
|
set-register a %arg{@}
|
|
|
|
evaluate-commands %sh{
|
|
|
|
if [ -z "${kak_opt_termcmd}" ]; then
|
|
|
|
echo "fail 'termcmd option is not set'"
|
|
|
|
exit
|
|
|
|
fi
|
2022-12-11 19:30:02 +01:00
|
|
|
termcmd=$kak_opt_termcmd
|
|
|
|
args=$kak_quoted_reg_a
|
|
|
|
unset kak_opt_termcmd kak_quoted_reg_a
|
|
|
|
setsid ${termcmd} "$args" < /dev/null > /dev/null 2>&1 &
|
2020-01-13 05:23:35 +01:00
|
|
|
}
|
2018-12-02 13:59:45 +01:00
|
|
|
}
|
|
|
|
}
|
2022-02-22 10:14:47 +01:00
|
|
|
complete-command x11-terminal shell
|
2018-12-02 13:59:45 +01:00
|
|
|
|
2022-02-22 10:14:47 +01:00
|
|
|
define-command x11-focus -params ..1 -docstring '
|
2018-12-02 13:59:45 +01:00
|
|
|
x11-focus [<kakoune_client>]: focus a given client''s window
|
|
|
|
If no client is passed, then the current client is used' \
|
|
|
|
%{
|
|
|
|
evaluate-commands %sh{
|
2016-10-11 09:03:41 +02:00
|
|
|
if [ $# -eq 1 ]; then
|
2018-12-02 13:59:45 +01:00
|
|
|
printf "evaluate-commands -client '%s' focus" "$1"
|
2015-11-17 23:25:33 +01:00
|
|
|
else
|
2020-07-11 18:23:27 +02:00
|
|
|
xdotool windowactivate $kak_client_env_WINDOWID > /dev/null ||
|
|
|
|
echo 'fail failed to run x11-focus, see *debug* buffer for details'
|
2015-11-17 23:25:33 +01:00
|
|
|
fi
|
2018-12-02 13:59:45 +01:00
|
|
|
}
|
|
|
|
}
|
2022-07-19 15:56:05 +02:00
|
|
|
complete-command -menu x11-focus client
|
2015-11-17 23:25:33 +01:00
|
|
|
|
|
|
|
alias global focus x11-focus
|
2018-12-02 13:59:45 +01:00
|
|
|
alias global terminal x11-terminal
|
2019-03-13 19:15:59 +01:00
|
|
|
|
|
|
|
}
|