Skip to content

Commit

Permalink
feat!: cleanup and updated (#619)
Browse files Browse the repository at this point in the history
* feat!: cleanup

Signed-off-by: Carlos Alexandro Becker <[email protected]>

* more cleanup

Signed-off-by: Carlos Alexandro Becker <[email protected]>

* fix: more cleanup

Signed-off-by: Carlos Alexandro Becker <[email protected]>

* fix: more cleanup

---------

Signed-off-by: Carlos Alexandro Becker <[email protected]>
  • Loading branch information
caarlos0 authored Jul 3, 2024
1 parent d2e7742 commit fce3edf
Show file tree
Hide file tree
Showing 27 changed files with 692 additions and 2,962 deletions.
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ linters:
- goimports
- goprintffuncname
- gosec
- ifshort
# - ifshort
- misspell
- prealloc
- revive
Expand Down
7 changes: 2 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

.PHONY: default clean glow run log

LOGFILE := debug.log

default: glow

clean:
Expand All @@ -13,8 +11,7 @@ glow:
go build

run: clean glow
GLOW_LOGFILE=$(LOGFILE) ./glow
./glow

log:
> $(LOGFILE)
tail -f $(LOGFILE)
tail -f ~/.cache/glow/glow.log
52 changes: 7 additions & 45 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,9 @@ Glow is a terminal based markdown reader designed from the ground up to bring
out the beauty—and power—of the CLI.

Use it to discover markdown files, read documentation directly on the command
line and stash markdown files to your own private collection, so you can read
them anywhere. Glow will find local markdown files in subdirectories or a local
line. Glow will find local markdown files in subdirectories or a local
Git repository.

By the way, all data stashed is encrypted end-to-end: only you can decrypt it.
More on that below.

## Installation

### Package Manager
Expand Down Expand Up @@ -84,6 +80,7 @@ packages. ARM builds are also available for macOS, Linux, FreeBSD and OpenBSD.
### Go

Or just install it with `go`:

```bash
go install github.com/charmbracelet/glow@latest
```
Expand All @@ -98,27 +95,17 @@ go build

[releases]: https://github.com/charmbracelet/glow/releases


## The TUI

Simply run `glow` without arguments to start the textual user interface and
browse local and stashed markdown. Glow will find local markdown files in the
browse local. Glow will find local markdown files in the
current directory and below or, if you’re in a Git repository, Glow will search
the repo.

Markdown files can be read with Glow's high-performance pager. Most of the
keystrokes you know from `less` are the same, but you can press `?` to list
the hotkeys.

### Stashing

Glow works with the Charm Cloud to allow you to store any markdown files in
your own private collection. You can stash a local document from the Glow TUI by
pressing `s`.

Stashing is private, its contents will not be exposed publicly, and it's
encrypted end-to-end. More on encryption below.

## The CLI

In addition to a TUI, Glow has a CLI for working with Markdown. To format a
Expand All @@ -138,18 +125,6 @@ glow github.com/charmbracelet/glow
glow https://host.tld/file.md
```

### Stashing

You can also stash documents from the CLI:

```bash
glow stash README.md
```

Then, when you run `glow` without arguments will you can browse through your
stashed documents. This is a great way to keep track of things that you need to
reference often.

### Word Wrapping

The `-w` flag lets you set a maximum width at which the output will be wrapped:
Expand Down Expand Up @@ -211,32 +186,19 @@ pager: true
width: 80
```
## 🔒 Encryption: How It Works
Encryption works by issuing symmetric keys (basically a generated password) and
encrypting it with the local SSH public key generated by the open-source
[charm][charmlib] library. That encrypted key is then sent up to our server.
We can’t read it since we don’t have your private key. When you want to decrypt
something or view your stash, that key is downloaded from our server and
decrypted locally using the SSH private key. When you link accounts, the
symmetric key is encrypted for each new public key. This happens on your
machine and not our server, so we never see any unencrypted data.
[charmlib]: https://github.com/charmbracelet/charm
## Feedback
We’d love to hear your thoughts on this project. Feel free to drop us a note!
* [Twitter](https://twitter.com/charmcli)
* [The Fediverse](https://mastodon.social/@charmcli)
* [Discord](https://charm.sh/chat)
- [Twitter](https://twitter.com/charmcli)
- [The Fediverse](https://mastodon.social/@charmcli)
- [Discord](https://charm.sh/chat)
## License
[MIT](https://github.com/charmbracelet/glow/raw/master/LICENSE)
***
---
Part of [Charm](https://charm.sh).
Expand Down
94 changes: 51 additions & 43 deletions config_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,61 +13,35 @@ import (

const defaultConfig = `# style name or JSON path (default "auto")
style: "auto"
# show local files only; no network (TUI-mode only)
local: false
# mouse support (TUI-mode only)
mouse: false
# use pager to display markdown
pager: false
# word-wrap at width
width: 80`
width: 80
`

var configCmd = &cobra.Command{
Use: "config",
Hidden: false,
Short: "Edit the glow config file",
Long: paragraph(fmt.Sprintf("\n%s the glow config file. We’ll use EDITOR to determine which editor to use. If the config file doesn't exist, it will be created.", keyword("Edit"))),
Example: paragraph("glow config\nglow config --config path/to/config.yml"),
Args: cobra.NoArgs,
SilenceUsage: true,
RunE: func(_ *cobra.Command, _ []string) error {
if configFile == "" {
scope := gap.NewScope(gap.User, "glow")

var err error
configFile, err = scope.ConfigPath("glow.yml")
if err != nil {
return err
}
}

if ext := path.Ext(configFile); ext != ".yaml" && ext != ".yml" {
return fmt.Errorf("'%s' is not a supported config type: use '%s' or '%s'", ext, ".yaml", ".yml")
}

if _, err := os.Stat(configFile); os.IsNotExist(err) {
// File doesn't exist yet, create all necessary directories and
// write the default config file
if err := os.MkdirAll(filepath.Dir(configFile), 0o700); err != nil {
return err
}

f, err := os.Create(configFile)
if err != nil {
return err
}
defer func() { _ = f.Close() }()
func defaultConfigFile() string {
scope := gap.NewScope(gap.User, "glow")
path, _ := scope.ConfigPath("glow.yml")
return path
}

if _, err := f.WriteString(defaultConfig); err != nil {
return err
}
} else if err != nil { // some other error occurred
var configCmd = &cobra.Command{
Use: "config",
Hidden: false,
Short: "Edit the glow config file",
Long: paragraph(fmt.Sprintf("\n%s the glow config file. We’ll use EDITOR to determine which editor to use. If the config file doesn't exist, it will be created.", keyword("Edit"))),
Example: paragraph("glow config\nglow config --config path/to/config.yml"),
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {

Check warning on line 37 in config_cmd.go

View workflow job for this annotation

GitHub Actions / lint

unused-parameter: parameter 'cmd' seems to be unused, consider removing or renaming it as _ (revive)
if err := ensureConfigFile(); err != nil {
return err
}

c, err := editor.Cmd("Glow", configFile)
if err != nil {
return fmt.Errorf("could not edit %s: %w", configFile, err)
return err
}
c.Stdin = os.Stdin
c.Stdout = os.Stdout
Expand All @@ -80,3 +54,37 @@ var configCmd = &cobra.Command{
return nil
},
}

func ensureConfigFile() error {
if configFile == "" {
configFile = defaultConfigFile()
if err := os.MkdirAll(filepath.Dir(configFile), 0o755); err != nil {
return fmt.Errorf("Could not write config file: %w", err)
}
}

if ext := path.Ext(configFile); ext != ".yaml" && ext != ".yml" {
return fmt.Errorf("'%s' is not a supported config type: use '%s' or '%s'", ext, ".yaml", ".yml")
}

if _, err := os.Stat(configFile); os.IsNotExist(err) {
// File doesn't exist yet, create all necessary directories and
// write the default config file
if err := os.MkdirAll(filepath.Dir(configFile), 0o700); err != nil {
return err
}

f, err := os.Create(configFile)
if err != nil {
return err
}
defer func() { _ = f.Close() }()

if _, err := f.WriteString(defaultConfig); err != nil {
return err
}
} else if err != nil { // some other error occurred
return err
}
return nil
}
77 changes: 39 additions & 38 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,72 +1,73 @@
module github.com/charmbracelet/glow

go 1.17
go 1.21.4

require (
github.com/adrg/xdg v0.4.0
github.com/atotto/clipboard v0.1.4
github.com/charmbracelet/bubbles v0.15.0
github.com/charmbracelet/bubbletea v0.25.0
github.com/charmbracelet/charm v0.8.7
github.com/charmbracelet/glamour v0.6.0
github.com/charmbracelet/lipgloss v0.6.0
github.com/charmbracelet/x/editor v0.0.0-20231116172829-450eedbca1ab
github.com/caarlos0/env/v11 v11.0.1
github.com/charmbracelet/bubbles v0.18.0
github.com/charmbracelet/bubbletea v0.26.4
github.com/charmbracelet/glamour v0.6.1-0.20230519131405-7528eaad6620
github.com/charmbracelet/lipgloss v0.11.1-0.20240608174255-33b3263db7dd
github.com/charmbracelet/log v0.4.0
github.com/charmbracelet/x/editor v0.0.0-20240625164403-2627ec16405d
github.com/dustin/go-humanize v1.0.1
github.com/mattn/go-runewidth v0.0.15
github.com/meowgorithm/babyenv v1.3.1
github.com/mitchellh/go-homedir v1.1.0
github.com/muesli/gitcha v0.2.0
github.com/muesli/go-app-paths v0.2.2
github.com/muesli/reflow v0.3.0
github.com/muesli/termenv v0.15.2
github.com/sahilm/fuzzy v0.1.0
github.com/segmentio/ksuid v1.0.4
github.com/spf13/cobra v1.8.0
github.com/spf13/viper v1.14.0
golang.org/x/sys v0.17.0
golang.org/x/term v0.15.0
golang.org/x/text v0.14.0
github.com/sahilm/fuzzy v0.1.1
github.com/spf13/cobra v1.7.0
github.com/spf13/viper v1.15.0
golang.org/x/sys v0.21.0
golang.org/x/term v0.21.0
golang.org/x/text v0.16.0
)

require (
github.com/alecthomas/chroma v0.10.0 // indirect
github.com/alecthomas/chroma/v2 v2.8.0 // indirect
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/aymerick/douceur v0.2.0 // indirect
github.com/calmh/randomart v1.1.0 // indirect
github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81 // indirect
github.com/dgrijalva/jwt-go v3.2.0+incompatible // indirect
github.com/charmbracelet/x/ansi v0.1.2 // indirect
github.com/charmbracelet/x/input v0.1.2 // indirect
github.com/charmbracelet/x/term v0.1.1 // indirect
github.com/charmbracelet/x/windows v0.1.2 // indirect
github.com/dlclark/regexp2 v1.4.0 // indirect
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/go-logfmt/logfmt v0.6.0 // indirect
github.com/gorilla/css v1.0.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/magiconair/properties v1.8.6 // indirect
github.com/mattn/go-isatty v0.0.18 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-localereader v0.0.1 // indirect
github.com/microcosm-cc/bluemonday v1.0.21 // indirect
github.com/mikesmitty/edkey v0.0.0-20170222072505-3356ea4e686a // indirect
github.com/microcosm-cc/bluemonday v1.0.25 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/muesli/ansi v0.0.0-20211018074035-2e021307bc4b // indirect
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect
github.com/muesli/cancelreader v0.2.2 // indirect
github.com/muesli/sasquatch v0.0.0-20200811221207-66979d92330a // indirect
github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/pelletier/go-toml/v2 v2.0.5 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/pelletier/go-toml/v2 v2.0.6 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/rogpeppe/go-internal v1.12.0 // indirect
github.com/sabhiram/go-gitignore v0.0.0-20180611051255-d3107576ba94 // indirect
github.com/spf13/afero v1.9.2 // indirect
github.com/spf13/afero v1.9.3 // indirect
github.com/spf13/cast v1.5.0 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.4.1 // indirect
github.com/yuin/goldmark v1.5.2 // indirect
github.com/yuin/goldmark-emoji v1.0.1 // indirect
golang.org/x/crypto v0.17.0 // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/sync v0.1.0 // indirect
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
github.com/subosito/gotenv v1.4.2 // indirect
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
github.com/yuin/goldmark v1.5.4 // indirect
github.com/yuin/goldmark-emoji v1.0.2 // indirect
golang.org/x/exp v0.0.0-20240604190554-fc45aab8b7f8 // indirect
golang.org/x/net v0.26.0 // indirect
golang.org/x/sync v0.7.0 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit fce3edf

Please sign in to comment.