2019-03-13 19:15:59 +01:00
|
|
|
# x11
|
|
|
|
|
|
|
|
hook global KakBegin .* %sh{
|
2019-03-27 18:17:37 +01:00
|
|
|
if [ -n "$DISPLAY" ] && [ -z "$TMUX" ]; then
|
2019-03-13 19:15:59 +01:00
|
|
|
echo "require-module x11"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
provide-module x11 %{
|
|
|
|
|
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' \
|
|
|
|
'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 ' \
|
2019-03-06 10:58:57 +01:00
|
|
|
'xfce4-terminal -e ' \
|
|
|
|
'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
|
|
|
}
|
|
|
|
|
2018-12-21 18:14:28 +01:00
|
|
|
define-command x11-terminal -params 1.. -shell-completion -docstring '
|
|
|
|
x11-terminal <program> [<arguments>]: create a new terminal as an x11 window
|
|
|
|
The program passed as argument will be executed in the new terminal' \
|
2018-12-02 13:59:45 +01:00
|
|
|
%{
|
|
|
|
evaluate-commands %sh{
|
2015-11-06 08:14:50 +01:00
|
|
|
if [ -z "${kak_opt_termcmd}" ]; then
|
2018-12-02 13:59:45 +01:00
|
|
|
echo "fail 'termcmd option is not set'"
|
2015-11-06 08:14:50 +01:00
|
|
|
exit
|
|
|
|
fi
|
2018-12-21 18:14:28 +01:00
|
|
|
# join arguments into a single string, in which they're delimited
|
|
|
|
# by single quotes, and with single quotes inside transformed to '\''
|
|
|
|
# so that sh -c "$args" will re-split the arguments properly
|
|
|
|
# example:
|
|
|
|
# $1 = ab
|
|
|
|
# $2 = foo bar
|
|
|
|
# $3 =
|
|
|
|
# $4 = foo'bar
|
|
|
|
# $args = 'ab' 'foo bar' '' 'foo'\''bar'
|
|
|
|
# would be nicer to do in a single sed/awk call but that's difficult
|
|
|
|
args=$(
|
|
|
|
for i in "$@"; do
|
|
|
|
# special case to preserve empty variables as sed won't touch these
|
|
|
|
if [ "$i" = '' ]; then
|
|
|
|
printf "'' "
|
|
|
|
else
|
|
|
|
printf %s "$i" | sed -e "s|'|'\\\\''|g; s|^|'|; s|$|' |"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
)
|
|
|
|
setsid ${kak_opt_termcmd} "$args" < /dev/null > /dev/null 2>&1 &
|
2018-12-02 13:59:45 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
define-command x11-focus -params ..1 -client-completion -docstring '
|
|
|
|
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
|
|
|
|
xdotool windowactivate $kak_client_env_WINDOWID > /dev/null
|
|
|
|
fi
|
2018-12-02 13:59:45 +01:00
|
|
|
}
|
|
|
|
}
|
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
|
|
|
|
|
|
|
}
|