summaryrefslogtreecommitdiff
path: root/rc/paths
diff options
context:
space:
mode:
authorAlex Leferry 2 <alexherbo2@gmail.com>2020-08-13 18:21:25 +0200
committerAlex Leferry 2 <alexherbo2@gmail.com>2020-08-13 21:33:41 +0200
commit7fe2efc9bed557373e9c9cfe860d8e684dfd56bc (patch)
tree90e2a1c628b6ccc05c04415011255200c312f746 /rc/paths
parentdefb50fc0ace0195d12e804993b1b74343024ada (diff)
Overhaul
Diffstat (limited to 'rc/paths')
l---------rc/paths/aliases/:a1
l---------rc/paths/aliases/:b1
l---------rc/paths/aliases/:e1
l---------rc/paths/aliases/a2
l---------rc/paths/aliases/b2
l---------rc/paths/aliases/e2
-rwxr-xr-xrc/paths/commands/:attach4
-rwxr-xr-xrc/paths/commands/:buffer7
-rwxr-xr-xrc/paths/commands/:cd4
-rwxr-xr-xrc/paths/commands/:edit35
-rwxr-xr-xrc/paths/commands/:get7
-rwxr-xr-xrc/paths/commands/:it3
-rwxr-xr-xrc/paths/commands/:ls6
-rwxr-xr-xrc/paths/commands/:send6
-rwxr-xr-xrc/paths/commands/attach16
-rwxr-xr-xrc/paths/commands/buffer38
-rwxr-xr-xrc/paths/commands/cd!4
-rwxr-xr-xrc/paths/commands/edit75
-rwxr-xr-xrc/paths/commands/get10
-rwxr-xr-xrc/paths/commands/it5
-rwxr-xr-xrc/paths/commands/send11
21 files changed, 78 insertions, 162 deletions
diff --git a/rc/paths/aliases/:a b/rc/paths/aliases/:a
new file mode 120000
index 0000000..aa48667
--- /dev/null
+++ b/rc/paths/aliases/:a
@@ -0,0 +1 @@
+../commands/:attach \ No newline at end of file
diff --git a/rc/paths/aliases/:b b/rc/paths/aliases/:b
new file mode 120000
index 0000000..85d8725
--- /dev/null
+++ b/rc/paths/aliases/:b
@@ -0,0 +1 @@
+../commands/:buffer \ No newline at end of file
diff --git a/rc/paths/aliases/:e b/rc/paths/aliases/:e
new file mode 120000
index 0000000..75c9534
--- /dev/null
+++ b/rc/paths/aliases/:e
@@ -0,0 +1 @@
+../commands/:edit \ No newline at end of file
diff --git a/rc/paths/aliases/a b/rc/paths/aliases/a
index ad2cb98..aa48667 120000
--- a/rc/paths/aliases/a
+++ b/rc/paths/aliases/a
@@ -1 +1 @@
-../commands/attach \ No newline at end of file
+../commands/:attach \ No newline at end of file
diff --git a/rc/paths/aliases/b b/rc/paths/aliases/b
index daf79f2..85d8725 120000
--- a/rc/paths/aliases/b
+++ b/rc/paths/aliases/b
@@ -1 +1 @@
-../commands/buffer \ No newline at end of file
+../commands/:buffer \ No newline at end of file
diff --git a/rc/paths/aliases/e b/rc/paths/aliases/e
index 1cb50b6..75c9534 120000
--- a/rc/paths/aliases/e
+++ b/rc/paths/aliases/e
@@ -1 +1 @@
-../commands/edit \ No newline at end of file
+../commands/:edit \ No newline at end of file
diff --git a/rc/paths/commands/:attach b/rc/paths/commands/:attach
new file mode 100755
index 0000000..2894021
--- /dev/null
+++ b/rc/paths/commands/:attach
@@ -0,0 +1,4 @@
+#!/bin/sh
+
+# Reattach to the session.
+kak -c "$KAKOUNE_SESSION" "$@"
diff --git a/rc/paths/commands/:buffer b/rc/paths/commands/:buffer
new file mode 100755
index 0000000..0d63f2a
--- /dev/null
+++ b/rc/paths/commands/:buffer
@@ -0,0 +1,7 @@
+#!/bin/sh
+
+# Open buffer
+:send buffer "$@"
+
+# Focus back the client
+:send focus
diff --git a/rc/paths/commands/:cd b/rc/paths/commands/:cd
new file mode 100755
index 0000000..a936e3c
--- /dev/null
+++ b/rc/paths/commands/:cd
@@ -0,0 +1,4 @@
+#!/bin/sh
+
+# Sync to your current working directory
+:send cd "$PWD"
diff --git a/rc/paths/commands/:edit b/rc/paths/commands/:edit
new file mode 100755
index 0000000..65c26d9
--- /dev/null
+++ b/rc/paths/commands/:edit
@@ -0,0 +1,35 @@
+#!/bin/sh
+
+. "$KAKOUNE_PRELUDE"
+
+# Skip options
+[ "$1" = '--' ] && shift
+
+# Open files
+commands=$(
+ while [ "$1" ]; do
+ file=$(realpath "$1")
+ case "$2" in
+ '+'*':'*)
+ line=${2#+}; line=${line%:*}
+ column=${2#*:}
+ shift 2
+ kak_escape edit "$file" "$line" "$column"
+ ;;
+ '+'*)
+ line=${2#+}
+ shift 2
+ kak_escape edit "$file" "$line"
+ ;;
+ *)
+ shift 1
+ kak_escape edit "$file"
+ ;;
+ esac
+ done
+)
+
+:send "$commands"
+
+# Focus back the client
+:send focus
diff --git a/rc/paths/commands/:get b/rc/paths/commands/:get
new file mode 100755
index 0000000..13bf2fc
--- /dev/null
+++ b/rc/paths/commands/:get
@@ -0,0 +1,7 @@
+#!/bin/sh
+
+# Get a value from a client
+mkfifo connect.fifo
+trap 'rm connect.fifo' EXIT
+:send echo -to-file "$PWD/connect.fifo" "$@"
+cat connect.fifo
diff --git a/rc/paths/commands/:it b/rc/paths/commands/:it
new file mode 100755
index 0000000..17cc516
--- /dev/null
+++ b/rc/paths/commands/:it
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+:get %val{buffile}
diff --git a/rc/paths/commands/:ls b/rc/paths/commands/:ls
new file mode 100755
index 0000000..e41719d
--- /dev/null
+++ b/rc/paths/commands/:ls
@@ -0,0 +1,6 @@
+#!/bin/sh
+
+# List buffers
+kak_quoted_buflist=$(:get %val{buflist})
+eval "set -- $kak_quoted_buflist"
+printf '%s\n' "$@"
diff --git a/rc/paths/commands/:send b/rc/paths/commands/:send
new file mode 100755
index 0000000..86f90a6
--- /dev/null
+++ b/rc/paths/commands/:send
@@ -0,0 +1,6 @@
+#!/bin/sh
+
+. "$KAKOUNE_PRELUDE"
+
+# Send commands to the client
+kak_escape evaluate-commands -try-client "$KAKOUNE_CLIENT" "$@" | kak -p "$KAKOUNE_SESSION"
diff --git a/rc/paths/commands/attach b/rc/paths/commands/attach
deleted file mode 100755
index b7f1471..0000000
--- a/rc/paths/commands/attach
+++ /dev/null
@@ -1,16 +0,0 @@
-#!/bin/sh
-
-# Attach a command ran from Kakoune with :connect-detach.
-
-if test -e "$KAKOUNE_CONNECT_SCRIPT"; then
- mv "$KAKOUNE_CONNECT_SCRIPT" "$KAKOUNE_CONNECT_SCRIPT~"
- sh "$KAKOUNE_CONNECT_SCRIPT~"
- # Note:
- # This script is deleted by :connect-detach when reattaching to the session.
- # If the script still exists, sh <connect-script> did not reattach.
- # Mitigate the need to manually reattach.
- if test -e "$KAKOUNE_CONNECT_SCRIPT~"; then
- rm -f "$KAKOUNE_CONNECT_SCRIPT~"
- edit
- fi
-fi
diff --git a/rc/paths/commands/buffer b/rc/paths/commands/buffer
deleted file mode 100755
index 46b594e..0000000
--- a/rc/paths/commands/buffer
+++ /dev/null
@@ -1,38 +0,0 @@
-#!/bin/sh
-
-# Open buffers. With no argument, list buffers instead.
-
-. "$KAKOUNE_PRELUDE"
-
-main() {
- if test $# -eq 0; then
- list
- else
- edit "$@"
- # Try to attach a connect terminal command
- attach
- fi
-}
-
-list() {
- kak_quoted_buflist=$(get '%val{buflist}')
- eval "set -- $kak_quoted_buflist"
- printf '%s\n' "$@"
-}
-
-edit() {
- commands=''
- for buffer do
- kak_quoted_buffer=$(kak_escape "$buffer")
- commands="buffer $kak_quoted_buffer; $commands"
- done
- # Attach to terminal.
- # Ensure there is a terminal.
- if test -t 1 -a "$KAKOUNE_CONNECT_ATTACH" = true; then
- kak -c "$KAKOUNE_SESSION" -e "$commands"
- else
- send "$commands"
- fi
-}
-
-main "$@"
diff --git a/rc/paths/commands/cd! b/rc/paths/commands/cd!
deleted file mode 100755
index f2e6304..0000000
--- a/rc/paths/commands/cd!
+++ /dev/null
@@ -1,4 +0,0 @@
-#!/bin/sh
-
-# Sync the Kakoune working directory to your current working directory.
-send cd "$PWD"
diff --git a/rc/paths/commands/edit b/rc/paths/commands/edit
deleted file mode 100755
index f34d228..0000000
--- a/rc/paths/commands/edit
+++ /dev/null
@@ -1,75 +0,0 @@
-#!/bin/sh
-
-# Open files.
-
-. "$KAKOUNE_PRELUDE"
-
-# Option parser
-# For the simplicity of parsing, we only parse the first argument.
-wait=false
-case "$1" in
- -wait) wait=true; shift ;;
- --) shift; break ;;
-esac
-
-commands=''
-regex=''
-while test $# -gt 0; do
- file=$(realpath "$1")
- kak_quoted_file=$(kak_escape "$file")
- # Optional coordinates
- case "$2" in
- +*:*)
- line=${2#+}; line=${line%:*}
- column=${2#*:}
- shift 2
- commands="edit $kak_quoted_file $line $column; $commands"
- ;;
- +*)
- line=${2#+}
- shift 2
- commands="edit $kak_quoted_file $line; $commands"
- ;;
- *)
- shift
- commands="edit $kak_quoted_file; $commands"
- ;;
- esac
- regex="${regex}|\\Q${file}\\E"
-done
-# Focus back the client on open.
-commands="$commands; focus"
-regex=${regex#|}
-kak_quoted_regex=$(kak_escape "$regex")
-
-# Attach to terminal.
-# Note: Ensure there is a terminal.
-# Motivation: GUI apps can connect to the client.
-# Example: :connect-shell dolphin
-if test -t 1 -a "$KAKOUNE_CONNECT_ATTACH" = true; then
- kak -c "$KAKOUNE_SESSION" -e "$commands"
-else
- send "$commands"
-fi
-
-if test "$wait" = true; then
- state=$(mktemp -d)
- trap 'rm -Rf "$state"' EXIT
- mkfifo "$state/status"
- send "
- hook -group connect-detach global BufWritePost $kak_quoted_regex %{
- remove-hooks global connect-detach
- delete-buffer %val{hook_param}
- echo -to-file $state/status 0
- }
- hook -group connect-detach global BufClose $kak_quoted_regex %{
- remove-hooks global connect-detach
- echo -to-file $state/status 1
- }
- "
- read status < "$state/status"
- exit "$status"
-fi
-
-# Try to attach a connect terminal command
-attach
diff --git a/rc/paths/commands/get b/rc/paths/commands/get
deleted file mode 100755
index f9ef02d..0000000
--- a/rc/paths/commands/get
+++ /dev/null
@@ -1,10 +0,0 @@
-#!/bin/sh
-
-# Get a property.
-
-state=$(mktemp -d)
-trap 'rm -Rf "$state"' EXIT
-mkfifo "$state/fifo"
-
-send echo -to-file "$state/fifo" "$@"
-cat "$state/fifo"
diff --git a/rc/paths/commands/it b/rc/paths/commands/it
deleted file mode 100755
index 92c5869..0000000
--- a/rc/paths/commands/it
+++ /dev/null
@@ -1,5 +0,0 @@
-#!/bin/sh
-
-# Get the current buffer.
-
-get %val{buffile}
diff --git a/rc/paths/commands/send b/rc/paths/commands/send
deleted file mode 100755
index f107e71..0000000
--- a/rc/paths/commands/send
+++ /dev/null
@@ -1,11 +0,0 @@
-#!/bin/sh
-
-# Send a command.
-
-. "$KAKOUNE_PRELUDE"
-
-if test -n "$KAKOUNE_SESSION" -a -n "$KAKOUNE_CLIENT"; then
- kak_escape evaluate-commands -try-client "$KAKOUNE_CLIENT" "$@" | kak -p "$KAKOUNE_SESSION"
-elif test -n "$KAKOUNE_SESSION"; then
- kak -c "$KAKOUNE_SESSION" -e "$@"
-fi