diff options
| author | Alex Leferry 2 <alexherbo2@gmail.com> | 2020-08-13 18:21:25 +0200 |
|---|---|---|
| committer | Alex Leferry 2 <alexherbo2@gmail.com> | 2020-08-13 21:33:41 +0200 |
| commit | 7fe2efc9bed557373e9c9cfe860d8e684dfd56bc (patch) | |
| tree | 90e2a1c628b6ccc05c04415011255200c312f746 | |
| parent | defb50fc0ace0195d12e804993b1b74343024ada (diff) | |
Overhaul
39 files changed, 289 insertions, 438 deletions
diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..06b033b --- /dev/null +++ b/Makefile @@ -0,0 +1,9 @@ +install: + curl -sSL https://github.com/mawww/kakoune/raw/master/doc/kakoune_logo.svg --create-dirs -o ~/.local/share/icons/hicolor/scalable/apps/kakoune.svg + mkdir -p ~/.local/bin ~/.local/share/kak + ln -sf "${PWD}/bin/kak-shell" "${PWD}/bin/kak-desktop" ~/.local/bin + ln -sf "${PWD}/share/applications/kakoune-connect.desktop" ~/.local/share/applications + ln -sf "${PWD}/share/kak/connect" ~/.local/share/kak + +uninstall: + rm -Rf ~/.local/bin/kak-shell ~/.local/bin/kak-desktop ~/.local/share/kak/connect @@ -1,8 +1,6 @@ # connect.kak -###### [Installation](#installation) | [Usage](#usage) | [Configuration](#configuration) | [Documentation](#documentation) | [Contributing](CONTRIBUTING) - -Connect a program to [Kakoune] clients. +Leverage the client-server architecture of [Kakoune] to connect programs to clients. [Kakoune]: https://kakoune.org @@ -12,71 +10,72 @@ Connect a program to [Kakoune] clients. ## Dependencies - [prelude.kak] -- [terminal-mode.kak] [prelude.kak]: https://github.com/alexherbo2/prelude.kak -[terminal-mode.kak]: https://github.com/alexherbo2/terminal-mode.kak -### Suggestion +### Optional integrations - [explore.kak] +- [terminal-mode.kak] - [yank-ring.kak] [explore.kak]: https://github.com/alexherbo2/explore.kak +[terminal-mode.kak]: https://github.com/alexherbo2/terminal-mode.kak [yank-ring.kak]: https://github.com/alexherbo2/yank-ring.kak ## Installation +Run the following in your terminal: + +``` sh +make install +``` + Add [`rc`](rc) to your autoload or source [`connect.kak`](rc/connect.kak) and its [modules](rc/modules) manually. -### Start an interactive shell +## Usage -Add [`kak-shell`] to your path. +### Example 1 -[`kak-shell`]: bin/kak-shell +**Kakoune** – Open a new terminal: -### Add to desktop +``` kak +> +``` -1. Copy [`kakoune-connect.desktop`] to `$XDG_DATA_HOME/applications`. -2. Copy [Kakoune’s logo] to `$XDG_DATA_HOME/icons/hicolor/scalable/apps/kakoune.svg`. -3. Add [`kak-desktop`] to your path. -4. Open `$XDG_CONFIG_HOME/mimeapps.list` and add the following MIME type association: +**Terminal** – Open all `.txt` files: +``` sh +:e *.txt ``` -[Default Applications] -text/plain=kakoune-connect.desktop -text/xml=kakoune-connect.desktop + +### Example 2 + +**Kakoune** – Open [Dolphin]: + +``` kak +$ dolphin ``` -Add more entries to your liking. +[Dolphin]: https://dolphin.kde.org -[`kakoune-connect.desktop`]: share/applications/kakoune-connect.desktop -[`kak-desktop`]: bin/kak-desktop -[Kakoune’s logo]: https://github.com/mawww/kakoune/blob/master/doc/kakoune_logo.svg +### Example 3 -### Prompt +**Kakoune** – Same with [modules]: -1. Copy the [`prompt`] to `$XDG_DATA_HOME/kak/connect/prompt`. -2. Depending on your shell: +``` kak +require-module connect-dolphin -``` bash -PS1='$($XDG_DATA_HOME/kak/connect/prompt) $ ' +dolphin ``` -[`prompt`]: share/kak/connect/prompt - -## Usage +### Example 4 -Connect a terminal with `:connect-terminal`. -Open files with the `edit` shell command or your favorite program; -buffers with the `buffer` shell command… +**Terminal** – Manage sessions: -You can start an interactive shell (or a program) connected to a session – in the same way [nix-shell] does – with `kak-shell`. -By default, the connections occur in the same terminal window (try `:fzf-files` or `:fzf-buffers` to see); -you can change the terminal settings with `,tcr` (for _user mode_ – _terminal_ – _connect_ – _reset_), -which resets the detach option and prompts you to choose a windowing system ([X11], [tmux], etc.). -You can change it at your will with `,t`. -The [terminal-mode.kak] interface is similar to [i3’s split commands]. +``` sh +kak-shell +``` **Illustration** @@ -87,15 +86,9 @@ Kakoune sessions: 2 johto + create new session Kakoune session: 1█ -client0 at kanto $ edit -:fzf-files +@kanto $ :a█ ``` -[nix-shell]: https://nixos.org/nix/manual#sec-nix-shell -[X11]: https://x.org -[tmux]: https://github.com/tmux/tmux -[i3’s split commands]: https://i3wm.org/docs/userguide.html#OrientationSplit - ## Configuration ``` kak @@ -120,73 +113,29 @@ map global normal <c-q> ': quit!<ret>' map global normal Y ': yank-ring<ret>' ``` -By setting the option `connect_environment`, you can specify commands that +By setting the `connect_environment` option, you can specify commands that are run before the shell is executed. This might be useful, if you want to -change or export environment variables: +change or export environment variables. ``` kak set-option global connect_environment %{ SHELL=elvish - export GIT_EDITOR='kak -c "$KAKOUNE_SESSION"' - export LYEDITOR='edit %(file)s +%(line)s:%(column)s' + export GIT_EDITOR=:attach } ``` -## Documentation - -### Kakoune - -Defined in [`connect.kak`](rc/connect.kak). - -#### Commands - -- `connect-terminal` (alias: `t`): Connect a terminal. -- `connect-shell` (alias: `$`): Connect a shell. -- `connect-detach` (alias: `d`): Write the given shell command to your connect data path and detach the client. - -#### Options - -- `connect_attach`: Attach to terminal. Default is `no`. -- `connect_data_path`: Path to connect data. Default is `$XDG_DATA_HOME/kak/connect` or `~/.local/share/kak/connect`. - -#### Modules +### Custom prompt -Defined in [`modules`](rc/modules). - -- `connect-broot` -- `connect-dmenu` -- `connect-dolphin` -- `connect-fzf` -- `connect-lf` -- `connect-nnn` -- `connect-rofi` -- `connect-wofi` - -### Shell - -#### Commands - -Defined in [`commands`](rc/paths/commands) and [`aliases`](rc/paths/aliases). - -- `edit` (alias: `e`): Open files. -- `buffer` (alias: `b`): Open buffers. With no argument, list buffers instead. -- `attach` (alias: `a`): Attach a command ran from Kakoune with `:connect-detach`. -- `it`: Get the current buffer. -- `send`: Send a command. -- `get`: Get a property. -- `cd!`: Sync the Kakoune working directory to your current working directory. - -#### Environment variables +``` bash +PS1='$(~/.local/share/kak/connect/prompt) $ ' +``` -Defined in [`env`](rc/env). +## Documentation -- `IN_KAKOUNE_CONNECT`: Determine whether the shell is connected to a Kakoune session. -- `KAKOUNE_SESSION`: Kakoune session. -- `KAKOUNE_CLIENT`: Kakoune client. -- `KAKOUNE_CONNECT_SCRIPT`: Path to connect script, used by `:connect-detach` for writing shell commands. -- `KAKOUNE_CONNECT_ATTACH`: Whether to attach to terminal. -- `EDITOR`: Editor to be used. Default is `edit`. -- `VISUAL`: Visual editor to be used. Default is `edit`. -- `GIT_EDITOR`: [Git] editor to be used. Default is `edit -wait`. +- [Commands] +- [Aliases] +- [Modules] -[Git]: https://git-scm.com +[Commands]: rc/paths/commands +[Aliases]: rc/paths/aliases +[Modules]: rc/modules diff --git a/bin/kak-desktop b/bin/kak-desktop index 5e03ab7..f9c1aa3 100755 --- a/bin/kak-desktop +++ b/bin/kak-desktop @@ -1,24 +1,29 @@ #!/bin/sh main() { - # Send the edit command to the client. - if test -n "$IN_KAKOUNE_CONNECT"; then - edit "$@" - # Terminal. + # Send the edit command to the client + if [ "$IN_KAKOUNE_CONNECT" ]; then + :edit "$@" + + # Terminal elif test -t 0 -a -t 1; then kak "$@" - # GUI apps. + + # GUI apps else - launch "$@" + open "$@" fi } -launch() { +open() { + # Skip options + [ "$1" = '--' ] && shift + file=$1 line=$2 column=$3 kak -ui dummy -e " new %{ hook -always -once global ClientClose %val{client} kill! - edit %{$file} $line $column + edit %{$file} %{$line} %{$column} } " } diff --git a/bin/kak-shell b/bin/kak-shell index 1516f44..fc44687 100755 --- a/bin/kak-shell +++ b/bin/kak-shell @@ -1,67 +1,35 @@ #!/bin/sh -# Environment variables -XDG_DATA_HOME=${XDG_DATA_HOME:-~/.local/share} -KAKOUNE_CONNECT_SCRIPT=$XDG_DATA_HOME/kak/connect/script.sh - main() { - # Interactively set the Kakoune session. - # Support to connect to a session by its index. - if test -z "$KAKOUNE_SESSION"; then - kak_session_list=$(kak -l | sort) - echo 'Kakoune sessions:' - echo_n "$kak_session_list" | number_lines - echo '+ create new session' - echo_n 'Kakoune session:' - read kak_session - if is_number "$kak_session"; then - kak_session=$(echo "$kak_session_list" | get_line "$kak_session") - fi - KAKOUNE_SESSION=$kak_session - fi - # Exit if the Kakoune session is empty. - if test -z "$KAKOUNE_SESSION"; then - exit 1 - fi - # Start an interactive shell. - start "$@" -} + prompt_kakoune_session + [ "$text" ] || exit 1 -start() { - # Start the session in daemon mode. - setsid kak -s "$KAKOUNE_SESSION" -d < /dev/null > /dev/null 2>&1 - connect "$@" + connect "$text" "$@" } 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 + session=$1 + shift + setsid kak -s "$session" -d < /dev/null > /dev/null 2>&1 & + kak -c "$session" -e "connect-detach $@" + sh connect.sh +} + +prompt_kakoune_session() { + kak_session_list=$(kak -l | sort) + echo 'Kakoune sessions:' + printf "$kak_session_list" | number_lines + echo '+ create new session' + printf 'Kakoune session:' + read kak_session + if is_number "$kak_session"; then + kak_session=$(echo "$kak_session_list" | get_line "$kak_session") fi -} -attach() { - mv "$KAKOUNE_CONNECT_SCRIPT" "$KAKOUNE_CONNECT_SCRIPT~" - sh "$KAKOUNE_CONNECT_SCRIPT~" - rm -f "$KAKOUNE_CONNECT_SCRIPT~" + text=$kak_session } -# Utilities - -echo() { - printf '%s\n' "$*" -} - -echo_n() { - printf '%s' "$*" -} +# Utility functions ──────────────────────────────────────────────────────────── is_number() { test "$1" -eq "$1" 2> /dev/null diff --git a/rc/connect.kak b/rc/connect.kak index fa25239..2c7207b 100644 --- a/rc/connect.kak +++ b/rc/connect.kak @@ -1,91 +1,98 @@ +# Save the connect path declare-option -hidden str connect_path %sh(dirname "$kak_source") -declare-option str connect_environment - -hook global ModuleLoaded connect %{ - hook global ModuleLoaded terminal-mode %{ - require-module connect-terminal-mode - } - hook global KakBegin .* %{ - require-module connect-terminal-mode - } -} provide-module connect %{ + # Modules require-module prelude - declare-option -docstring 'Attach to terminal' bool connect_attach no - declare-option -docstring 'Path to connect data' str connect_data_path %sh{ - # Environment variables - XDG_DATA_HOME=${XDG_DATA_HOME:-~/.local/share} - DATA=$XDG_DATA_HOME/kak/connect - printf '%s' "$DATA" - } - define-command connect-terminal -params .. -shell-completion -docstring 'Connect a terminal' %{ + + # Options + declare-option str connect_environment + + # Commands + define-command connect-terminal -params .. -shell-completion -docstring 'Open a new terminal' %{ terminal sh -c %{ - kak_opt_prelude=$1 kak_opt_connect_path=$2 kak_opt_connect_data_path=$3 kak_opt_connect_attach=$4 kak_opt_connect_environment=$5 kak_session=$6 kak_client=$7 kak_client_env_SHELL=$8 kak_sh_pwd=$9 + kak_opt_prelude=$1 + kak_opt_connect_path=$2 + kak_opt_connect_environment=$3 + kak_session=$4 + kak_client=$5 + . "$kak_opt_connect_path/env/default.env" . "$kak_opt_connect_path/env/overrides.env" . "$kak_opt_connect_path/env/kakoune.env" . "$kak_opt_connect_path/env/git.env" + eval "$kak_opt_connect_environment" - shift 9 - # Start the shell in the current working directory. - cd "$kak_sh_pwd" - "${@:-$SHELL}" - } -- %opt{prelude} %opt{connect_path} %opt{connect_data_path} %opt{connect_attach} %opt{connect_environment} %val{session} %val{client} %val{client_env_SHELL} %sh{pwd} %arg{@} + + shift 5 + + [ "$1" ] && "$@" || "$SHELL" + } -- \ + %opt{prelude} \ + %opt{connect_path} \ + %opt{connect_environment} \ + %val{session} \ + %val{client} \ + %arg{@} } - define-command connect-shell -params 1.. -shell-completion -docstring 'Connect a shell' %{ + + define-command connect-shell -params 1.. -shell-completion -docstring 'Execute commands in a shell' %{ nop %sh{ - # kak_opt_prelude kak_opt_connect_path kak_opt_connect_data_path kak_opt_connect_attach kak_opt_connect_environment kak_session kak_client kak_client_env_SHELL + # kak_opt_prelude + # kak_opt_connect_path + # kak_opt_connect_environment + # kak_session + # kak_client + . "$kak_opt_connect_path/env/default.env" . "$kak_opt_connect_path/env/overrides.env" . "$kak_opt_connect_path/env/kakoune.env" . "$kak_opt_connect_path/env/git.env" + eval "$kak_opt_connect_environment" + setsid sh -c "$@" < /dev/null > /dev/null 2>&1 & } } - define-command connect-detach -params .. -shell-completion -docstring 'Write the given shell command to your connect data path and detach the client' %{ - evaluate-commands %sh{ - mkdir -p "$kak_opt_connect_data_path" - } - echo -to-file "%opt{connect_data_path}/script.sh" -quoting shell %arg{@} - # Delete the script - hook -once global ClientCreate %val{client} %{ - nop %sh{ - rm -f "$kak_opt_connect_data_path/script.sh~" - } - } - quit! - } - alias global t connect-terminal - alias global $ connect-shell - alias global d connect-detach -} -provide-module connect-terminal-mode %{ - require-module connect - require-module terminal-mode + define-command connect-detach -params .. -shell-completion -docstring 'Write an attachable program to connect.sh and detach the client' %{ + echo -to-file "%val{client_env_PWD}/connect.sh" -quoting shell sh -c %{ + rm connect.sh - declare-user-mode connect + kak_opt_prelude=$1 + kak_opt_connect_path=$2 + kak_opt_connect_environment=$3 + kak_session=$4 + kak_server_working_directory=$5 - # Set the terminal to :connect-detach. - # connect-set-detach <scope> - define-command -hidden connect-set-detach -params 1 %{ - set-option %arg{1} connect_attach yes - alias %arg{1} terminal connect-detach - } + . "$kak_opt_connect_path/env/default.env" + . "$kak_opt_connect_path/env/overrides.env" + . "$kak_opt_connect_path/env/kakoune.env" + . "$kak_opt_connect_path/env/git.env" + + eval "$kak_opt_connect_environment" + + shift 5 - # Reset terminal settings. - # connect-set-terminal <scope> - define-command -hidden connect-set-terminal -params 1 %{ - set-option %arg{1} connect_attach no - enter-user-mode terminal + cd "$kak_server_working_directory" + + [ "$1" ] && "$@" || "$SHELL" + } -- \ + %opt{prelude} \ + %opt{connect_path} \ + %opt{connect_environment} \ + %val{session} \ + %sh{pwd} \ + %arg{@} + + # Detach the client + quit! } - # Mappings - map global terminal c ': enter-user-mode connect<ret>' -docstring 'connect' - map global connect d ': connect-set-detach global<ret>' -docstring 'Detach' - map global connect r ': connect-set-terminal global<ret>' -docstring 'Reset' + # Aliases + alias global > connect-terminal + alias global $ connect-shell + alias global & connect-detach } require-module connect diff --git a/rc/env/git.env b/rc/env/git.env index 83ff9c0..d90e610 100644 --- a/rc/env/git.env +++ b/rc/env/git.env @@ -1 +1 @@ -export GIT_EDITOR='edit -wait' +export GIT_EDITOR=kak diff --git a/rc/env/kakoune.env b/rc/env/kakoune.env index 23b915a..832a02d 100644 --- a/rc/env/kakoune.env +++ b/rc/env/kakoune.env @@ -2,7 +2,3 @@ export IN_KAKOUNE_CONNECT=1 export KAKOUNE_SESSION=$kak_session export KAKOUNE_CLIENT=$kak_client export KAKOUNE_PRELUDE=$kak_opt_prelude -export KAKOUNE_CONNECT=$kak_opt_connect_path -export KAKOUNE_CONNECT_DATA=$kak_opt_connect_data_path -export KAKOUNE_CONNECT_SCRIPT=$kak_opt_connect_data_path/script.sh -export KAKOUNE_CONNECT_ATTACH=$kak_opt_connect_attach diff --git a/rc/env/overrides.env b/rc/env/overrides.env index d16cf9d..1e756e0 100644 --- a/rc/env/overrides.env +++ b/rc/env/overrides.env @@ -1,5 +1,4 @@ -# aliases, commands, paths, tools -PATH=$kak_opt_connect_path/paths/aliases:$kak_opt_connect_path/paths/commands:$PATH:$kak_opt_connect_path/paths/tools -SHELL=$kak_client_env_SHELL -VISUAL=edit -EDITOR=edit +paths=$kak_opt_connect_path/paths +PATH=$paths/aliases:$paths/commands:$PATH:$paths/tools +VISUAL=:edit +EDITOR=:edit diff --git a/rc/modules/broot.kak b/rc/modules/broot.kak index a9a47e6..76f00b4 100644 --- a/rc/modules/broot.kak +++ b/rc/modules/broot.kak @@ -3,7 +3,8 @@ provide-module connect-broot %{ require-module connect + define-command broot -params .. -file-completion -docstring 'Open files with Broot' %{ - connect-terminal broot %arg{@} + > broot %arg{@} } } diff --git a/rc/modules/dmenu.kak b/rc/modules/dmenu.kak index c34c270..6be98bb 100644 --- a/rc/modules/dmenu.kak +++ b/rc/modules/dmenu.kak @@ -6,15 +6,14 @@ provide-module connect-dmenu %{ require-module connect - define-command dmenu-files -params .. -file-completion -docstring 'Open selected files with Rofi' %{ - connect-shell %{ - edit $(fd --type file . "$@" | dmenu -l 20 -i -p 'Open selected files') - } -- %arg{@} + + define-command dmenu-files -params .. -file-completion -docstring 'Open files with dmenu' %{ + $ %(:edit $(fd --type file . "$@" | dmenu -l 20 -i -p 'Open files')) -- %arg{@} } - define-command dmenu-buffers -params ..1 -buffer-completion -docstring 'Open selected buffers with Rofi' %{ - connect-shell %{ - buffer $(buffer | grep -F "$1" | dmenu -l 20 -i -p 'Open selected buffers') - } -- %arg{@} + + define-command dmenu-buffers -params ..1 -buffer-completion -docstring 'Open buffers with dmenu' %{ + $ %(:buffer $(:ls | grep -F "$1" | dmenu -l 20 -i -p 'Open buffers')) -- %arg{@} } + alias global dmenu dmenu-files } diff --git a/rc/modules/dolphin.kak b/rc/modules/dolphin.kak index d68e934..6917bc1 100644 --- a/rc/modules/dolphin.kak +++ b/rc/modules/dolphin.kak @@ -3,9 +3,8 @@ provide-module connect-dolphin %{ require-module connect + define-command dolphin -params .. -file-completion -docstring 'Open files with Dolphin' %{ - connect-shell %{ - dolphin "${@:-.}" - } -- %arg{@} + $ %(dolphin "${@:-.}") -- %arg{@} } } diff --git a/rc/modules/fzf.kak b/rc/modules/fzf.kak index f03fa6f..e6e120d 100644 --- a/rc/modules/fzf.kak +++ b/rc/modules/fzf.kak @@ -6,15 +6,14 @@ provide-module connect-fzf %{ require-module connect - define-command fzf-files -params .. -file-completion -docstring 'Open selected files with fzf' %{ - connect-terminal sh -c %{ - edit $(fd --type file . "$@" | fzf) - } -- %arg{@} + + define-command fzf-files -params .. -file-completion -docstring 'Open files with fzf' %{ + > sh -c %(:edit $(fd --type file . "$@" | fzf --prompt='(f)>')) -- %arg{@} } - define-command fzf-buffers -params ..1 -buffer-completion -docstring 'Open selected buffers with fzf' %{ - connect-terminal sh -c %{ - buffer $(buffer | grep -F "$1" | fzf) - } -- %arg{@} + + define-command fzf-buffers -params ..1 -buffer-completion -docstring 'Open buffers with fzf' %{ + > sh -c %(:buffer $(:ls | grep -F "$1" | fzf --prompt='(b)>')) -- %arg{@} } + alias global fzf fzf-files } diff --git a/rc/modules/lf.kak b/rc/modules/lf.kak index 9fc500f..7a8c319 100644 --- a/rc/modules/lf.kak +++ b/rc/modules/lf.kak @@ -3,7 +3,8 @@ provide-module connect-lf %{ require-module connect + define-command lf -params .. -file-completion -docstring 'Open files with lf' %{ - connect-terminal lf %arg{@} + > lf %arg{@} } } diff --git a/rc/modules/nnn.kak b/rc/modules/nnn.kak index 8305949..e78b6e9 100644 --- a/rc/modules/nnn.kak +++ b/rc/modules/nnn.kak @@ -3,7 +3,8 @@ provide-module connect-nnn %{ require-module connect + define-command nnn -params .. -file-completion -docstring 'Open files with nnn' %{ - connect-terminal nnn %arg{@} + > nnn %arg{@} } } diff --git a/rc/modules/rofi.kak b/rc/modules/rofi.kak index f6befbd..6359f75 100644 --- a/rc/modules/rofi.kak +++ b/rc/modules/rofi.kak @@ -6,15 +6,14 @@ provide-module connect-rofi %{ require-module connect - define-command rofi-files -params .. -file-completion -docstring 'Open selected files with Rofi' %{ - connect-shell %{ - edit $(fd --type file . "$@" | rofi -dmenu -i -p 'Open selected files') - } -- %arg{@} + + define-command rofi-files -params .. -file-completion -docstring 'Open files with Rofi' %{ + $ %(:edit $(fd --type file . "$@" | rofi -dmenu -i -p 'Open files')) -- %arg{@} } - define-command rofi-buffers -params ..1 -buffer-completion -docstring 'Open selected buffers with Rofi' %{ - connect-shell %{ - buffer $(buffer | grep -F "$1" | rofi -dmenu -i -p 'Open selected buffers') - } -- %arg{@} + + define-command rofi-buffers -params ..1 -buffer-completion -docstring 'Open buffers with Rofi' %{ + $ %(:buffer $(:ls | grep -F "$1" | rofi -dmenu -i -p 'Open buffers')) -- %arg{@} } + alias global rofi rofi-files } diff --git a/rc/modules/wofi.kak b/rc/modules/wofi.kak index 527306f..f567adc 100644 --- a/rc/modules/wofi.kak +++ b/rc/modules/wofi.kak @@ -6,15 +6,14 @@ provide-module connect-wofi %{ require-module connect - define-command wofi-files -params .. -file-completion -docstring 'Open selected files with Wofi' %{ - connect-shell %{ - edit $(fd --type file . "$@" | wofi --show dmenu --prompt 'Open selected files') - } -- %arg{@} + + define-command wofi-files -params .. -file-completion -docstring 'Open files with Wofi' %{ + $ %(:edit $(fd --type file . "$@" | wofi --dmenu --prompt 'Open files')) -- %arg{@} } - define-command wofi-buffers -params ..1 -buffer-completion -docstring 'Open selected buffers with Wofi' %{ - connect-shell %{ - buffer $(buffer | grep -F "$1" | wofi --show dmenu --prompt 'Open selected buffers') - } -- %arg{@} + + define-command wofi-buffers -params ..1 -buffer-completion -docstring 'Open buffers with Wofi' %{ + $ %(:buffer $(:ls | grep -F "$1" | wofi --dmenu --prompt 'Open buffers')) -- %arg{@} } + alias global wofi wofi-files } 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 diff --git a/share/applications/kakoune-connect.desktop b/share/applications/kakoune-connect.desktop index cbee86e..5b385ed 100644 --- a/share/applications/kakoune-connect.desktop +++ b/share/applications/kakoune-connect.desktop @@ -1,5 +1,5 @@ [Desktop Entry] Type=Application -Name=Kakoune (C) +Name=Kakoune Exec=kak-desktop %F Icon=kakoune.svg diff --git a/share/kak/connect/prompt b/share/kak/connect/prompt index e861b9f..86b7b2f 100755 --- a/share/kak/connect/prompt +++ b/share/kak/connect/prompt @@ -5,6 +5,10 @@ none='\033[0m' yellow='\033[33m' magenta='\033[35m' -if test -n "$IN_KAKOUNE_CONNECT"; then +if [ -n "$KAKOUNE_SESSION" ] && [ -n "$KAKOUNE_CLIENT" ]; then printf "${magenta}${KAKOUNE_CLIENT}${none} at ${yellow}${KAKOUNE_SESSION}${none}" + +elif [ -n "$KAKOUNE_SESSION" ]; then + printf "(${yellow}${KAKOUNE_SESSION}${none})" + fi |
