Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 54 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"flag"
"fmt"
"os"
"path/filepath"
"runtime"
"strings"

Expand Down Expand Up @@ -81,7 +82,7 @@ func runList(path string, max int, inclSnoozed bool, inclDone bool) {

tui.SortItems(all)

filtered := all[:0]
var filtered []*tuido.Item
for _, item := range all {
s := item.Satus()
if !inclDone && (s == tuido.Checked || s == tuido.Obsolete) {
Expand All @@ -97,10 +98,60 @@ func runList(path string, max int, inclSnoozed bool, inclDone bool) {
if max > 0 && max < count {
count = max
}
filtered = filtered[:count]

for i := 0; i < count; i++ {
fmt.Printf("%s\n", filtered[i].String())
writeTo := expandTilde(tui.GetConfigWriteTo())

type entry struct {
prefix string
text string
}
entries := make([]entry, count)
prevFile := ""
for i, item := range filtered {
loc := item.Location()
lastColon := strings.LastIndex(loc, ":")
filePath, lineStr := loc[:lastColon], loc[lastColon+1:]
baseName := filepath.Base(filePath)

absFile, err := filepath.Abs(filePath)
if err != nil {
absFile = filePath
}
isWriteTo := absFile == writeTo ||
strings.HasPrefix(absFile, writeTo+string(filepath.Separator))

switch {
case isWriteTo:
entries[i].prefix = ""
case baseName == prevFile:
entries[i].prefix = ":" + lineStr
default:
entries[i].prefix = "(" + baseName + ":" + lineStr + ")"
prevFile = baseName
}
entries[i].text = item.String()
}

maxWidth := 0
for _, e := range entries {
if len(e.prefix) > maxWidth {
maxWidth = len(e.prefix)
}
}

for _, e := range entries {
fmt.Printf("%*s %s\n", maxWidth, e.prefix, e.text)
}
}

func expandTilde(path string) string {
if strings.HasPrefix(path, "~/") {
if home, err := os.UserHomeDir(); err == nil {
return filepath.Join(home, path[2:])
}
}
return path
}

func runCreate(text string) {
Expand Down
27 changes: 27 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,33 @@ From some directory containing `[x]it!` files / items, or from anywhere to recov
tuido
```

### CLI commands

`tuido` can also be used non-interactively:

```
tuido list [--max N] [-z] [-a] [path]
```

Lists open and in-progress items from `path` (default: current directory). Snoozed and completed/cancelled items are excluded by default.

- `-z`, `--zzz` — include snoozed items
- `-a`, `--all` — include snoozed, completed, and cancelled items
- `--max N` — limit output to N items

```
tuido create <text>
tuido add <text>
```

Creates a new open item, written to the configured `writeto` location.

```
tuido init
```

Interactive setup wizard. Creates a local (`./.tuido`) or global (`~/.config/tuido.conf`) config file. Run this the first time you use `tuido` in a new context, or to reconfigure an existing one.

### In app controls

- **?**: help
Expand Down
Loading