Skip to content

Commit

Permalink
v0.9.0
Browse files Browse the repository at this point in the history
  • Loading branch information
shenwei356 committed Jun 22, 2017
1 parent 6e052cd commit f580284
Show file tree
Hide file tree
Showing 7 changed files with 249 additions and 20 deletions.
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ It could save you much time of writing Python/R scripts.
- [Features](#features)
- [Subcommands](#subcommands)
- [Installation](#installation)
- [Bash-completion](#bash-completion)
- [Compared to `csvkit`](#compared-to-csvkit)
- [Examples](#examples)
- [Acknowledgements](#acknowledgements)
Expand Down Expand Up @@ -114,6 +115,12 @@ It could save you much time of writing Python/R scripts.
- `plot box` boxplot
- `plot line` line plot and scatter plot

**Misc**

- `version` print version information and check for update
- `genautocomplete` generate shell autocompletion script


## Installation

[Download Page](https://github.com/shenwei356/csvtk/releases)
Expand Down Expand Up @@ -152,6 +159,25 @@ And then:
go get -u github.com/shenwei356/csvtk/csvtk


## Bash-completion

Note: The current version supports Bash only.
This should work for *nix systems with Bash installed.

Howto:

1. run: `csvtk genautocomplete`

2. create and edit `~/.bash_completion` file if you don't have it.

nano ~/.bash_completion

add the following:

for bcfile in ~/.bash_completion.d/* ; do
. $bcfile
done

## Compared to `csvkit`

[csvkit](http://csvkit.readthedocs.org/)
Expand Down
83 changes: 83 additions & 0 deletions csvtk/cmd/genautocomplete.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// Copyright © 2016 Wei Shen <shenwei356@gmail.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

package cmd

import (
"fmt"
"os"
"path/filepath"

homedir "github.com/mitchellh/go-homedir"
"github.com/shenwei356/util/pathutil"
"github.com/spf13/cobra"
)

// genautocompleteCmd represents the fq2fa command
var genautocompleteCmd = &cobra.Command{
Use: "genautocomplete",
Short: "generate shell autocompletion script",
Long: `generate shell autocompletion script
Note: The current version supports Bash only.
This should work for *nix systems with Bash installed.
Howto:
1. run: csvtk genautocomplete
2. create and edit ~/.bash_completion file if you don't have it.
nano ~/.bash_completion
add the following:
for bcfile in ~/.bash_completion.d/* ; do
. $bcfile
done
`,
Run: func(cmd *cobra.Command, args []string) {
autocompleteTarget := getFlagString(cmd, "file")
autocompleteType := getFlagString(cmd, "type")

if autocompleteType != "bash" {
checkError(fmt.Errorf("only Bash is supported for now"))
}

dir := filepath.Dir(autocompleteTarget)
ok, err := pathutil.DirExists(dir)
checkError(err)
if !ok {
os.MkdirAll(dir, 0744)
}
checkError(cmd.Root().GenBashCompletionFile(autocompleteTarget))

log.Infof("bash completion file for csvtk saved to %s", autocompleteTarget)
},
}

func init() {
RootCmd.AddCommand(genautocompleteCmd)
defaultCompletionFile, err := homedir.Expand("~/.bash_completion.d/csvtk.sh")
checkError(err)
genautocompleteCmd.Flags().StringP("file", "", defaultCompletionFile, "autocompletion file")
genautocompleteCmd.Flags().StringP("type", "", "bash", "autocompletion type (currently only bash supported)")
}
2 changes: 1 addition & 1 deletion csvtk/cmd/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import (
)

// VERSION of csvtk
const VERSION = "0.8.0"
const VERSION = "0.9.0"

func checkError(err error) {
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion csvtk/cmd/mutate2.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,5 +307,5 @@ func init() {
RootCmd.AddCommand(mutate2Cmd)
mutate2Cmd.Flags().StringP("expression", "e", "", `artithmetic/string expressions. e.g. '$1 + $2', '$a / $b', ' $1 > 100 ? "big" : "small" '`)
mutate2Cmd.Flags().StringP("name", "n", "", `new column name`)
mutate2Cmd.Flags().IntP("digits", "", 2, `number of digits after the dot`)
mutate2Cmd.Flags().IntP("digits", "L", 2, `number of digits after the dot`)
}
1 change: 0 additions & 1 deletion dev-version.md
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
- add subcommand `csvtk mutate2`:
55 changes: 38 additions & 17 deletions doc/docs/download.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,24 @@

## Current Version

[csvtk v0.8.0](https://github.com/shenwei356/csvtk/releases/tag/v0.8.0)
[![Github Releases (by Release)](https://img.shields.io/github/downloads/shenwei356/csvtk/v0.8.0/total.svg)](https://github.com/shenwei356/csvtk/releases/tag/v0.8.0)

- **new command `csvtk gather` for gathering columns into key-value pairs**.
- `csvtk sort`: support **sorting by user-defined order**.
- fix bug of *unselecting field*: wrongly reporting error of fields not existing.
affected commands: `cut`, `filter`, `fitler2`, `freq`, `grep`, `inter`, `mutate`,
`rename`, `rename2`, `replace`, `stats2`, `uniq`.
- update help message of flag `-F/--fuzzy-fields`.
- update help message of global flag `-t`, which overrides both `-d` and `-D`.
If you want other delimiter for tabular input, use `-t $'\t' -D "delimiter"`.
[csvtk v0.9.0](https://github.com/shenwei356/csvtk/releases/tag/v0.9.0)
[![Github Releases (by Release)](https://img.shields.io/github/downloads/shenwei356/csvtk/v0.9.0/total.svg)](https://github.com/shenwei356/csvtk/releases/tag/v0.9.0)

- add subcommand `csvtk mutate2`: create new column from selected fields by **awk-like artithmetic/string expressions**
- add new command `genautocomplete` to generate **shell autocompletion** script!

Links:

***Tip: run `csvtk version` to check update !!!***

OS |Arch |File, (mirror为中国用户下载镜像链接) |Download Count
:------|:---------|:-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|:-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Linux |32-bit |[csvtk_linux_386.tar.gz](https://github.com/shenwei356/csvtk/releases/download/v0.8.0/csvtk_linux_386.tar.gz), ([mirror](http://app.shenwei.me/data/csvtk/csvtk_linux_386.tar.gz)) |[![Github Releases (by Asset)](https://img.shields.io/github/downloads/shenwei356/csvtk/latest/csvtk_linux_386.tar.gz.svg?maxAge=3600)](https://github.com/shenwei356/csvtk/releases/download/v0.8.0/csvtk_linux_386.tar.gz)
Linux |**64-bit**|[**csvtk_linux_amd64.tar.gz**](https://github.com/shenwei356/csvtk/releases/download/v0.8.0/csvtk_linux_amd64.tar.gz), ([mirror](http://app.shenwei.me/data/csvtk/csvtk_linux_amd64.tar.gz)) |[![Github Releases (by Asset)](https://img.shields.io/github/downloads/shenwei356/csvtk/latest/csvtk_linux_amd64.tar.gz.svg?maxAge=3600)](https://github.com/shenwei356/csvtk/releases/download/v0.8.0/csvtk_linux_amd64.tar.gz)
OS X |32-bit |[csvtk_darwin_386.tar.gz](https://github.com/shenwei356/csvtk/releases/download/v0.8.0/csvtk_darwin_386.tar.gz), ([mirror](http://app.shenwei.me/data/csvtk/csvtk_darwin_386.tar.gz)) |[![Github Releases (by Asset)](https://img.shields.io/github/downloads/shenwei356/csvtk/latest/csvtk_darwin_386.tar.gz.svg?maxAge=3600)](https://github.com/shenwei356/csvtk/releases/download/v0.8.0/csvtk_darwin_386.tar.gz)
OS X |**64-bit**|[**csvtk_darwin_amd64.tar.gz**](https://github.com/shenwei356/csvtk/releases/download/v0.8.0/csvtk_darwin_amd64.tar.gz), ([mirror](http://app.shenwei.me/data/csvtk/csvtk_darwin_amd64.tar.gz)) |[![Github Releases (by Asset)](https://img.shields.io/github/downloads/shenwei356/csvtk/latest/csvtk_darwin_amd64.tar.gz.svg?maxAge=3600)](https://github.com/shenwei356/csvtk/releases/download/v0.8.0/csvtk_darwin_amd64.tar.gz)
Windows|32-bit |[csvtk_windows_386.exe.tar.gz](https://github.com/shenwei356/csvtk/releases/download/v0.8.0/csvtk_windows_386.exe.tar.gz), ([mirror](http://app.shenwei.me/data/csvtk/csvtk_windows_386.exe.tar.gz)) |[![Github Releases (by Asset)](https://img.shields.io/github/downloads/shenwei356/csvtk/latest/csvtk_windows_386.exe.tar.gz.svg?maxAge=3600)](https://github.com/shenwei356/csvtk/releases/download/v0.8.0/csvtk_windows_386.exe.tar.gz)
Windows|**64-bit**|[**csvtk_windows_amd64.exe.tar.gz**](https://github.com/shenwei356/csvtk/releases/download/v0.8.0/csvtk_windows_amd64.exe.tar.gz), ([mirror](http://app.shenwei.me/data/csvtk/csvtk_windows_amd64.exe.tar.gz))|[![Github Releases (by Asset)](https://img.shields.io/github/downloads/shenwei356/csvtk/latest/csvtk_windows_amd64.exe.tar.gz.svg?maxAge=3600)](https://github.com/shenwei356/csvtk/releases/download/v0.8.0/csvtk_windows_amd64.exe.tar.gz)
Linux |32-bit |[csvtk_linux_386.tar.gz](https://github.com/shenwei356/csvtk/releases/download/v0.9.0/csvtk_linux_386.tar.gz), ([mirror](http://app.shenwei.me/data/csvtk/csvtk_linux_386.tar.gz)) |[![Github Releases (by Asset)](https://img.shields.io/github/downloads/shenwei356/csvtk/latest/csvtk_linux_386.tar.gz.svg?maxAge=3600)](https://github.com/shenwei356/csvtk/releases/download/v0.9.0/csvtk_linux_386.tar.gz)
Linux |**64-bit**|[**csvtk_linux_amd64.tar.gz**](https://github.com/shenwei356/csvtk/releases/download/v0.9.0/csvtk_linux_amd64.tar.gz), ([mirror](http://app.shenwei.me/data/csvtk/csvtk_linux_amd64.tar.gz)) |[![Github Releases (by Asset)](https://img.shields.io/github/downloads/shenwei356/csvtk/latest/csvtk_linux_amd64.tar.gz.svg?maxAge=3600)](https://github.com/shenwei356/csvtk/releases/download/v0.9.0/csvtk_linux_amd64.tar.gz)
OS X |32-bit |[csvtk_darwin_386.tar.gz](https://github.com/shenwei356/csvtk/releases/download/v0.9.0/csvtk_darwin_386.tar.gz), ([mirror](http://app.shenwei.me/data/csvtk/csvtk_darwin_386.tar.gz)) |[![Github Releases (by Asset)](https://img.shields.io/github/downloads/shenwei356/csvtk/latest/csvtk_darwin_386.tar.gz.svg?maxAge=3600)](https://github.com/shenwei356/csvtk/releases/download/v0.9.0/csvtk_darwin_386.tar.gz)
OS X |**64-bit**|[**csvtk_darwin_amd64.tar.gz**](https://github.com/shenwei356/csvtk/releases/download/v0.9.0/csvtk_darwin_amd64.tar.gz), ([mirror](http://app.shenwei.me/data/csvtk/csvtk_darwin_amd64.tar.gz)) |[![Github Releases (by Asset)](https://img.shields.io/github/downloads/shenwei356/csvtk/latest/csvtk_darwin_amd64.tar.gz.svg?maxAge=3600)](https://github.com/shenwei356/csvtk/releases/download/v0.9.0/csvtk_darwin_amd64.tar.gz)
Windows|32-bit |[csvtk_windows_386.exe.tar.gz](https://github.com/shenwei356/csvtk/releases/download/v0.9.0/csvtk_windows_386.exe.tar.gz), ([mirror](http://app.shenwei.me/data/csvtk/csvtk_windows_386.exe.tar.gz)) |[![Github Releases (by Asset)](https://img.shields.io/github/downloads/shenwei356/csvtk/latest/csvtk_windows_386.exe.tar.gz.svg?maxAge=3600)](https://github.com/shenwei356/csvtk/releases/download/v0.9.0/csvtk_windows_386.exe.tar.gz)
Windows|**64-bit**|[**csvtk_windows_amd64.exe.tar.gz**](https://github.com/shenwei356/csvtk/releases/download/v0.9.0/csvtk_windows_amd64.exe.tar.gz), ([mirror](http://app.shenwei.me/data/csvtk/csvtk_windows_amd64.exe.tar.gz))|[![Github Releases (by Asset)](https://img.shields.io/github/downloads/shenwei356/csvtk/latest/csvtk_windows_amd64.exe.tar.gz.svg?maxAge=3600)](https://github.com/shenwei356/csvtk/releases/download/v0.9.0/csvtk_windows_amd64.exe.tar.gz)

## Installation

Expand Down Expand Up @@ -69,9 +62,37 @@ And then:

go get -u github.com/shenwei356/csvtk/csvtk

## Bash-completion

Note: The current version supports Bash only.
This should work for *nix systems with Bash installed.

Howto:

1. run: `csvtk genautocomplete`

2. create and edit `~/.bash_completion` file if you don't have it.

nano ~/.bash_completion

add the following:

for bcfile in ~/.bash_completion.d/* ; do
. $bcfile
done

## Previous Versions

- [csvtk v0.8.0](https://github.com/shenwei356/csvtk/releases/tag/v0.8.0)
[![Github Releases (by Release)](https://img.shields.io/github/downloads/shenwei356/csvtk/v0.8.0/total.svg)](https://github.com/shenwei356/csvtk/releases/tag/v0.8.0)
- **new command `csvtk gather` for gathering columns into key-value pairs**.
- `csvtk sort`: support **sorting by user-defined order**.
- fix bug of *unselecting field*: wrongly reporting error of fields not existing.
affected commands: `cut`, `filter`, `fitler2`, `freq`, `grep`, `inter`, `mutate`,
`rename`, `rename2`, `replace`, `stats2`, `uniq`.
- update help message of flag `-F/--fuzzy-fields`.
- update help message of global flag `-t`, which overrides both `-d` and `-D`.
If you want other delimiter for tabular input, use `-t $'\t' -D "delimiter"`.
- [csvtk v0.7.1](https://github.com/shenwei356/csvtk/releases/tag/v0.7.1)
[![Github Releases (by Release)](https://img.shields.io/github/downloads/shenwei356/csvtk/v0.7.1/total.svg)](https://github.com/shenwei356/csvtk/releases/tag/v0.7.1)
- `csvtk plot box` and `csvtk plot line`: fix bugs for special cases of input
Expand Down
100 changes: 100 additions & 0 deletions doc/docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
- [rename2](#rename2)
- [replace](#replace)
- [mutate](#mutate)
- [mutate2](#mutate2)
- [gather](#gather)

**Ordering**
Expand All @@ -63,6 +64,10 @@
- [plot box](#plot-box)
- [plot line](#plot-line)

**Misc**

- [genautocomplete](#genautocomplete)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->

## csvtk
Expand Down Expand Up @@ -1190,6 +1195,69 @@ Examples
ken,22222,k
shenwei,999999,s

## mutate2

Usage

```
create new column from selected fields by awk-like artithmetic/string expressions
The artithmetic/string expression is supported by:
https://github.com/Knetic/govaluate
Supported operators and types:
Modifiers: + - / * & | ^ ** % >> <<
Comparators: > >= < <= == != =~ !~
Logical ops: || &&
Numeric constants, as 64-bit floating point (12345.678)
String constants (single quotes: 'foobar')
Date constants (single quotes)
Boolean constants: true false
Parenthesis to control order of evaluation ( )
Arrays (anything separated by , within parenthesis: (1, 2, 'foo'))
Prefixes: ! - ~
Ternary conditional: ? :
Null coalescence: ??
Usage:
csvtk mutate2 [flags]
Flags:
-L, --digits int number of digits after the dot (default 2)
-e, --expression string artithmetic/string expressions. e.g. '$1 + $2', '$a / $b', ' $1 > 100 ? "big" : "small" '
-h, --help help for mutate2
-n, --name string new column name
```

Example

1. Math

$ cat testdata/digitals.tsv | csvtk mutate2 -t -H -e '$1 + $3' -L 0
4 5 6 10
1 2 3 4
7 8 0 7
8 1,000 4 12

1. Bool

$ cat testdata/digitals.tsv | csvtk mutate2 -t -H -e '$1 > 5'
4 5 6 false
1 2 3 false
7 8 0 true
8 1,000 4 true

1. Ternary conditional

$ cat testdata/digitals.tsv | csvtk mutate2 -t -H -e '$1 > 5 ? "big" : "small" '
4 5 6 small
1 2 3 small
7 8 0 big
8 1,000 4 big

## gather

Usage
Expand Down Expand Up @@ -1532,7 +1600,39 @@ Examples

![scatter.png](testdata/figures/scatter.png)

## genautocomplete

Usage

```
generate shell autocompletion script
Note: The current version supports Bash only.
This should work for *nix systems with Bash installed.
Howto:
1. run: csvtk genautocomplete
2. create and edit ~/.bash_completion file if you don't have it.
nano ~/.bash_completion
add the following:
for bcfile in ~/.bash_completion.d/* ; do
. $bcfile
done
Usage:
csvtk genautocomplete [flags]
Flags:
--file string autocompletion file (default "/home/shenwei/.bash_completion.d/csvtk.sh")
-h, --help help for genautocomplete
--type string autocompletion type (currently only bash supported) (default "bash")
```

<div id="disqus_thread"></div>
<script>
Expand Down

0 comments on commit f580284

Please sign in to comment.