M Makefile => Makefile +2 -0
@@ 183,6 183,8 @@ installdirs-debug-yes: installdirs-debug-no
install: src/kak installdirs install-debug-$(debug) install-gzip-man-$(gzip_man)
cp src/kak$(suffix) $(bindir)
chmod 0755 $(bindir)/kak
+ cp src/kak-connect$(suffix) $(bindir)
+ chmod 0755 $(bindir)/kak-connect
ln -sf ../../bin/kak $(libexecdir)/kak
A rc/windowing/connect.kak => rc/windowing/connect.kak +19 -0
@@ 0,0 1,19 @@
+define-command -override connect -params 1.. -command-completion -docstring 'Run a command as <command> sh -c {connect} -- [arguments]. Example: connect terminal sh' %{
+ %arg{1} sh -c %{
+ export KAKOUNE_SESSION=$1
+ export KAKOUNE_CLIENT=$2
+ shift 3
+
+ export EDITOR='kak-connect'
+
+ [ $# = 0 ] && set -- "$SHELL"
+
+ "$@"
+ } -- %val{session} %val{client} %arg{@}
+}
+
+define-command -override run -params 1.. -shell-completion -docstring 'Run a program in a new session' %{
+ nop %sh{
+ nohup "$@" < /dev/null > /dev/null 2>&1 &
+ }
+}
A src/kak-connect => src/kak-connect +27 -0
@@ 0,0 1,27 @@
+#!/bin/sh
+
+if [ -z "$*" ] ; then
+ cat <<EOF >&2
+Usage: $(basename "$0") <file> ...
+
+Edit the files in a connected Kakoune session.
+EOF
+ exit 1
+fi
+
+if [ -z "$KAKOUNE_CLIENT" ] || [ -z "$KAKOUNE_SESSION" ]; then
+ cat <<EOF >&2
+No connected Kakoune session.
+EOF
+ exit 1
+fi
+
+while [ -n "$1" ]; do
+ realpath "$1" | \
+ tr '\n' '\0' | \
+ sed 's| |\\ |g' | \
+ xargs -0 printf 'evaluate-commands -try-client %s edit "%s"\n' "$KAKOUNE_CLIENT" | \
+ kak -p "$KAKOUNE_SESSION"
+ shift
+done
+