kakoune

Fork of kakoune, an acceptable text editor
git clone git://git.laack.co/kakoune.git
Log | Files | Refs

screen.kak (2541B)


      1 # http://gnu.org/software/screen/
      2 # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
      3 
      4 
      5 provide-module screen %{
      6 
      7 # ensure that we're running under screen
      8 evaluate-commands %sh{
      9     [ -z "${kak_opt_windowing_modules}" ] || [ -n "$STY" ] || echo 'fail screen not detected'
     10 }
     11 
     12 define-command screen-terminal-impl -hidden -params 3.. %{
     13     nop %sh{
     14         tty="$(ps -o tty ${kak_client_pid} | tail -n 1)"
     15         screen -X eval "$1" "$2"
     16         shift 2
     17         # see x11.kak for what this achieves
     18         args=$(
     19             for i in "$@"; do
     20                 printf "'%s' " "$(printf %s "$i" | sed "s|'|'\\\\''|g")"
     21             done
     22         )
     23         screen -X screen sh -c "${args} ; screen -X remove" < "/dev/$tty"
     24     }
     25 }
     26 
     27 define-command screen-terminal-vertical -params 1.. -docstring '
     28 screen-terminal-vertical <program> [<arguments>]: create a new terminal as a screen pane
     29 The current pane is split into two, left and right
     30 The program passed as argument will be executed in the new terminal' \
     31 %{
     32     screen-terminal-impl 'split -v' 'focus right' %arg{@}
     33 }
     34 complete-command screen-terminal-vertical shell
     35 
     36 define-command screen-terminal-horizontal -params 1.. -docstring '
     37 screen-terminal-horizontal <program> [<arguments>]: create a new terminal as a screen pane
     38 The current pane is split into two, top and bottom
     39 The program passed as argument will be executed in the new terminal' \
     40 %{
     41     screen-terminal-impl 'split -h' 'focus down' %arg{@}
     42 }
     43 complete-command screen-terminal-horizontal shell
     44 
     45 define-command screen-terminal-window -params 1.. -docstring '
     46 screen-terminal-window <program> [<arguments>]: create a new terminal as a screen window
     47 The program passed as argument will be executed in the new terminal' \
     48 %{
     49     nop %sh{
     50         tty="$(ps -o tty ${kak_client_pid} | tail -n 1)"
     51         screen -X screen "$@" < "/dev/$tty"
     52     }
     53 }
     54 complete-command screen-terminal-window shell
     55 
     56 define-command screen-focus -params ..1 -docstring '
     57 screen-focus [<client>]: focus the given client
     58 If no client is passed then the current one is used' \
     59 %{
     60     evaluate-commands %sh{
     61         if [ $# -eq 1 ]; then
     62             printf %s\\n "
     63                 evaluate-commands -client '$1' focus
     64                 "
     65         elif [ -n "${kak_client_env_STY}" ]; then
     66             tty="$(ps -o tty ${kak_client_pid} | tail -n 1)"
     67             screen -X select "${kak_client_env_WINDOW}" < "/dev/$tty"
     68         fi
     69     }
     70 }
     71 complete-command -menu screen-focus client 
     72 
     73 alias global focus screen-focus
     74 
     75 }