Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

支持环境变量G_HOME自定义g目录 #18

Closed
voidint opened this issue Jun 15, 2019 · 8 comments
Closed

支持环境变量G_HOME自定义g目录 #18

voidint opened this issue Jun 15, 2019 · 8 comments
Labels
help wanted Extra attention is needed

Comments

@voidint
Copy link
Owner

voidint commented Jun 15, 2019

  • 优先读取环境变量G_HOME
  • 若环境变量G_HOME值为空,则读取默认路径~/.g
@voidint voidint added the enhancement New feature or request label Jul 14, 2019
@voidint voidint changed the title 支持自定义g根目录 支持环境变量G_HOME自定义g目录 Jul 14, 2019
@voidint
Copy link
Owner Author

voidint commented Jul 14, 2019

// ghome 返回g根目录
func ghome() (dir string) {
	if dir = os.Getenv("G_HOME"); dir != "" {
		return dir
	}
	homeDir, _ := os.UserHomeDir()
	return filepath.Join(homeDir, ".g")
}

@voidint voidint added help wanted Extra attention is needed and removed enhancement New feature or request labels Jul 14, 2019
@voidint
Copy link
Owner Author

voidint commented Jul 14, 2019

  • 问题一:通过环境变量切换到非默认的G家目录后,需要手动变更环境变量GOROOTPATH等,因为这类环境变量的值还是指向的变更前的G家目录(我并不打算由g去修改.bashrc),也就是说这是一种非全自动化的切换,不够完美。

  • 问题二:由于g需要对G_HOME指向的目录拥有读写权限,这势必会导致有人使用sudo g的方式运行程序,而这种情况下原来的环境变量将丢失(sudo默认并不会继承所有环境变量),这会使得体验变差。

@alpha-baby
Copy link

  • 问题一:通过环境变量切换到非默认的G家目录后,需要手动变更环境变量GOROOTPATH等,因为这类环境变量的值还是指向的变更前的G家目录(我并不打算由g去修改.bashrc),也就是说这是一种非全自动化的切换,不够完美。
  • 问题二:由于g需要对G_HOME指向的目录拥有读写权限,这势必会导致有人使用sudo g的方式运行程序,而这种情况下原来的环境变量将丢失(sudo默认并不会继承原环境变量),这会使得体验变差。

同感

@voidint
Copy link
Owner Author

voidint commented Jan 4, 2021

  • 自定义g目录需求比较普遍,但是起码存在着上文中提及的两个主要问题且暂时没有很好的解决方案。因此,对于这类不成熟的特性,比较合适的做法是将其归类到实验特性中(许多软件都有实验特性,如Chrome)。
  • 既然要将自定义g目录纳入到实验特性中,那么如何开启实验特性?参考docker的做法,引入名为G_EXPERIMENTAL的环境变量,即G_EXPERIMENTAL=true时开启实验特性,此时G_HOME才会生效。
const (
	experimentalEnv = "G_EXPERIMENTAL"
	homeEnv         = "G_HOME"
)

func ghome() (dir string) {
	if experimental := os.Getenv(experimentalEnv); experimental == "true" {
		if dir = os.Getenv(homeEnv); dir != "" {
			return dir
		}
	}
	homeDir, _ := os.UserHomeDir()
	return filepath.Join(homeDir, ".g")
}

voidint added a commit that referenced this issue Jan 4, 2021
@chawyehsu
Copy link

这样设计很奇怪不是么,g 默认安装下是不会设置 G_HOME 的,也就是说用户默认就是用 ~/.g 作为 g 目录。而要自定义 g 目录的用户,必然会手动设置 G_HOME,也会自行修改 PATH 等设置,也清楚自己设置的 G_HOME 是否要权限。

多弄一个 G_EXPERIMENTAL 来”避免“用户考虑到的问题,有点多此一举。

@alpha-baby
Copy link

这样设计很奇怪不是么,g 默认安装下是不会设置 G_HOME 的,也就是说用户默认就是用 ~/.g 作为 g 目录。而要自定义 g 目录的用户,必然会手动设置 G_HOME,也会自行修改 PATH 等设置,也清楚自己设置的 G_HOME 是否要权限。

多弄一个 G_EXPERIMENTAL 来”避免“用户考虑到的问题,有点多此一举。

我也觉得有点多余

@NeptuneNeptune
Copy link

环境变量明明设置了,为啥不管用啊,还是装在C盘的默认目录;用的1.2版本,G_HOME和G_EXXXXXX也配置了

@voidint
Copy link
Owner Author

voidint commented May 27, 2021

环境变量明明设置了,为啥不管用啊,还是装在C盘的默认目录;用的1.2版本,G_HOME和G_EXXXXXX也配置了

1.2.0版本中并不包含这个特性,可以拉取master分支自己编译一个。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

4 participants