x11.kak (2602B)
1 # x11 2 3 provide-module x11 %{ 4 5 # ensure that we're running in the right environment 6 evaluate-commands %sh{ 7 [ -z "${kak_opt_windowing_modules}" ] || [ -n "$DISPLAY" ] || echo 'fail DISPLAY is not set' 8 } 9 10 # termcmd should be set such as the next argument is the whole 11 # command line to execute 12 declare-option -docstring %{shell command run to spawn a new terminal 13 A shell command is appended to the one set in this option at runtime} \ 14 str termcmd %sh{ 15 for termcmd in 'alacritty -e sh -c' \ 16 'kitty sh -c' \ 17 'termite -e ' \ 18 'urxvt -e sh -c' \ 19 'rxvt -e sh -c' \ 20 'st -e sh -c' \ 21 'xterm -e sh -c' \ 22 'roxterm -e sh -c' \ 23 'mintty -e sh -c' \ 24 'sakura -x ' \ 25 'gnome-terminal -e ' \ 26 'xfce4-terminal -x sh -c' \ 27 'konsole -e '; do 28 terminal=${termcmd%% *} 29 if command -v $terminal >/dev/null 2>&1; then 30 printf %s\\n "$termcmd" 31 exit 32 fi 33 done 34 } 35 36 define-command x11-terminal-window -params 1.. -docstring ' 37 x11-terminal-window <program> [<arguments>]: create a new terminal as an X11 window 38 The program passed as argument will be executed in the new terminal' \ 39 %{ 40 evaluate-commands -save-regs 'a' %{ 41 set-register a %arg{@} 42 evaluate-commands %sh{ 43 if [ -z "${kak_opt_termcmd}" ]; then 44 echo "fail 'termcmd option is not set'" 45 exit 46 fi 47 termcmd=$kak_opt_termcmd 48 args=$kak_quoted_reg_a 49 unset kak_opt_termcmd kak_quoted_reg_a 50 setsid ${termcmd} "$args" < /dev/null > /dev/null 2>&1 & 51 } 52 } 53 } 54 complete-command x11-terminal-window shell 55 56 define-command x11-focus -params ..1 -docstring ' 57 x11-focus [<kakoune_client>]: focus a given client''s window 58 If no client is passed, then the current client is used' \ 59 %{ 60 evaluate-commands %sh{ 61 if [ $# -eq 1 ]; then 62 printf "evaluate-commands -client '%s' focus" "$1" 63 else 64 xdotool windowactivate $kak_client_env_WINDOWID > /dev/null || 65 echo 'fail failed to run x11-focus, see *debug* buffer for details' 66 fi 67 } 68 } 69 complete-command -menu x11-focus client 70 71 alias global focus x11-focus 72 73 # deprecated 74 define-command -hidden x11-terminal -params 1.. %{ 75 x11-terminal-window %arg{@} 76 } 77 78 }