kcr static
parent
bea6d34907
commit
6913341bfb
|
@ -0,0 +1,3 @@
|
|||
#!/bin/sh
|
||||
|
||||
"kcr-fzf-$@"
|
|
@ -0,0 +1,19 @@
|
|||
#!/bin/sh
|
||||
|
||||
# Open buffers.
|
||||
#
|
||||
# Usage:
|
||||
#
|
||||
# kcr fzf buffers [patterns]
|
||||
|
||||
# – fzf (https://github.com/junegunn/fzf)
|
||||
# – bat (https://github.com/sharkdp/bat)
|
||||
|
||||
kcr get --raw %val{buflist} |
|
||||
grep -F "$*" |
|
||||
fzf --preview-window=down:60% --preview 'kcr cat --raw {} | bat --style=numbers --color=always --line-range :500' --prompt='(b)>' |
|
||||
|
||||
# Open buffers
|
||||
while read name; do
|
||||
kcr send buffer "$name"
|
||||
done
|
|
@ -0,0 +1,19 @@
|
|||
#!/bin/sh
|
||||
|
||||
# Open files.
|
||||
#
|
||||
# Usage:
|
||||
#
|
||||
# kcr fzf files [paths]
|
||||
|
||||
# – fzf (https://github.com/junegunn/fzf)
|
||||
# – fd (https://github.com/sharkdp/fd)
|
||||
# – bat (https://github.com/sharkdp/bat)
|
||||
|
||||
fd --type file . "$@" |
|
||||
fzf --preview-window=down:60% --preview 'bat --style=numbers --color=always --line-range :500 {}' --prompt='(f)>' |
|
||||
|
||||
# Open files
|
||||
while read file; do
|
||||
kcr edit "$file"
|
||||
done
|
|
@ -0,0 +1,14 @@
|
|||
#!/bin/sh
|
||||
|
||||
# Open files by content.
|
||||
#
|
||||
# Usage:
|
||||
#
|
||||
# kcr fzf grep [paths]
|
||||
|
||||
# – fzf (https://github.com/junegunn/fzf)
|
||||
# – ripgrep (https://github.com/BurntSushi/ripgrep)
|
||||
|
||||
rg --column --with-filename '.+' "$@" |
|
||||
fzf --prompt='(g)>' |
|
||||
kcr edit-search
|
|
@ -0,0 +1,29 @@
|
|||
#!/bin/sh
|
||||
|
||||
# Start an interactive shell.
|
||||
#
|
||||
# Usage:
|
||||
#
|
||||
# kcr fzf shell [command] [arguments]
|
||||
|
||||
# – fzf (https://github.com/junegunn/fzf)
|
||||
|
||||
set_environment() {
|
||||
session=$1 client=${2#null} buffer_name=${3#null} working_directory=$4
|
||||
}
|
||||
|
||||
# Run fzf with the session list
|
||||
rows=$(
|
||||
kcr list --raw |
|
||||
fzf --prompt='(s)>'
|
||||
)
|
||||
|
||||
IFS='
|
||||
'
|
||||
for row in $rows; do
|
||||
IFS=' '
|
||||
set_environment $row
|
||||
|
||||
# Start an interactive shell
|
||||
KAKOUNE_SESSION=$session KAKOUNE_CLIENT=$client kcr shell "$@"
|
||||
done
|
|
@ -0,0 +1,11 @@
|
|||
#!/bin/sh
|
||||
|
||||
# Get expansions from a client in session.
|
||||
#
|
||||
# Usage:
|
||||
#
|
||||
# kcr get-expansion <type> <name>
|
||||
|
||||
type=$1 name=$2
|
||||
shift 2
|
||||
kcr get "$@" "%${type}{${name}}"
|
|
@ -0,0 +1,5 @@
|
|||
[Desktop Entry]
|
||||
Type=Application
|
||||
Name=Kakoune
|
||||
Exec=kcr open %F
|
||||
Icon=kakoune.svg
|
|
@ -0,0 +1,24 @@
|
|||
# `edit`
|
||||
|
||||
[`edit`] related commands for **kcr**.
|
||||
|
||||
[`edit`]: https://github.com/alexherbo2/kakoune.cr#edit
|
||||
|
||||
## Commands
|
||||
|
||||
```
|
||||
kcr edit-search [input: <file>:<line>:<column>:<text>] ⇒ Open files from search results
|
||||
```
|
||||
|
||||
###### `edit-search`
|
||||
|
||||
```
|
||||
kcr edit-search [input: <file>:<line>:<column>:<text>]
|
||||
```
|
||||
|
||||
Open files from search results.
|
||||
|
||||
**Note**: This command is only meant to be useful for scripting.
|
||||
See [`kcr-fzf-grep`] for example.
|
||||
|
||||
[`kcr-fzf-grep`]: ../fzf/kcr-fzf-grep
|
|
@ -0,0 +1,27 @@
|
|||
#!/bin/sh
|
||||
|
||||
# Open files from search results.
|
||||
#
|
||||
# Usage:
|
||||
#
|
||||
# kcr edit-search [input: <file>:<line>:<column>:<text>]
|
||||
|
||||
# Execute the following Kakoune commands.
|
||||
#
|
||||
# Input: <file>:<line>:<column>:<text>
|
||||
# Output: <file><line><column>
|
||||
select_each_line='<a-s>_'
|
||||
select_search_fields='s^(.+?):(\d+):(\d+):(.+?)$<ret>'
|
||||
save_selections='Z'
|
||||
select_file_save_and_restore='1s<ret>"fZz'
|
||||
select_line_save_and_restore='2s<ret>"f<a-Z>az'
|
||||
select_column_save_and_restore='3s<ret>"f<a-Z>az'
|
||||
select_data='"fz'
|
||||
prepare_output='y%<a-R>a<ret><esc>'
|
||||
delete_end_of_file='ged'
|
||||
|
||||
kak -f "${select_each_line}${select_search_fields}${save_selections}${select_file_save_and_restore}${select_line_save_and_restore}${select_column_save_and_restore}${select_data}${prepare_output}${delete_end_of_file}" |
|
||||
|
||||
while read file; read line; read column; do
|
||||
kcr edit "$file" "+$line:$column"
|
||||
done
|
|
@ -0,0 +1,97 @@
|
|||
# `fzf`
|
||||
|
||||
[fzf] integration for **kcr**.
|
||||
|
||||
[fzf]: https://github.com/junegunn/fzf
|
||||
|
||||
## Dependencies
|
||||
|
||||
- [bat]
|
||||
- [fd]
|
||||
- [ripgrep]
|
||||
|
||||
[bat]: https://github.com/sharkdp/bat
|
||||
[fd]: https://github.com/sharkdp/fd
|
||||
[ripgrep]: https://github.com/BurntSushi/ripgrep
|
||||
|
||||
## Usage
|
||||
|
||||
```
|
||||
kcr [-s, --session <name>] [-c, --client <name>] fzf <command> [arguments]
|
||||
```
|
||||
|
||||
## Configuration
|
||||
|
||||
Kakoune example configuration:
|
||||
|
||||
`~/.config/kak/kakrc`
|
||||
|
||||
``` kak
|
||||
map -docstring 'Open files' global normal <c-f> ': + kcr-fzf-files<ret>'
|
||||
map -docstring 'Open buffers' global normal <c-b> ': + kcr-fzf-buffers<ret>'
|
||||
map -docstring 'Open files by content' global normal <c-g> ': + kcr-fzf-grep<ret>'
|
||||
```
|
||||
|
||||
Bash example configuration:
|
||||
|
||||
`~/.bashrc`
|
||||
|
||||
``` sh
|
||||
alias K='kcr-fzf-shell'
|
||||
```
|
||||
|
||||
## Commands
|
||||
|
||||
```
|
||||
kcr fzf <command> [arguments] ⇒ Run fzf command
|
||||
kcr fzf files [paths] ⇒ Open files
|
||||
kcr fzf buffers [patterns] ⇒ Open buffers
|
||||
kcr fzf grep [paths] ⇒ Open files by content
|
||||
kcr fzf shell [command] [arguments] ⇒ Start an interactive shell
|
||||
```
|
||||
|
||||
###### `fzf`
|
||||
|
||||
```
|
||||
kcr fzf <command> [arguments]
|
||||
```
|
||||
|
||||
Run fzf command.
|
||||
|
||||
###### `fzf files`
|
||||
|
||||
```
|
||||
kcr fzf files [paths]
|
||||
```
|
||||
|
||||
Open files.
|
||||
|
||||
###### `fzf buffers`
|
||||
|
||||
```
|
||||
kcr fzf buffers [patterns]
|
||||
```
|
||||
|
||||
Open buffers.
|
||||
|
||||
###### `fzf grep`
|
||||
|
||||
```
|
||||
kcr fzf grep [paths]
|
||||
```
|
||||
|
||||
Open files by content.
|
||||
|
||||
###### `fzf shell`
|
||||
|
||||
```
|
||||
kcr fzf shell [command] [arguments]
|
||||
```
|
||||
|
||||
Start an interactive shell.
|
||||
|
||||
**Example**
|
||||
|
||||
``` sh
|
||||
kcr fzf shell kcr attach
|
||||
```
|
|
@ -0,0 +1,3 @@
|
|||
#!/bin/sh
|
||||
|
||||
"kcr-fzf-$@"
|
|
@ -0,0 +1,19 @@
|
|||
#!/bin/sh
|
||||
|
||||
# Open buffers.
|
||||
#
|
||||
# Usage:
|
||||
#
|
||||
# kcr fzf buffers [patterns]
|
||||
|
||||
# – fzf (https://github.com/junegunn/fzf)
|
||||
# – bat (https://github.com/sharkdp/bat)
|
||||
|
||||
kcr get --raw %val{buflist} |
|
||||
grep -F "$*" |
|
||||
fzf --preview-window=down:60% --preview 'kcr cat --raw {} | bat --style=numbers --color=always --line-range :500' --prompt='(b)>' |
|
||||
|
||||
# Open buffers
|
||||
while read name; do
|
||||
kcr send buffer "$name"
|
||||
done
|
|
@ -0,0 +1,19 @@
|
|||
#!/bin/sh
|
||||
|
||||
# Open files.
|
||||
#
|
||||
# Usage:
|
||||
#
|
||||
# kcr fzf files [paths]
|
||||
|
||||
# – fzf (https://github.com/junegunn/fzf)
|
||||
# – fd (https://github.com/sharkdp/fd)
|
||||
# – bat (https://github.com/sharkdp/bat)
|
||||
|
||||
fd --type file . "$@" |
|
||||
fzf --preview-window=down:60% --preview 'bat --style=numbers --color=always --line-range :500 {}' --prompt='(f)>' |
|
||||
|
||||
# Open files
|
||||
while read file; do
|
||||
kcr edit "$file"
|
||||
done
|
|
@ -0,0 +1,14 @@
|
|||
#!/bin/sh
|
||||
|
||||
# Open files by content.
|
||||
#
|
||||
# Usage:
|
||||
#
|
||||
# kcr fzf grep [paths]
|
||||
|
||||
# – fzf (https://github.com/junegunn/fzf)
|
||||
# – ripgrep (https://github.com/BurntSushi/ripgrep)
|
||||
|
||||
rg --column --with-filename '.+' "$@" |
|
||||
fzf --prompt='(g)>' |
|
||||
kcr edit-search
|
|
@ -0,0 +1,29 @@
|
|||
#!/bin/sh
|
||||
|
||||
# Start an interactive shell.
|
||||
#
|
||||
# Usage:
|
||||
#
|
||||
# kcr fzf shell [command] [arguments]
|
||||
|
||||
# – fzf (https://github.com/junegunn/fzf)
|
||||
|
||||
set_environment() {
|
||||
session=$1 client=${2#null} buffer_name=${3#null} working_directory=$4
|
||||
}
|
||||
|
||||
# Run fzf with the session list
|
||||
rows=$(
|
||||
kcr list --raw |
|
||||
fzf --prompt='(s)>'
|
||||
)
|
||||
|
||||
IFS='
|
||||
'
|
||||
for row in $rows; do
|
||||
IFS=' '
|
||||
set_environment $row
|
||||
|
||||
# Start an interactive shell
|
||||
KAKOUNE_SESSION=$session KAKOUNE_CLIENT=$client kcr shell "$@"
|
||||
done
|
|
@ -0,0 +1,35 @@
|
|||
# `get`
|
||||
|
||||
[`get`] related commands for **kcr**.
|
||||
|
||||
[`get`]: https://github.com/alexherbo2/kakoune.cr#get
|
||||
|
||||
## Configuration
|
||||
|
||||
Bash example configuration:
|
||||
|
||||
`~/.bashrc`
|
||||
|
||||
``` sh
|
||||
alias val='kcr get-expansion val'
|
||||
alias opt='kcr get-expansion opt'
|
||||
alias reg='kcr get-expansion reg'
|
||||
```
|
||||
|
||||
## Commands
|
||||
|
||||
```
|
||||
kcr get-expansion <type> <name> ⇒ Get expansions from a client in session
|
||||
```
|
||||
|
||||
###### `get-expansion`
|
||||
|
||||
```
|
||||
kcr get-expansion <type> <name>
|
||||
```
|
||||
|
||||
Get [expansions] from a client in session.
|
||||
|
||||
**Note**: This command is only meant to be useful for creating aliases.
|
||||
|
||||
[Expansions]: https://github.com/mawww/kakoune/blob/master/doc/pages/expansions.asciidoc
|
|
@ -0,0 +1,11 @@
|
|||
#!/bin/sh
|
||||
|
||||
# Get expansions from a client in session.
|
||||
#
|
||||
# Usage:
|
||||
#
|
||||
# kcr get-expansion <type> <name>
|
||||
|
||||
type=$1 name=$2
|
||||
shift 2
|
||||
kcr get "$@" "%${type}{${name}}"
|
|
@ -0,0 +1,77 @@
|
|||
# Edit me and press F5 to reload.
|
||||
# Type in insert mode (), {}, []…
|
||||
# Inspect the *debug* buffer populated with `kcr send --debug` or via `export KAKOUNE_DEBUG=1`.
|
||||
# Open a connected terminal with [>] or [+] and try the following commands.
|
||||
#
|
||||
# Examples:
|
||||
#
|
||||
# export KAKOUNE_DEBUG=1
|
||||
#
|
||||
# kcr get %val{buflist}
|
||||
#
|
||||
# kcr echo -- echo kanto | kcr echo -- echo johto | kcr escape
|
||||
# kcr echo -- kanto johto | kcr escape -- echo {}
|
||||
#
|
||||
# kcr echo -- echo kanto | kcr echo -- echo johto | kcr send
|
||||
# kcr echo -- kanto johto | kcr send -- echo {}
|
||||
|
||||
$ sh -c %{
|
||||
time=$1
|
||||
|
||||
kcr send -- info 'Go ahead and experiment.'
|
||||
sleep $((time))
|
||||
|
||||
kcr send -- info 'Don’t think too much.'
|
||||
sleep $((time))
|
||||
|
||||
kcr send -- info 'Let intuition be your guide.'
|
||||
sleep $((time))
|
||||
|
||||
kcr send -- info 'Baten Kaitos: Eternal Wings and the Lost Ocean, in the Moonguile Forest, 2003.'
|
||||
sleep $((time * 2))
|
||||
|
||||
kcr get %reg{.} |
|
||||
kcr send -- info 'You have selected: {}'
|
||||
} -- 2
|
||||
|
||||
declare-option str-list pairs ( ) { } [ ]
|
||||
|
||||
define-command -override insert-opening-pair -params 2 %{
|
||||
execute-keys %arg{1} %arg{2} '<left>'
|
||||
}
|
||||
|
||||
define-command -override insert-closing-pair -params 2 %{
|
||||
try %{
|
||||
execute-keys -draft ';' '<a-k>\Q' %arg{2} '<ret>'
|
||||
execute-keys '<right>'
|
||||
} catch %{
|
||||
execute-keys %arg{2}
|
||||
}
|
||||
}
|
||||
|
||||
define-command -override map-pairs %{
|
||||
$ sh -c %{
|
||||
filter='
|
||||
_nwise(2) as [$opening, $closing] |
|
||||
|
||||
["map", "global", "insert", $opening, "<a-;>: {}<ret>"],
|
||||
["insert-opening-pair", $opening, $closing],
|
||||
|
||||
["map", "global", "insert", $closing, "<a-;>: {}<ret>"],
|
||||
["insert-closing-pair", $opening, $closing]
|
||||
'
|
||||
kcr get %opt{pairs} |
|
||||
jq "[$filter]" |
|
||||
kcr send
|
||||
}
|
||||
}
|
||||
|
||||
define-command -override unmap-pairs %{
|
||||
$ sh -c %{
|
||||
kcr get %opt{pairs} |
|
||||
jq 'map(["unmap", "global", "insert", .])' |
|
||||
kcr send
|
||||
}
|
||||
}
|
||||
|
||||
map-pairs
|
|
@ -0,0 +1,34 @@
|
|||
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
|
||||
|
||||
[ $# = 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{
|
||||
setsid "$@" < /dev/null > /dev/null 2>&1 &
|
||||
}
|
||||
}
|
||||
|
||||
define-command -override connect-program -params 1.. -shell-completion -docstring 'Connect a program' %{
|
||||
connect run %arg{@}
|
||||
}
|
||||
|
||||
define-command -override connect-terminal -params .. -shell-completion -docstring 'Connect a terminal' %{
|
||||
connect terminal %arg{@}
|
||||
}
|
||||
|
||||
define-command -override connect-popup -params .. -shell-completion -docstring 'Connect a popup' %{
|
||||
connect popup %arg{@}
|
||||
}
|
||||
|
||||
# Aliases
|
||||
alias global $ connect-program
|
||||
alias global > connect-terminal
|
||||
alias global + connect-popup
|
|
@ -0,0 +1,13 @@
|
|||
define-command -override initialize -params 1 -file-completion -docstring 'Initialize the playground' %{
|
||||
edit -fifo %arg{1} '*playground*'
|
||||
set-option buffer filetype kak
|
||||
map -docstring 'Reload the playground' buffer normal <F5> ': reload<ret>'
|
||||
info -title Playground 'Press F5 or enter :reload to reload the *playground* buffer'
|
||||
}
|
||||
|
||||
define-command -override reload -docstring 'Reload the playground' %{
|
||||
$ sh -c %{
|
||||
playground=$(kcr cat --raw '*playground*')
|
||||
kcr send evaluate-commands "$playground"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
[custom.kakoune]
|
||||
symbol = '🐈'
|
||||
command = 'printf "%s@%s" "${KAKOUNE_CLIENT:-null}" "$KAKOUNE_SESSION"'
|
||||
when = '[ "$KAKOUNE_SESSION" ] || [ "$KAKOUNE_CLIENT" ]'
|
||||
shell = ['sh']
|
||||
description = 'The current Kakoune session and client'
|
||||
style = 'green'
|
||||
format = '[$symbol $output]($style)'
|
Loading…
Reference in New Issue