diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index f4ced9e..6b4f59c 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -1,21 +1,23 @@ name: golangci-lint -on: - push: - pull_request: + +on: [push, pull_request] + permissions: contents: read - # Optional: allow read access to pull request. Use with `only-new-issues` option. - # pull-requests: read + +env: + GO_VERSION: 1.20 + jobs: golangci: name: lint runs-on: ubuntu-latest steps: - - uses: actions/setup-go@v3 + - uses: actions/setup-go@v4 with: - go-version: 1.18 - - uses: actions/checkout@v3 + go-version: ${{ env.GO_VERSION }} + - uses: actions/checkout@v4 - name: golangci-lint uses: golangci/golangci-lint-action@v3 with: - version: v1.48 + version: v1.54.2 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 0dd1e70..e02e628 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,10 +1,15 @@ name: Prepare Release + on: workflow_dispatch: inputs: release_id: description: "Release id (tag name)" required: true + +env: + GO_VERSION: 1.20 + jobs: create_release: name: Create release draft @@ -14,9 +19,9 @@ jobs: steps: - name: Create release id: create_release - uses: actions/create-release@v1 # https://github.com/actions/create-release + uses: actions/create-release@v1 # TODO: replace deprecated action env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Automatically provided + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: tag_name: ${{ github.event.inputs.release_id }} body: | @@ -29,6 +34,7 @@ jobs: release_name: ${{ github.event.inputs.release_id }} prerelease: true draft: true + build: name: Build needs: create_release @@ -49,10 +55,10 @@ jobs: binary_name: stoic runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - uses: actions/setup-go@v2 + - uses: actions/checkout@v4 + - uses: actions/setup-go@v4 with: - go-version: "1.18" + go-version: ${{ env.GO_VERSION }} - name: Build binary env: GOOS: ${{ matrix.go_os }} @@ -66,9 +72,9 @@ jobs: fi zip -j stoic-${{ matrix.name }}.zip ./out/${{ matrix.binary_name }} ./LICENSE ./INSTALL.md ./CHANGELOG.md - name: Upload binaries - uses: actions/upload-release-asset@v1 # https://github.com/actions/upload-release-asset + uses: actions/upload-release-asset@v1 # TODO: replace deprecated action env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Automatically provided + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: upload_url: ${{ needs.create_release.outputs.upload_url }} asset_path: ./stoic-${{ matrix.name }}.zip diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4f407a1..c55d083 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,41 +1,38 @@ -on: [push, pull_request] name: Test + +on: [push, pull_request] + +env: + GO_VERSION: 1.20 + jobs: test: strategy: matrix: - go-version: [1.18.x] os: [ubuntu-latest, macos-latest] runs-on: ${{ matrix.os }} steps: - - uses: actions/setup-go@v3 + - uses: actions/setup-go@v4 with: - go-version: ${{ matrix.go-version }} - - uses: actions/checkout@v3 + go-version: ${{ env.GO_VERSION }} + - uses: actions/checkout@v4 - run: go test ./... test-cache: - strategy: - matrix: - go-version: [1.18.x] runs-on: ubuntu-latest steps: - - uses: actions/setup-go@v3 + - uses: actions/setup-go@v4 with: - go-version: 1.18.x - - uses: actions/checkout@v3 - - uses: actions/cache@v2 + go-version: ${{ env.GO_VERSION }} + - uses: actions/checkout@v4 + - uses: actions/cache@v3 with: - # In order: - # * Module download cache - # * Build cache (Linux) - # * Build cache (Mac) path: | ~/go/pkg/mod ~/.cache/go-build ~/Library/Caches/go-build ~\AppData\Local\go-build - key: ${{ runner.os }}-go-${{ matrix.go-version }}-${{ hashFiles('**/go.sum') }} + key: ${{ runner.os }}-go-${{ env.GO_VERSION }}-${{ hashFiles('**/go.sum') }} restore-keys: | - ${{ runner.os }}-go-${{ matrix.go-version }}- + ${{ runner.os }}-go-${{ env.GO_VERSION }}- - run: go test ./... diff --git a/.golangci.yml b/.golangci.yml index f3dbc0b..6a5c634 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,23 +1,165 @@ linters: - disable-all: true - enable: - - deadcode # Finds unused code - - errcheck # Errcheck is a program for checking for unchecked errors in go programs. These unchecked errors can be critical bugs in some cases - - gosimple # Linter for Go source code that specializes in simplifying a code - - govet # Vet examines Go source code and reports suspicious constructs, such as Printf calls whose arguments do not align with the format string - - ineffassign # Detects when assignments to existing variables are not used - - staticcheck # Staticcheck is a go vet on steroids, applying a ton of static analysis checks - # - structcheck # Finds unused struct fields - - typecheck # Like the front-end of a Go compiler, parses and type-checks Go code - - unused # Checks Go code for unused constants, variables, functions and types - - varcheck # Finds unused global variables and constants - ## disabled by default - - errname # Checks that sentinel errors are prefixed with the Err and error types are suffixed with the Error. - - errorlint # errorlint is a linter for that can be used to find code that will cause problems with the error wrapping scheme introduced in Go 1.13. - - goconst # Finds repeated strings that could be replaced by a constant - - gocritic # Provides diagnostics that check for bugs, performance and style issues. - # - gosec # Inspects source code for security problems - - unconvert # Remove unnecessary type conversions - - unparam # Reports unused function parameters - - usestdlibvars # detect the possibility to use variables/constants from the Go standard library - # - wastedassign # wastedassign finds wasted assignment statements. + presets: + - bugs + - comment + - complexity + - error + - format + - import + - metalinter + - module + - performance + - sql + - style + - test + - unused + + # Linters presets: + # bugs: asciicheck, bodyclose, durationcheck, errcheck, errorlint, exhaustive, exportloopref, gosec, govet, makezero, nilerr, noctx, rowserrcheck, scopelint, sqlclosecheck, staticcheck, typecheck + # comment: godot, godox, misspell + # complexity: cyclop, funlen, gocognit, gocyclo, nestif + # error: errcheck, errorlint, goerr113, wrapcheck + # format: gci, gofmt, gofumpt, goimports + # import: depguard, gci, goimports, gomodguard + # metalinter: gocritic, govet, revive, staticcheck + # module: depguard, gomoddirectives, gomodguard + # performance: bodyclose, maligned, noctx, prealloc + # sql: rowserrcheck, sqlclosecheck + # style: asciicheck, depguard, dogsled, dupl, exhaustivestruct, forbidigo, forcetypeassert, gochecknoglobals, gochecknoinits, goconst, gocritic, godot, godox, goerr113, goheader, golint, gomnd, gomoddirectives, gomodguard, goprintffuncname, gosimple, ifshort, importas, interfacer, lll, makezero, misspell, nakedret, nlreturn, nolintlint, paralleltest, predeclared, promlinter, revive, stylecheck, tagliatelle, testpackage, thelper, tparallel, unconvert, wastedassign, whitespace, wrapcheck, wsl + # test: exhaustivestruct, paralleltest, testpackage, tparallel + # unused: deadcode, ineffassign, structcheck, unparam, unused, varcheck + + enable: [] + # Enabled by default linters: + # deadcode: Finds unused code [fast: false, auto-fix: false] + # errcheck: Errcheck is a program for checking for unchecked errors in go programs. These unchecked errors can be critical bugs in some cases [fast: false, auto-fix: false] + # gosimple (megacheck): Linter for Go source code that specializes in simplifying a code [fast: false, auto-fix: false] + # govet (vet, vetshadow): Vet examines Go source code and reports suspicious constructs, such as Printf calls whose arguments do not align with the format string [fast: false, auto-fix: false] + # ineffassign: Detects when assignments to existing variables are not used [fast: true, auto-fix: false] + # staticcheck (megacheck): Staticcheck is a go vet on steroids, applying a ton of static analysis checks [fast: false, auto-fix: false] + # structcheck: Finds unused struct fields [fast: false, auto-fix: false] + # typecheck: Like the front-end of a Go compiler, parses and type-checks Go code [fast: false, auto-fix: false] + # unused (megacheck): Checks Go code for unused constants, variables, functions and types [fast: false, auto-fix: false] + # varcheck: Finds unused global variables and constants [fast: false, auto-fix: false] + + disable: + - deadcode # deprecated + - exhaustivestruct # deprecated + - golint # deprecated + - ifshort #deprecated + - interfacer # deprecated + - maligned # deprecated + - nosnakecase # depreceated + - scopelint # deprecated + - structcheck # deprecated + - varcheck # deprecated + # TODO: handle the issue with the following linters + - gochecknoglobals # flags our globals + - depguard # flags our modules + - forbidigo # flags our fmt.Println + - wrapcheck # flags our unchecked errors + - varnamelen # flags our short variable names + - testpackage # flags our test package for not using _test + - staticcheck # flags our use of depreccated functions + - paralleltest # flags our failure to use t.Parallel() + - ireturn # flags our use of returned interfaces + - gomnd # flags our use of magic numbers + - revive # flags our use of underscores in variable names + - stylecheck # flags our use of underscores in variable names + - prealloc # flags our failure to preallocated slices + - lll # flags our long lines + - gosec # flags our use of exec.Command and math/rand + # - bodyclose # toggle on when desired + # - dupl # toggle on when desired + # - errcheck # toggle on when desired + # - errorlint # toggle on when desired + # - forbidigo # not useful for cli with default config + # - forcetypeassert # toggle on when desired + # - gci # toggle on when desired + # - gochecknoglobals # toggle on when desired + # - gocritic # toggle on when desired + # - godox # toggle on when desired + # - goerr113 # toggle on when desired + # - gomnd # toggle on when desired + # - gosec # toggle on when desired + # - ifshort # toggle on when desired + # - lll # toggle on when desired + # - nlreturn # toggle on when desired + # - noctx # toggle on when desired + # - paralleltest # toggle on when desired + # - revive # toggle on when desired + # - staticcheck # toggle on when desired + # - tagliatelle # toggle on when desired + # - testpackage # toggle on when desired + # - unconvert # toggle on when desired + # - unparam # toggle on when desired + # - wrapcheck # toggle on when desired + # - wsl # toggle on when desired + + # Disabled by default linters: + # asciicheck: Simple linter to check that your code does not contain non-ASCII identifiers [fast: true, auto-fix: false] + # bodyclose: checks whether HTTP response body is closed successfully [fast: false, auto-fix: false] + # cyclop: checks function and package cyclomatic complexity [fast: false, auto-fix: false] + # depguard: Go linter that checks if package imports are in a list of acceptable packages [fast: false, auto-fix: false] + # dogsled: Checks assignments with too many blank identifiers (e.g. x, _, _, _, := f()) [fast: true, auto-fix: false] + # dupl: Tool for code clone detection [fast: true, auto-fix: false] + # durationcheck: check for two durations multiplied together [fast: false, auto-fix: false] + # errorlint: errorlint is a linter for that can be used to find code that will cause problems with the error wrapping scheme introduced in Go 1.13. [fast: false, auto-fix: false] + # exhaustive: check exhaustiveness of enum switch statements [fast: false, auto-fix: false] + # exhaustivestruct: Checks if all struct's fields are initialized [fast: false, auto-fix: false] + # exportloopref: checks for pointers to enclosing loop variables [fast: false, auto-fix: false] + # forbidigo: Forbids identifiers [fast: true, auto-fix: false] + # forcetypeassert: finds forced type assertions [fast: true, auto-fix: false] + # funlen: Tool for detection of long functions [fast: true, auto-fix: false] + # gci: Gci control golang package import order and make it always deterministic. [fast: true, auto-fix: true] + # gochecknoglobals: check that no global variables exist [fast: true, auto-fix: false] + # gochecknoinits: Checks that no init functions are present in Go code [fast: true, auto-fix: false] + # gocognit: Computes and checks the cognitive complexity of functions [fast: true, auto-fix: false] + # goconst: Finds repeated strings that could be replaced by a constant [fast: true, auto-fix: false] + # gocritic: Provides many diagnostics that check for bugs, performance and style issues. [fast: false, auto-fix: false] + # gocyclo: Computes and checks the cyclomatic complexity of functions [fast: true, auto-fix: false] + # godot: Check if comments end in a period [fast: true, auto-fix: true] + # godox: Tool for detection of FIXME, TODO and other comment keywords [fast: true, auto-fix: false] + # goerr113: Golang linter to check the errors handling expressions [fast: false, auto-fix: false] + # gofmt: Gofmt checks whether code was gofmt-ed. By default this tool runs with -s option to check for code simplification [fast: true, auto-fix: true] + # gofumpt: Gofumpt checks whether code was gofumpt-ed. [fast: true, auto-fix: true] + # goheader: Checks is file header matches to pattern [fast: true, auto-fix: false] + # goimports: Goimports does everything that gofmt does. Additionally it checks unused imports [fast: true, auto-fix: true] + # golint: Golint differs from gofmt. Gofmt reformats Go source code, whereas golint prints out style mistakes [fast: false, auto-fix: false] + # gomnd: An analyzer to detect magic numbers. [fast: true, auto-fix: false] + # gomoddirectives: Manage the use of 'replace', 'retract', and 'excludes' directives in go.mod. [fast: true, auto-fix: false] + # gomodguard: Allow and block list linter for direct Go module dependencies. This is different from depguard where there are different block types for example version constraints and module recommendations. [fast: true, auto-fix: false] + # goprintffuncname: Checks that printf-like functions are named with `f` at the end [fast: true, auto-fix: false] + # gosec (gas): Inspects source code for security problems [fast: false, auto-fix: false] + # ifshort: Checks that your code uses short syntax for if-statements whenever possible [fast: true, auto-fix: false] + # importas: Enforces consistent import aliases [fast: false, auto-fix: false] + # interfacer: Linter that suggests narrower interface types [fast: false, auto-fix: false] + # lll: Reports long lines [fast: true, auto-fix: false] + # makezero: Finds slice declarations with non-zero initial length [fast: false, auto-fix: false] + # maligned: Tool to detect Go structs that would take less memory if their fields were sorted [fast: false, auto-fix: false] + # misspell: Finds commonly misspelled English words in comments [fast: true, auto-fix: true] + # nakedret: Finds naked returns in functions greater than a specified function length [fast: true, auto-fix: false] + # nestif: Reports deeply nested if statements [fast: true, auto-fix: false] + # nilerr: Finds the code that returns nil even if it checks that the error is not nil. [fast: false, auto-fix: false] + # nlreturn: nlreturn checks for a new line before return and branch statements to increase code clarity [fast: true, auto-fix: false] + # noctx: noctx finds sending http request without context.Context [fast: false, auto-fix: false] + # nolintlint: Reports ill-formed or insufficient nolint directives [fast: true, auto-fix: false] + # paralleltest: paralleltest detects missing usage of t.Parallel() method in your Go test [fast: true, auto-fix: false] + # prealloc: Finds slice declarations that could potentially be preallocated [fast: true, auto-fix: false] + # predeclared: find code that shadows one of Go's predeclared identifiers [fast: true, auto-fix: false] + # promlinter: Check Prometheus metrics naming via promlint [fast: true, auto-fix: false] + # revive: Fast, configurable, extensible, flexible, and beautiful linter for Go. Drop-in replacement of golint. [fast: false, auto-fix: false] + # rowserrcheck: checks whether Err of rows is checked successfully [fast: false, auto-fix: false] + # scopelint: Scopelint checks for unpinned variables in go programs [fast: true, auto-fix: false] + # sqlclosecheck: Checks that sql.Rows and sql.Stmt are closed. [fast: false, auto-fix: false] + # stylecheck: Stylecheck is a replacement for golint [fast: false, auto-fix: false] + # tagliatelle: Checks the struct tags. [fast: true, auto-fix: false] + # testpackage: linter that makes you use a separate _test package [fast: true, auto-fix: false] + # thelper: thelper detects golang test helpers without t.Helper() call and checks the consistency of test helpers [fast: false, auto-fix: false] + # tparallel: tparallel detects inappropriate usage of t.Parallel() method in your Go test codes [fast: false, auto-fix: false] + # unconvert: Remove unnecessary type conversions [fast: false, auto-fix: false] + # unparam: Reports unused function parameters [fast: false, auto-fix: false] + # wastedassign: wastedassign finds wasted assignment statements. [fast: false, auto-fix: false] + # whitespace: Tool for detection of leading and trailing whitespace [fast: true, auto-fix: true] + # wrapcheck: Checks that errors returned from external packages are wrapped [fast: false, auto-fix: false] + # wsl: Whitespace Linter - Forces you to use empty lines! [fast: true, auto-fix: false] diff --git a/cmd/edit.go b/cmd/edit.go index a359b36..890915b 100644 --- a/cmd/edit.go +++ b/cmd/edit.go @@ -40,6 +40,7 @@ func (e *editCommand) Date() time.Time { func (e *editCommand) Run() { entry := stoic.NewEntry(e.ctx, e.date) + err := e.ctx.OpenInEditor(entry) if err != nil { fmt.Println("Error running program:", err) diff --git a/cmd/list.go b/cmd/list.go index 20443c0..a47c971 100644 --- a/cmd/list.go +++ b/cmd/list.go @@ -27,6 +27,7 @@ func NewListCommand(ctx stoic.Context) ListCommand { func (lc listCommand) Run() { var items []list.Item + files := lc.ctx.Files() for _, file := range files { @@ -85,11 +86,14 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { selectedItem, _ := m.list.SelectedItem().(item) _ = OpenFileInEditor(selectedItem.title, m.context) + os.Exit(0) + case msg.String() == " ": selectedItem, _ := m.list.SelectedItem().(item) _ = OpenFileInEditor(selectedItem.title, m.context) + os.Exit(0) } case tea.WindowSizeMsg: @@ -99,6 +103,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { var cmd tea.Cmd m.list, cmd = m.list.Update(msg) + return m, cmd } @@ -111,6 +116,7 @@ func OpenFileInEditor(filepath string, ctx stoic.Context) error { cmd.Stdin = os.Stdin cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr + return cmd.Run() } @@ -144,6 +150,7 @@ func ConvertBytesToSizeString(size int64) string { } else if curr < thousand { return fmt.Sprintf("%d%s", int(curr), s) } + curr /= thousand } diff --git a/go.mod b/go.mod index e1fc1cb..6aa94e9 100644 --- a/go.mod +++ b/go.mod @@ -1,38 +1,35 @@ module github.com/skatkov/stoic -go 1.19 +go 1.20 require ( - github.com/charmbracelet/lipgloss v0.5.0 + github.com/charmbracelet/bubbles v0.16.1 + github.com/charmbracelet/bubbletea v0.24.2 + github.com/charmbracelet/lipgloss v0.8.0 github.com/mitchellh/go-homedir v1.1.0 - github.com/stretchr/testify v1.8.0 + github.com/stretchr/testify v1.4.0 github.com/tj/go-naturaldate v1.3.0 ) require ( github.com/atotto/clipboard v0.1.4 // indirect - github.com/containerd/console v1.0.3 // indirect - github.com/kr/pretty v0.3.0 // indirect + github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect + github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81 // indirect + github.com/davecgh/go-spew v1.1.0 // indirect github.com/lucasb-eyer/go-colorful v1.2.0 // indirect - github.com/mattn/go-isatty v0.0.16 // indirect + github.com/mattn/go-isatty v0.0.19 // indirect github.com/mattn/go-localereader v0.0.1 // indirect - github.com/mattn/go-runewidth v0.0.13 // indirect - github.com/muesli/ansi v0.0.0-20211031195517-c9f0611b6c70 // indirect + github.com/mattn/go-runewidth v0.0.15 // indirect + github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect github.com/muesli/cancelreader v0.2.2 // indirect github.com/muesli/reflow v0.3.0 // indirect - github.com/muesli/termenv v0.12.0 // indirect - github.com/rivo/uniseg v0.3.4 // indirect - github.com/sahilm/fuzzy v0.1.0 // indirect - golang.org/x/sys v0.0.0-20220818161305-2296e01440c6 // indirect - golang.org/x/term v0.0.0-20220722155259-a9ba230a4035 // indirect - golang.org/x/text v0.3.7 // indirect - gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect - gopkg.in/yaml.v3 v3.0.1 // indirect -) - -require ( - github.com/charmbracelet/bubbles v0.13.0 - github.com/charmbracelet/bubbletea v0.22.1 - github.com/davecgh/go-spew v1.1.1 // indirect + github.com/muesli/termenv v0.15.2 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect + github.com/rivo/uniseg v0.4.4 // indirect + github.com/sahilm/fuzzy v0.1.0 // indirect + golang.org/x/sync v0.3.0 // indirect + golang.org/x/sys v0.12.0 // indirect + golang.org/x/term v0.12.0 // indirect + golang.org/x/text v0.13.0 // indirect + gopkg.in/yaml.v2 v2.2.2 // indirect ) diff --git a/go.sum b/go.sum index 262d88e..07e18ee 100644 --- a/go.sum +++ b/go.sum @@ -1,106 +1,63 @@ github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z4= github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI= -github.com/charmbracelet/bubbles v0.11.0 h1:fBLyY0PvJnd56Vlu5L84JJH6f4axhgIJ9P3NET78f0Q= -github.com/charmbracelet/bubbles v0.11.0/go.mod h1:bbeTiXwPww4M031aGi8UK2HT9RDWoiNibae+1yCMtcc= -github.com/charmbracelet/bubbles v0.13.0 h1:zP/ROH3wJEBqZWKIsD50ZKKlx3ydLInq3LdD/Nrlb8w= -github.com/charmbracelet/bubbles v0.13.0/go.mod h1:bbeTiXwPww4M031aGi8UK2HT9RDWoiNibae+1yCMtcc= -github.com/charmbracelet/bubbletea v0.21.0 h1:f3y+kanzgev5PA916qxmDybSHU3N804uOnKnhRPXTcI= -github.com/charmbracelet/bubbletea v0.21.0/go.mod h1:GgmJMec61d08zXsOhqRC/AiOx4K4pmz+VIcRIm1FKr4= -github.com/charmbracelet/bubbletea v0.22.1 h1:z66q0LWdJNOWEH9zadiAIXp2GN1AWrwNXU8obVY9X24= -github.com/charmbracelet/bubbletea v0.22.1/go.mod h1:8/7hVvbPN6ZZPkczLiB8YpLkLJ0n7DMho5Wvfd2X1C0= -github.com/charmbracelet/harmonica v0.2.0/go.mod h1:KSri/1RMQOZLbw7AHqgcBycp8pgJnQMYYT8QZRqZ1Ao= -github.com/charmbracelet/lipgloss v0.5.0 h1:lulQHuVeodSgDez+3rGiuxlPVXSnhth442DATR2/8t8= -github.com/charmbracelet/lipgloss v0.5.0/go.mod h1:EZLha/HbzEt7cYqdFPovlqy5FZPj0xFhg5SaqxScmgs= -github.com/containerd/console v1.0.3 h1:lIr7SlA5PxZyMV30bDW0MGbiOPXwc63yRuCP0ARubLw= -github.com/containerd/console v1.0.3/go.mod h1:7LqA/THxQ86k76b8c/EMSiaJ3h1eZkMkXar0TQ1gf3U= -github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= +github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k= +github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8= +github.com/charmbracelet/bubbles v0.16.1 h1:6uzpAAaT9ZqKssntbvZMlksWHruQLNxg49H5WdeuYSY= +github.com/charmbracelet/bubbles v0.16.1/go.mod h1:2QCp9LFlEsBQMvIYERr7Ww2H2bA7xen1idUDIzm/+Xc= +github.com/charmbracelet/bubbletea v0.24.2 h1:uaQIKx9Ai6Gdh5zpTbGiWpytMU+CfsPp06RaW2cx/SY= +github.com/charmbracelet/bubbletea v0.24.2/go.mod h1:XdrNrV4J8GiyshTtx3DNuYkR1FDaJmO3l2nejekbsgg= +github.com/charmbracelet/lipgloss v0.8.0 h1:IS00fk4XAHcf8uZKc3eHeMUTCxUH6NkaTrdyCQk84RU= +github.com/charmbracelet/lipgloss v0.8.0/go.mod h1:p4eYUZZJ/0oXTuCQKFF8mqyKCz0ja6y+7DniDDw5KKU= +github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81 h1:q2hJAaP1k2wIvVRd/hEHD7lacgqrCPS+k8g1MndzfWY= +github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81/go.mod h1:YynlIjWYF8myEu6sdkwKIvGQq+cOckRm6So2avqoYAk= +github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= -github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= -github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0= -github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk= -github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= -github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= -github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= -github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= -github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY= github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0= -github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y= -github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= -github.com/mattn/go-isatty v0.0.16 h1:bq3VjFmv/sOjHtdEhmkEV4x1AJtvUvOJ2PFAZ5+peKQ= -github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= +github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA= +github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mattn/go-localereader v0.0.1 h1:ygSAOl7ZXTx4RdPYinUpg6W99U8jWvWi9Ye2JC/oIi4= github.com/mattn/go-localereader v0.0.1/go.mod h1:8fBrzywKY7BI3czFoHkuzRoWE9C+EiG4R1k4Cjx5p88= -github.com/mattn/go-runewidth v0.0.10/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk= github.com/mattn/go-runewidth v0.0.12/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk= -github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU= -github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= +github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U= +github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= -github.com/muesli/ansi v0.0.0-20211018074035-2e021307bc4b/go.mod h1:fQuZ0gauxyBcmsdE3ZT4NasjaRdxmbCS0jRHsrWu3Ho= -github.com/muesli/ansi v0.0.0-20211031195517-c9f0611b6c70 h1:kMlmsLSbjkikxQJ1IPwaM+7LJ9ltFu/fi8CRzvSnQmA= -github.com/muesli/ansi v0.0.0-20211031195517-c9f0611b6c70/go.mod h1:fQuZ0gauxyBcmsdE3ZT4NasjaRdxmbCS0jRHsrWu3Ho= -github.com/muesli/cancelreader v0.2.0 h1:SOpr+CfyVNce341kKqvbhhzQhBPyJRXQaCtn03Pae1Q= -github.com/muesli/cancelreader v0.2.0/go.mod h1:3XuTXfFS2VjM+HTLZY9Ak0l6eUKfijIfMUZ4EgX0QYo= +github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 h1:ZK8zHtRHOkbHy6Mmr5D264iyp3TiX5OmNcI5cIARiQI= +github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6/go.mod h1:CJlz5H+gyd6CUWT45Oy4q24RdLyn7Md9Vj2/ldJBSIo= github.com/muesli/cancelreader v0.2.2 h1:3I4Kt4BQjOR54NavqnDogx/MIoWBFa0StPA8ELUXHmA= github.com/muesli/cancelreader v0.2.2/go.mod h1:3XuTXfFS2VjM+HTLZY9Ak0l6eUKfijIfMUZ4EgX0QYo= -github.com/muesli/reflow v0.2.1-0.20210115123740-9e1d0d53df68/go.mod h1:Xk+z4oIWdQqJzsxyjgl3P22oYZnHdZ8FFTHAQQt5BMQ= github.com/muesli/reflow v0.3.0 h1:IFsN6K9NfGtjeggFP+68I4chLZV2yIKsXJFNZ+eWh6s= github.com/muesli/reflow v0.3.0/go.mod h1:pbwTDkVPibjO2kyvBQRBxTWEEGDGq0FlB1BIKtnHY/8= -github.com/muesli/termenv v0.11.1-0.20220204035834-5ac8409525e0/go.mod h1:Bd5NYQ7pd+SrtBSrSNoBBmXlcY8+Xj4BMJgh8qcZrvs= -github.com/muesli/termenv v0.11.1-0.20220212125758-44cd13922739/go.mod h1:Bd5NYQ7pd+SrtBSrSNoBBmXlcY8+Xj4BMJgh8qcZrvs= -github.com/muesli/termenv v0.12.0 h1:KuQRUE3PgxRFWhq4gHvZtPSLCGDqM5q/cYr1pZ39ytc= -github.com/muesli/termenv v0.12.0/go.mod h1:WCCv32tusQ/EEZ5S8oUIIrC/nIuBcxCVqlN4Xfkv+7A= +github.com/muesli/termenv v0.15.2 h1:GohcuySI0QmI3wN8Ok9PtKGkgkFIk7y6Vpb5PvrY+Wo= +github.com/muesli/termenv v0.15.2/go.mod h1:Epx+iuz8sNs7mNKhxzH4fWXGNpZwUaJKRS1noLXviQ8= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= -github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY= github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= -github.com/rivo/uniseg v0.3.4 h1:3Z3Eu6FGHZWSfNKJTOUiPatWwfc7DzJRU04jFUqJODw= -github.com/rivo/uniseg v0.3.4/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= -github.com/rogpeppe/go-internal v1.6.1 h1:/FiVV8dS/e+YqF2JvO3yXRFbBLTIuSDkuC7aBOAvL+k= -github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= +github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis= +github.com/rivo/uniseg v0.4.4/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= github.com/sahilm/fuzzy v0.1.0 h1:FzWGaw2Opqyu+794ZQ9SYifWv2EIXpwP4q8dY1kDAwI= github.com/sahilm/fuzzy v0.1.0/go.mod h1:VFvziUEIMCrT6A6tw2RFIXPXXmzXbOsSHF0DOI8ZK9Y= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/objx v0.4.0 h1:M2gUjqZET1qApGOWNSnZ49BAIMX4F/1plDv3+l31EJ4= -github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= -github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY= -github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk= -github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/tj/assert v0.0.0-20190920132354-ee03d75cd160 h1:NSWpaDaurcAJY7PkL8Xt0PhZE7qpvbZl5ljd8r6U0bI= github.com/tj/assert v0.0.0-20190920132354-ee03d75cd160/go.mod h1:mZ9/Rh9oLWpLLDRpvE+3b7gP/C2YyLFYxNmcLnPTMe0= github.com/tj/go-naturaldate v1.3.0 h1:OgJIPkR/Jk4bFMBLbxZ8w+QUxwjqSvzd9x+yXocY4RI= github.com/tj/go-naturaldate v1.3.0/go.mod h1:rpUbjivDKiS1BlfMGc2qUKNZ/yxgthOfmytQs8d8hKk= -golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220204135822-1c1b9b1eba6a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220209214540-3681064d5158/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220610221304-9f5ed59c137d h1:Zu/JngovGLVi6t2J3nmAf3AoTDwuzw85YZ3b9o4yU7s= -golang.org/x/sys v0.0.0-20220610221304-9f5ed59c137d/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220818161305-2296e01440c6 h1:Sx/u41w+OwrInGdEckYmEuU5gHoGSL4QbDz3S9s6j4U= -golang.org/x/sys v0.0.0-20220818161305-2296e01440c6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= -golang.org/x/term v0.0.0-20220526004731-065cf7ba2467 h1:CBpWXWQpIRjzmkkA+M7q9Fqnwd2mZr3AFqexg8YTfoM= -golang.org/x/term v0.0.0-20220526004731-065cf7ba2467/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= -golang.org/x/term v0.0.0-20220722155259-a9ba230a4035 h1:Q5284mrmYTpACcm+eAKjKJH48BBwSyfJqmmGDTtT8Vc= -golang.org/x/term v0.0.0-20220722155259-a9ba230a4035/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= -golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk= -golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E= +golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y= +golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o= +golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/term v0.12.0 h1:/ZfYdc3zq+q02Rv9vGqTeSItdzZTSNDmfTi0mBAuidU= +golang.org/x/term v0.12.0/go.mod h1:owVbMEjm3cBLCHdkQu9b1opXd4ETQWc3BhuQGKgXgvU= +golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k= +golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= -gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= +gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= -gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/internal/context.go b/internal/context.go index 8c8af21..c236091 100644 --- a/internal/context.go +++ b/internal/context.go @@ -63,6 +63,7 @@ func (ctx *context) OpenInEditor(entry Entry) error { err := createDirectoryIfMissing(ctx.directory) if err != nil { fmt.Println(err) + return err } @@ -74,6 +75,7 @@ func (ctx *context) OpenInEditor(entry Entry) error { cmd.Stdin = os.Stdin cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr + return cmd.Run() } @@ -112,6 +114,7 @@ func readFile(filename string) (string, error) { defer file.Close() var lines []string + scanner := bufio.NewScanner(file) for scanner.Scan() { lines = append(lines, scanner.Text()) @@ -134,6 +137,7 @@ func (ctx context) Files() []string { files, _ := os.ReadDir(ctx.directory) var filenames []string + for _, file := range files { if strings.HasSuffix(file.Name(), ctx.fileExtension) { filename := strings.TrimSuffix(file.Name(), "."+ctx.fileExtension)