Handy Kakoune companion.

kks

Handy Kakoune companion.

Installation

Download release binary

Download the compiled binary for your system from Releases page and put it somewhere in your $PATH.

Build from source

Requires Go installed on your system.

Clone the repository and run go build, then copy the compiled binary somewhere in your $PATH.

If Go is configured to install packages in $PATH, it's also possible to install without cloning the repository: run go install github.com/kkga/kks@latest.

How to use

Kakoune configuration

Source kks init to add kks-connect command to Kakoune...

eval %sh{ kks init }

... and use your terminal integration to connect provided scripts, for example: kks-connect terminal kks-files.

Kakoune mappings example

map global normal -docstring 'terminal'         <c-t> ': kks-connect terminal<ret>'
map global normal -docstring 'files'            <c-f> ': kks-connect popup kks-files<ret>'
map global normal -docstring 'buffers'          <c-b> ': kks-connect popup kks-buffers<ret>'
map global normal -docstring 'files by content' <c-g> ': kks-connect popup kks-grep<ret>'
map global normal -docstring 'lines in buffer'  <c-l> ': kks-connect popup kks-lines<ret>'
map global normal -docstring 'recent files'     <c-r> ': kks-connect popup kks-mru<ret>'
map global normal -docstring 'lf'               <c-h> ': kks-connect panel kks-lf<ret>'
map global normal -docstring 'lazygit'          <c-v> ': kks-connect popup lazygit<ret>'

For more terminal integrations and for the (quite handy) popup command, see:

Shell configuration example

export EDITOR=`kks edit`

alias k='kks edit'
alias ks='eval (kks-select)'
alias kcd='cd (kks get %sh{pwd})'
alias ka='kks attach'
alias kl='kks list'

kks configuration

kks can be configured through environment variables.

At the moment, there is a single configuration option:

  • KKS_USE_GITDIR_SESSIONS
    • when set to any value and KKS_SESSION is empty, running kks edit will do the following:
      • if file is inside a git directory, kks will search for an existing session based on top-level git directory name and connect to it;
      • if a session for the directory doesn't exist, kks will start a new session and connect to it.

Usage

USAGE
  kks <command> [-s <session>] [-c <client>] [<args>]

COMMANDS
  new, n         create new session
  edit, e        edit file
  send, s        send command
  attach, a      attach to session
  kill           kill session
  ls             list sessions and clients
  get            get %{val}, %{opt} and friends
  cat            print buffer content
  env            print env
  init           print Kakoune definitions

ENVIRONMENT VARIABLES
  KKS_SESSION    Kakoune session
  KKS_CLIENT     Kakoune client

Use "kks <command> -h" for command usage.

Provided scripts


Similar projects

Owner
Gadzhi Kharkharov
~designer
Gadzhi Kharkharov
Comments
  • add git-like subcommand deferring mechanism

    add git-like subcommand deferring mechanism

    This commit implements a simple mechanism of deferring unknown subcommands to other executables in $PATH.

    When users executes kks foo kks will try to run kks-foo command.

    Example:

    $ cat ~/.local/bin/kks-date                                                                                                                                                                                  
    #!/bin/sh
    date $@
    $ kks date -I
    2021-11-12
    $ kks grep
    ...
    

    Just an idea, feel free to ignore if you don't like it (It can be implemented as wrapper script by user) :)

  • Panic on list command when no session is running

    Panic on list command when no session is running

    $ kak -l
    $ kks list
    panic: runtime error: index out of range [0] with length 0
    
    goroutine 1 [running]:
    github.com/kkga/kks/kak.(*Session).Dir(0xc000077cf0)
    	/home/teddy/src/kks/kak/kak.go:33 +0x8e
    github.com/kkga/kks/cmd.(*ListCmd).Run(0xc0001b4320)
    	/home/teddy/src/kks/cmd/list.go:75 +0x176
    github.com/kkga/kks/cmd.Root({0xc0001a8010, 0x0, 0xc000066750})
    	/home/teddy/src/kks/cmd/root.go:38 +0x689
    main.main()
    	/home/teddy/src/kks/main.go:21 +0xe8
    

    Reason: in kak/kak.go

    strings.Split(strings.TrimSpace(string(o)), "\n")
    

    Always returns 1 element slice where the only element is empty string when o == "".

    Simple fix:

    diff --git i/kak/kak.go w/kak/kak.go
    index 270ff4..3037f7 100644
    --- i/kak/kak.go
    +++ w/kak/kak.go
    @@ -46,6 +48,9 @@ func (s *Session) Clients() (clients []Client, err error) {
     func Sessions() (sessions []Session, err error) {
     	o, err := exec.Command("kak", "-l").Output()
     	for _, s := range strings.Split(strings.TrimSpace(string(o)), "\n") {
    +		if s == "" {
    +			continue
    +		}
     		sessions = append(sessions, Session{s})
     	}
     	return
    
  • Strip leading `-` from session name

    Strip leading `-` from session name

    My dotfiles repo lives in ~/.dotfiles, so the resulting gitdir session name is -dotfiles. This wreaks havoc with kak-lsp and kakoune itself, the former thinking it is a command-line flag, and the latter thinking it's a switch to the command you pass %val{session} to.

    shell stderr: <<<
    error: Found argument '-o' which wasn't expected, or isn't valid in this context
    
    USAGE:
        kak-lsp --daemonize --kakoune --session <SESSION>
    
    For more information try --help
    >>>
    

    Suggested fix

    Strip any non-alphanumeric characters from the front of the session name.

    To reproduce

    • Create a Git repo inside a hidden folder (e.g. ".test")
    • Pass KKS_USE_GITDIR_SESSIONS
    • Open kakoune and try to enable kak-lsp with evaluate-commands %sh{ kak-lsp --kakoune -s $kak_session }
    • Check *debug* and you will see kak-lsp complain about an unknown command line flag.
  • grep: force sh to be used for fzf preview command

    grep: force sh to be used for fzf preview command

    Fixes kks-grep preview on non POSIX shells (Fish)

    $SHELL variable is usually set to users preferred shell 1. If set, FZF uses the variable to run preview command. kks-grep preview command requires POSIX compatible shell.

  • Various code optimizations, ensure session exist when starting new daemons

    Various code optimizations, ensure session exist when starting new daemons

    • wip: use types for session, client, buffer
    • add KakContext struct
    • use new types in commands
    • use new type in connect
    • add short descriptions to commands
    • move filepath to kak package
    • kak.Create -> kak.Start
    • update preview cmd in scripts
    • move tmp reader to separate file
    • use filepath in run
    • scripts: ensure normal mode before executing keys in kks-lines
    • ensure session exists when starting new kak sessions
    • close fsnotify watcher and cleanup tmp files immediately after reading
    • use tmp naming in cat
  • check scanner for error

    check scanner for error

    It's considered a good practice to check for scanner's error. Also I allowed to myself to dismiss the clearSessions func, as it's called from single place only where kakExec is already available.

  • kks doesn't parse flags when running external commands

    kks doesn't parse flags when running external commands

    example: running a script kks-files as an external command should parse flags and properly set environments variables for the script

    kks -s mysession files
    
Related tags
DevPops continues my research on companion worms
DevPops continues my research on companion worms

DevPops continues my research on companion worms. It is a friendly companion without payload and without modifying any source files. The spreading vectors are gits.

Nov 15, 2022
A Declarative Cloud Firewall Reverse Proxy Solution with Companion Mobile App
A Declarative Cloud Firewall Reverse Proxy Solution with Companion Mobile App

A declarative Cloud firewall reverse proxy solution with inbuilt DDoS protection and alerting mechanism to protect your servers and keeping an eye on those malicious requests

Aug 10, 2022
Jun 20, 2022
CultureBot - A slack bot used to act as a companion to new people in tech

Culture Bot A slack bot used to act as a companion to new people in tech. Helps

Feb 6, 2022
Zero allocation Nullable structures in one library with handy conversion functions, marshallers and unmarshallers

nan - No Allocations Nevermore Package nan - Zero allocation Nullable structures in one library with handy conversion functions, marshallers and unmar

Dec 20, 2022
A handy, fast and powerful go template engine.
A handy, fast and powerful go template engine.

Hero Hero is a handy, fast and powerful go template engine, which pre-compiles the html templates to go code. It has been used in production environme

Dec 27, 2022
Handy tools to manipulate korean character.
Handy tools to manipulate korean character.

About hangul hangul is a set of handy tools for manipulate korean character in Go language. Example package main import ( "fmt" hangu

Oct 27, 2022
Handy commands to run in Go projects

Handy commands to run in Go projects

Jan 3, 2023
Handy little CLI for interacting with OCI data

oci-tool Handy little CLI for interacting with OCI data Installation go get github.com/csweichel/oci-tool I use Gitpod for developing this tool; you s

May 17, 2022
A Handy FieldBuilder Template for uber-go/zap

zap-fieldbuilder-template A Handy Generic Logging FieldBuilder Template around uber-go/zap. You can check this tiny blog for further information ?? Wh

Dec 16, 2021
Error interface wrappers for Google's errdetails protobuf types, because they're handy as heck and I want to use them more

Error interface wrappers for Google's errdetails protobuf types, because they're handy as heck and I want to use them more

Nov 18, 2021
A personal collection of handy CLI tools

Toolkit A personal collection of handy CLI tools Installation 1.) Download and extract the ZIP package for the the latest release 2.) Copy the appropr

Nov 8, 2021
A handy utility to generate configmap and values.yaml of your application for helmifying them

Helmfig Are you tired of writing values.yaml for configmap of your project when you are helmifying them? Helmfig is a handy tool that can generate the

Dec 14, 2022
Spanner - A handy tool for visualising Datadog traces
Spanner - A handy tool for visualising Datadog traces

Spanner A minimal tool for visualising Datadog traces ?? Installation You can in

Jan 2, 2022