Csvi - A terminal CSV editor

Go Test License Go Reference GitHub

( <English> / <Japanese> )

Csvi is a terminal-based CSV editor for UNIX-like systems and Windows.

image

Key Features

Video by @emisjerry

Install

Manual Installation

Download the binary package from Releases and extract the executable.

⚠️ Note: The macOS build is experimental and not yet tested. Please let us know if you encounter any issues!

Use eget installer (cross-platform)

brew install eget        # Unix-like systems
# or
scoop install eget       # Windows

cd (YOUR-BIN-DIRECTORY)
eget hymkor/csvi

Use scoop-installer (Windows only)

scoop install https://raw.githubusercontent.com/hymkor/csvi/master/csvi.json

or

scoop bucket add hymkor https://github.com/hymkor/scoop-bucket
scoop install csvi

Use "go install" (requires Go toolchain)

go install github.com/hymkor/csvi/cmd/csvi@latest

Note: go install places the executable in $HOME/go/bin or $GOPATH/bin, so you need to add this directory to your $PATH to run csvi.

Usage

$ csvi {options} FILENAME(...)

or

$ cat FILENAME | csvi {options}

Note: When reading from standard input, saving commands like w write to - (standard output) by default.

Options

Line Endings

By default, the editor uses the line ending detected from the input file. If no input data is provided, it falls back to the OS default line ending. You can override this behavior with the following options:

These options are mutually exclusive. Specifying both will result in an error.

Key-binding

Meta means either Alt+key or Esc followed by key.

Environment Variables

NO_COLOR

If the environment variable NO_COLOR is set to any value with at least one character, Csvi disables colored output. This follows the standard proposed by NO_COLOR.

RUNEWIDTH_EASTASIAN

Specifies the display width for Unicode characters classified as ambiguous width.

COLORFGBG

When the environment variable is defined in the form (FG);(BG) and the foreground (FG) is less than the background (BG), Csvi automatically uses color settings suitable for light backgrounds (equivalent to the -rv option).

Csvi normally uses the terminal's default colors via the escape sequences ESC[39m and ESC[49m. Thus, the (FG);(BG) values are not directly applied; they are only used to determine whether gray background lines should be adjusted toward light or dark shades.

GOREADLINESKK

When the environment variable GOREADLINESKK specifies dictionary files, the built-in SKK1 Kana-to-Kanji conversion via go-readline-skk is enabled.

(Note: ~ is automatically expanded to %USERPROFILE% on Windows, even in cmd.exe.)

Use as a Go package

package main

import (
    "fmt"
    "os"
    "strings"

    "github.com/mattn/go-colorable"

    "github.com/hymkor/csvi"
    "github.com/hymkor/csvi/uncsv"
)

func main() {
    source := `A,B,C,D
"A1","B1","C1","D1"
"A2","B2","C2","D2"`

    cfg := &csvi.Config{
        Mode: &uncsv.Mode{Comma: ','},
    }

    result, err := cfg.Edit(strings.NewReader(source), colorable.NewColorableStdout())

    if err != nil {
        fmt.Fprintln(os.Stderr, err.Error())
        os.Exit(1)
    }

    // // env GOEXPERIMENT=rangefunc go run example
    // for row := range result.Each {
    //     os.Stdout.Write(row.Rebuild(cfg.Mode))
    // }
    result.Each(func(row *uncsv.Row) bool {
        os.Stdout.Write(row.Rebuild(cfg.Mode))
        return true
    })
}

Changelog

Contributing

Acknowledgements

Author


  1. Simple Kana to Kanji conversion program. One of the Japanese input method editors. ↩︎