github.com/cockroachdb/tools@v0.0.0-20230222021103-a6d27438930d/cmd/getgo/system_unix.go (about)

     1  // Copyright 2017 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  //go:build aix || darwin || dragonfly || freebsd || linux || nacl || netbsd || openbsd || solaris
     6  // +build aix darwin dragonfly freebsd linux nacl netbsd openbsd solaris
     7  
     8  package main
     9  
    10  import (
    11  	"context"
    12  	"fmt"
    13  	"os"
    14  	"path/filepath"
    15  )
    16  
    17  const (
    18  	envSeparator = ":"
    19  	homeKey      = "HOME"
    20  	lineEnding   = "\n"
    21  	pathVar      = "$PATH"
    22  )
    23  
    24  var installPath = func() string {
    25  	home, err := getHomeDir()
    26  	if err != nil {
    27  		return "/usr/local/go"
    28  	}
    29  
    30  	return filepath.Join(home, ".go")
    31  }()
    32  
    33  func whichGo(ctx context.Context) (string, error) {
    34  	return findGo(ctx, "which")
    35  }
    36  
    37  func isWindowsXP() bool {
    38  	return false
    39  }
    40  
    41  func currentShell() string {
    42  	return os.Getenv("SHELL")
    43  }
    44  
    45  func persistEnvChangesForSession() error {
    46  	shellConfig, err := shellConfigFile()
    47  	if err != nil {
    48  		return err
    49  	}
    50  	fmt.Println()
    51  	fmt.Printf("One more thing! Run `source %s` to persist the\n", shellConfig)
    52  	fmt.Println("new environment variables to your current session, or open a")
    53  	fmt.Println("new shell prompt.")
    54  
    55  	return nil
    56  }