// Set the terminal title func main() { opts := mainOpts{} flag.StringVar(&opts.Auto, "a", "", "screen or xterm title") flag.StringVar(&opts.Raw, "r", "", "raw title") flag.StringVar(&opts.Screen, "s", "", "screen title") flag.StringVar(&opts.ScreenTTY, "S", "", "screen title via /dev/tty") flag.StringVar(&opts.Xterm, "x", "", "xterm title") flag.Parse() dev := termtitle.New() if len(opts.Auto) == 0 { opts.Auto = strings.Join(flag.Args(), " ") } if len(opts.Auto) > 0 { format := termtitle.GuessFormat(os.Getenv("TERM")) dev.PrintFormatted(opts.Auto, format) } if len(opts.Screen) > 0 { dev.PrintFormatted(opts.Screen, "screen") } if len(opts.Raw) > 0 { dev.PrintFormatted(opts.Raw, "raw") } if len(opts.Xterm) > 0 { dev.PrintFormatted(opts.Xterm, "xterm") } if len(opts.ScreenTTY) > 0 { dev = termtitle.New() if fd, err := open("/dev/tty"); err == nil { dev.Writer = fd dev.PrintFormatted(opts.ScreenTTY, "screen") } } }
// Print title to terminal. func (config *Config) PrintTitle(title string) error { format := termtitle.GuessFormat(os.Getenv("TERM")) dev := termtitle.New() return dev.PrintFormatted(title, format) }