Skip to content

Instantly share code, notes, and snippets.

@rigelrozanski
Created April 30, 2020 03:55
Show Gist options
  • Save rigelrozanski/da05a6f274b85fab88681551869a4be8 to your computer and use it in GitHub Desktop.
Save rigelrozanski/da05a6f274b85fab88681551869a4be8 to your computer and use it in GitHub Desktop.
Iterm2 imgcat image output from golang
import (
"encoding/base64"
"fmt"
"io/ioutil"
"os"
)
func main() {
r, err := os.Open("yourimagehere.png")
if err != nil {
panic(fmt.Sprintf("debug err: %v\n", err))
}
bz, err := ioutil.ReadAll(r)
if err != nil {
panic(fmt.Sprintf("debug err: %v\n", err))
}
fmt.Printf("\033]1337;File=;inline=1:%s\a\n", base64.StdEncoding.EncodeToString(bz))
}
// for more complex implementations checkout these repos:
// https://github.com/martinlindhe/imgcat/blob/master/lib/imgcat.go#L43
// https://github.com/olivere/iterm2-imagetools/blob/master/cmd/imgcat/imgcat.go
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment