kokodoko

package module
v0.2.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 4, 2021 License: MIT Imports: 4 Imported by: 0

README

ここどこ? (koko doko?)

Build Status Coverage Status Go Report Card Latest version Go Documentation License

Quickly generate GitHub permalink to lines of code in your local filesystem.

Installation

Assuming you have Go installed:

go get -u github.com/kinbiko/kokodoko/cmd/kokodoko

Usage

First argument should be a path to a file/directory on your local system. Second (optional) argument is the line number, or a line number range, that you would like to highlight.

$ kokodoko ./dotfiles/vimrc 10-15
Copied 'https://github.com/kinbiko/dotfiles/blob/15fc22c0c5672e0f15f2ef7ea333bd620aa9965c/vimrc#L10-L15' to the clipboard!

However, this tool is more useful when integrated directly in your editor.

Vim integration

Put the following in your .vimrc:

" Super hacky mapping to shell out to github.com/kinbiko/kokodoko and fetch the
" Github link to the current line(s)
nnoremap <silent> oiuy :!kokodoko % <C-R>=line(".")<CR><CR>
vnoremap <silent> oiuy :!kokodoko % <C-R>=line("'<")<CR>-<C-R>=line("'>")<CR><CR>u

Replace oiuy with your desired mapping.

Integrating with other editors

Contributions are welcome!

Documentation

Overview

Package kokodoko exposes an API for fetching GitHub permalinks given a path to a local file.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
}

Config holds options that alters the behavior of the app. Note: The author reserves the right to add fields to this struct without releasing a new major version. You should be fine as long as you name parameters in this struct.

type Kokodoko

type Kokodoko struct {
	// contains filtered or unexported fields
}

Kokodoko is the core application struct that executes everything.

func New

func New(sys System, o11y O11y, cfg Config) *Kokodoko

New creates a new Kokodoko application based on the given dependencies and configuration.

func (*Kokodoko) Run

func (k *Kokodoko) Run(ctx context.Context, args []string) (string, error)

Run reads the given args, performs some validation, makes some git syscalls, and returns the URL corresponding to the file (and line number(s)) identified in the args. First arg is interpreted as a file path, whereas the second optional argument is a line number or a line number range in the form "12-51". case it *is* actually easier to read since it's all very left-margin aligned.

type O11y

type O11y interface {
	Wrap(ctx context.Context, err error, msgAndFmtArgs ...interface{}) error

	WithMetadatum(ctx context.Context, tab, key string, value interface{}) context.Context
}

O11y exposes observability methods for monitoring this application.

type System

type System interface {
	// repoPath doesn't have to be the root of the repository -- any directory in the repo.
	RemoteURL(ctx context.Context, repoPath string) (string, error)
	// repoPath doesn't have to be the root of the repository -- any directory in the repo.
	Hash(ctx context.Context, repoPath string) (string, error)
	// repoPath doesn't have to be the root of the repository -- any directory in the repo.
	RepoRoot(ctx context.Context, repoPath string) (string, error)
	AbsolutePath(relative string) (string, error)
}

System represents data-fetching methods that require system calls.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL