Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ryboe/q
Quick and dirty debugging output for tired Go programmers
https://github.com/ryboe/q
debugger go golang
Last synced: about 1 month ago
JSON representation
Quick and dirty debugging output for tired Go programmers
- Host: GitHub
- URL: https://github.com/ryboe/q
- Owner: ryboe
- License: mit
- Created: 2016-02-07T21:57:59.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2024-02-25T19:31:42.000Z (10 months ago)
- Last Synced: 2024-04-22T22:21:37.720Z (8 months ago)
- Topics: debugger, go, golang
- Language: Go
- Homepage:
- Size: 6.22 MB
- Stars: 1,516
- Watchers: 21
- Forks: 85
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
- my-awesome - ryboe/q - 11 star:1.5k fork:0.1k Quick and dirty debugging output for tired Go programmers (Go)
- awesome-ccamel - ryboe/q - Quick and dirty debugging output for tired Go programmers (Go)
- awesome-golang-repositories - q
- awesome-discoveries - q - simply debug print _(`Go`)_ (Libraries)
README
# q
[![Go Report Card](https://goreportcard.com/badge/github.com/ryboe/q)](https://goreportcard.com/report/github.com/ryboe/q)
[![PkgGoDev](https://pkg.go.dev/badge/github.com/ryboe/q)](https://pkg.go.dev/github.com/ryboe/q)q is a better way to do print statement debugging.
Type `q.Q` instead of `fmt.Printf` and your variables will be printed like this:
![q output examples](https://i.imgur.com/OFmm7pb.png)
## Why is this better than `fmt.Printf`?
* Faster to type
* Pretty-printed vars and expressions
* Easier to see inside structs
* Doesn't go to noisy-ass stdout. It goes to `$TMPDIR/q`.
* Pretty colors!## Basic Usage
```go
import "q"
...
q.Q(a, b, c)
```For best results, dedicate a terminal to tailing `$TMPDIR/q` while you work.
## Install
```sh
git clone https://github.com/ryboe/q "$(go env GOPATH)"/src/q
```Put these functions in your shell config. Typing `qq` or `rmqq` will then start
tailing `$TMPDIR/q`.```sh
qq() {
clearlogpath="$TMPDIR/q"
if [[ -z "$TMPDIR" ]]; then
logpath="/tmp/q"
fiif [[ ! -f "$logpath" ]]; then
echo 'Q LOG' > "$logpath"
fitail -100f -- "$logpath"
}rmqq() {
logpath="$TMPDIR/q"
if [[ -z "$TMPDIR" ]]; then
logpath="/tmp/q"
fi
if [[ -f "$logpath" ]]; then
rm "$logpath"
fi
}
```You also can simply `tail -f $TMPDIR/q`, but it's highly recommended to use the above commands.
## Editor Integration
### VS Code
`Preferences > User Snippets > Go`
```json
"qq": {
"prefix": "qq",
"body": "q.Q($1) // DEBUG",
"description": "Pretty-print to $TMPDIR/q"
}
```### Sublime Text
`Tools > Developer > New Snippet`
```xml
source.go```
### Atom
`Atom > Open Your Snippets`
```coffee
'.source.go':
'qq':
'prefix': 'qq'
'body': 'q.Q($1) // DEBUG'
```### JetBrains GoLand
`Settings > Editor > Live Templates`
In `Go`, add a new template with:
* Abbreviation: `qq`
* Description: `Pretty-print to $TMPDIR/q`
* Template text: `q.Q($END$) // DEBUG`
* Applicable in: select the `Go` scope### Emacs
Add a new snippet file to the go-mode snippets directory
(`$HOME/.emacs.d/snippets/go-mode/qq`). This should
contain:```emacs
# -*- mode: snippet -*-
# name: qq
# key: qq
# --
q.Q(${1:...}) // DEBUG
```### Vim/NeoVim
For [SirVer/ultisnips](https://github.com/SirVer/ultisnips), use `:UltiSnipsEdit` to add the new snippet:
```snippets
snippet qq "qq"
q.Q(${1:})
${2}
endsnippet
```## Haven't I seen this somewhere before?
Python programmers will recognize this as a Golang port of the
[`q` module by zestyping](https://github.com/zestyping/q).Ping does a great job of explaining `q` in his awesome lightning talk from
PyCon 2013. Watch it! It's funny :)[![ping's PyCon 2013 lightning talk](https://i.imgur.com/7KmWvtG.jpg)](https://youtu.be/OL3De8BAhME?t=25m14s)
## FAQ
### Why `q.Q`?
It's quick to type and unlikely to cause naming collisions.
### Is `q.Q()` safe for concurrent use?
Yes.