2018-04-19 20:28:32 +03:00
|
|
|
# termcmd should be set such as the next argument is the whole
|
2014-04-10 22:40:52 +04:00
|
|
|
# command line to execute
|
2017-11-03 10:34:41 +03:00
|
|
|
declare-option -docstring %{shell command run to spawn a new terminal
|
2018-04-19 20:28:32 +03:00
|
|
|
A shell command is appended to the one set in this option at runtime} \
|
2017-05-16 14:35:43 +03:00
|
|
|
str termcmd %sh{
|
2017-06-08 20:02:44 +03:00
|
|
|
for termcmd in 'alacritty -e sh -c' \
|
2018-06-19 10:38:15 +03:00
|
|
|
'kitty sh -c' \
|
2017-06-08 20:02:44 +03:00
|
|
|
'termite -e ' \
|
2015-11-06 10:14:50 +03:00
|
|
|
'urxvt -e sh -c' \
|
|
|
|
'rxvt -e sh -c' \
|
|
|
|
'xterm -e sh -c' \
|
|
|
|
'roxterm -e sh -c' \
|
|
|
|
'mintty -e sh -c' \
|
2017-07-25 11:26:52 +03:00
|
|
|
'sakura -x ' \
|
2015-11-06 10:14:50 +03:00
|
|
|
'gnome-terminal -e ' \
|
|
|
|
'xfce4-terminal -e ' ; do
|
|
|
|
terminal=${termcmd%% *}
|
2017-05-16 15:18:45 +03:00
|
|
|
if command -v $terminal >/dev/null 2>&1; then
|
2018-05-07 00:29:52 +03:00
|
|
|
printf %s\\n "$termcmd"
|
2015-11-06 10:14:50 +03:00
|
|
|
exit
|
|
|
|
fi
|
|
|
|
done
|
2012-12-26 20:52:17 +04:00
|
|
|
}
|
|
|
|
|
2018-12-21 20:14:28 +03: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 15:59:45 +03:00
|
|
|
%{
|
|
|
|
evaluate-commands %sh{
|
2015-11-06 10:14:50 +03:00
|
|
|
if [ -z "${kak_opt_termcmd}" ]; then
|
2018-12-02 15:59:45 +03:00
|
|
|
echo "fail 'termcmd option is not set'"
|
2015-11-06 10:14:50 +03:00
|
|
|
exit
|
|
|
|
fi
|
2018-12-21 20:14:28 +03: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 15:59:45 +03: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 10:03:41 +03:00
|
|
|
if [ $# -eq 1 ]; then
|
2018-12-02 15:59:45 +03:00
|
|
|
printf "evaluate-commands -client '%s' focus" "$1"
|
2015-11-18 01:25:33 +03:00
|
|
|
else
|
|
|
|
xdotool windowactivate $kak_client_env_WINDOWID > /dev/null
|
|
|
|
fi
|
2018-12-02 15:59:45 +03:00
|
|
|
}
|
|
|
|
}
|
2015-11-18 01:25:33 +03:00
|
|
|
|
|
|
|
alias global focus x11-focus
|
2018-12-02 15:59:45 +03:00
|
|
|
alias global terminal x11-terminal
|