Skip to content

Commit

Permalink
Merge pull request #14 from vasyahacker/fix-macos-tmux
Browse files Browse the repository at this point in the history
tmux mode fix for MacOS
  • Loading branch information
anmitsu authored Nov 29, 2021
2 parents c7404e5 + e325fff commit 7aa60a3
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,17 @@ import (
)

func main() {
is_tmux := false
widget.Init()
defer widget.Fini()

if runtime.GOOS == "darwin" {
is_tmux = strings.Contains(os.Getenv("TERM_PROGRAM"), "tmux")
} else {
is_tmux = strings.Contains(os.Getenv("TERM"), "screen")
}
// Change a terminal title.
if strings.Contains(os.Getenv("TERM"), "screen") {
if is_tmux {
os.Stdout.WriteString("\033kgoful\033") // for tmux
} else {
os.Stdout.WriteString("\033]0;goful\007") // for otherwise
Expand All @@ -30,7 +36,7 @@ func main() {
const history = "~/.goful/history/shell"

goful := app.NewGoful(state)
config(goful)
config(goful, is_tmux)
_ = cmdline.LoadHistory(history)

goful.Run()
Expand All @@ -39,7 +45,7 @@ func main() {
_ = cmdline.SaveHistory(history)
}

func config(g *app.Goful) {
func config(g *app.Goful, is_tmux bool) {
look.Set("default") // default, midnight, black, white

if runewidth.EastAsianWidth {
Expand Down Expand Up @@ -114,7 +120,7 @@ func config(g *app.Goful) {
// for not close the terminal when the shell finishes running
const tail = `;read -p "HIT ENTER KEY"`

if strings.Contains(os.Getenv("TERM"), "screen") { // such as screen and tmux
if is_tmux { // such as screen and tmux
return []string{"tmux", "new-window", "-n", cmd, cmd + tail}
}
// To execute bash in gnome-terminal of a new window or tab.
Expand Down

0 comments on commit 7aa60a3

Please sign in to comment.