summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorAlex Leferry 2 <alexherbo2@gmail.com>2020-06-26 22:15:39 +0200
committerAlex Leferry 2 <alexherbo2@gmail.com>2020-06-26 23:23:04 +0200
commit884ddc581bdc59d23bf40a48cb97536b10ce05a5 (patch)
treeef33670cab19d3e8ad3eaa158e8515400fd216ed /bin
parente514458d045f70aea0b3573c1d7c1a12f81043c6 (diff)
Split kak-connect into kak-shell and kak-desktop
Diffstat (limited to 'bin')
-rwxr-xr-xbin/kak-connect72
-rwxr-xr-xbin/kak-desktop23
-rwxr-xr-xbin/kak-shell49
3 files changed, 72 insertions, 72 deletions
diff --git a/bin/kak-connect b/bin/kak-connect
deleted file mode 100755
index 9612ee3..0000000
--- a/bin/kak-connect
+++ /dev/null
@@ -1,72 +0,0 @@
-#!/bin/sh
-
-# Environment variables ────────────────────────────────────────────────────────
-
-XDG_DATA_HOME=${XDG_DATA_HOME:-~/.local/share}
-KAKOUNE_CONNECT_SCRIPT=$XDG_DATA_HOME/kak/connect/script.sh
-
-# Main ─────────────────────────────────────────────────────────────────────────
-
-main() {
-
- # Send the edit command to the session / client.
- if test -n "$KAKOUNE_SESSION" -o -n "$KAKOUNE_CLIENT"; then
- edit "$@"
-
- # Try to connect to an existing session from a previous :connect-detach command.
- elif test -t 1 -a -e "$KAKOUNE_CONNECT_SCRIPT"; then
- attach
-
- # Create a session and attach if there is a terminal.
- elif test -t 1; then
- kak_session=$$
- # Start a connected shell or edit files.
- if test $# -eq 0; then
- cat <<EOF | sed -E 's/^ {8}//'
- Starting a shell connected to the '$kak_session' Kakoune session.
-
- • [e]dit to attach
- • CTRL-D to quit
-
- ❯ (connect-shell) █
-EOF
- set -- "$SHELL"
- else
- set -- 'edit' "$@"
- fi
- # Start the session in daemon mode.
- setsid kak -s "$kak_session" -d < /dev/null > /dev/null 2>&1
- # Alias terminal to connect-detach and enter in the connect environment.
- # connect-detach allows to run CLI commands in the same terminal window.
- kak -c "$kak_session" -e "
- alias global terminal connect-detach
- set-option global connect_attach yes
- connect-terminal $@
- "
- # Attach the connect terminal command.
- # Act as a “boot loader”.
- if test -e "$KAKOUNE_CONNECT_SCRIPT"; then
- attach
- fi
-
- # GUI apps.
- else
- file=$1 line=$2 column=$3
- kak -ui dummy -e "
- new %{
- hook -always -once global ClientClose %val{client} kill!
- edit %{$file} $line $column
- }
- "
- fi
-}
-
-# Functions ────────────────────────────────────────────────────────────────────
-
-attach() {
- mv "$KAKOUNE_CONNECT_SCRIPT" "$KAKOUNE_CONNECT_SCRIPT~"
- sh "$KAKOUNE_CONNECT_SCRIPT~"
- rm -f "$KAKOUNE_CONNECT_SCRIPT~"
-}
-
-main "$@"
diff --git a/bin/kak-desktop b/bin/kak-desktop
new file mode 100755
index 0000000..53925ec
--- /dev/null
+++ b/bin/kak-desktop
@@ -0,0 +1,23 @@
+#!/bin/sh
+
+main() {
+ # Send the edit command to the client.
+ if test -n "$KAKOUNE_SESSION" -a -n "$KAKOUNE_CLIENT"; then
+ edit "$@"
+ # GUI apps.
+ else
+ launch "$@"
+ fi
+}
+
+launch() {
+ file=$1 line=$2 column=$3
+ kak -ui dummy -e "
+ new %{
+ hook -always -once global ClientClose %val{client} kill!
+ edit %{$file} $line $column
+ }
+ "
+}
+
+main "$@"
diff --git a/bin/kak-shell b/bin/kak-shell
new file mode 100755
index 0000000..1b65946
--- /dev/null
+++ b/bin/kak-shell
@@ -0,0 +1,49 @@
+#!/bin/sh
+
+# Usage
+USAGE='kak-shell [-s <session>] [-c <session>] [program]: Start an interactive shell.'
+
+# Environment variables
+XDG_DATA_HOME=${XDG_DATA_HOME:-~/.local/share}
+KAKOUNE_CONNECT_SCRIPT=$XDG_DATA_HOME/kak/connect/script.sh
+
+main() {
+ # Usage
+ if test $# -eq 0; then
+ printf '%s\n' "$USAGE" > /dev/stderr
+ exit 1
+ fi
+ # Option parser
+ case "$1" in
+ -s) KAKOUNE_SESSION=$2; shift 2; start "$@" ;;
+ -c) KAKOUNE_SESSION=$2; shift 2; connect "$@" ;;
+ esac
+}
+
+start() {
+ # Start the session in daemon mode.
+ setsid kak -s "$KAKOUNE_SESSION" -d < /dev/null > /dev/null 2>&1
+ connect "$@"
+}
+
+connect() {
+ # Alias terminal to connect-detach and enter in the connect environment.
+ # connect-detach allows to run CLI apps in the same terminal window.
+ kak -c "$KAKOUNE_SESSION" -e "
+ connect-set-detach global
+ connect-terminal $@
+ "
+ # Attach the connect terminal command.
+ # Act as a “boot loader”.
+ if test -e "$KAKOUNE_CONNECT_SCRIPT"; then
+ attach
+ fi
+}
+
+attach() {
+ mv "$KAKOUNE_CONNECT_SCRIPT" "$KAKOUNE_CONNECT_SCRIPT~"
+ sh "$KAKOUNE_CONNECT_SCRIPT~"
+ rm -f "$KAKOUNE_CONNECT_SCRIPT~"
+}
+
+main "$@"