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

Feature request: locate config files on the folder where the executable is. #3136

Closed
hellishvictor opened this issue Feb 7, 2024 · 10 comments

Comments

@hellishvictor
Copy link

hellishvictor commented Feb 7, 2024

Hi, the program store its config files on %APPDATA%.config, and it would be awesome if were possible locate them (including the "buffers" folder) on the same folder where the program is, so this way it can be used as portable on a USB pendrive or whatever.

Cheers.

@Andriamanitra
Copy link
Contributor

You can already do this with micro -config-dir ..

@niten94
Copy link
Contributor

niten94 commented Feb 7, 2024

I cannot explain properly at this time but there is something said about %APPDATA% so I think Windows is used. The work directory (.) usually has to be changed manually when running and doing something with that directory.

There is this batch file I wrote hours ago but there are still things I have not checked so I do not think it would be fine using it yet:

@echo off
setlocal
set "pdir=%~dp0"
endlocal & "%pdir%micro.exe" -config-dir "%pdir:~0,-1%" %*

@hellishvictor
Copy link
Author

@echo off
set "pdir=%~dp0"

"%pdir%micro.exe" -config-dir "%pdir:~0,-1%" %*

Works without setlocal & endlocal. And using: echo "%CD%\micro.exe" -config-dir "%CD%" %* will achieve the same result. However, thank you very much for your help.

@hellishvictor
Copy link
Author

hellishvictor commented Feb 8, 2024

You can already do this with micro -config-dir ..

That's fine, thank you! Consider implement something like "if the config file not exist on this folder, then use/create the %LOCALAPPDATA% location", it will be more simple for the users than be including the " -config-dir ." all the time.Keep up the great work, micro is awesome!

@hellishvictor
Copy link
Author

\micro-2.0.13\internal\config\config.go
Line 28:

            xdgHome = filepath.Join(home, ".config")
        }

        microHome = filepath.Join(xdgHome, "micro")

Do I have to change the ".config" to "filepath" for specify the executable location or on the line 31 just:
microHome = filepath
?

@niten94
Copy link
Contributor

niten94 commented Feb 11, 2024

I do not think the code can be changed like you asked because filepath is something that is like a library in Go but line 31 can be changed with something like microHome = "path". The configuration directory is set as a directory in the XDG configuration directory (like C:\Users\user\.config by default in micro) in line 20-31 if MICRO_CONFIG_HOME is not set, so the path would be like path\micro if line 28 is changed with xdgHome = "path".

I think the lines can be replaced like this so that configuration files in the directory with the executable file only will be used if MICRO_CONFIG_HOME is not set:

	microHome := os.Getenv("MICRO_CONFIG_HOME")
	if microHome == "" {
		exe, err := os.Executable()
		if err != nil {
			return errors.New("Error getting path of executable\nCan't load config files: " + err.Error())
		}
		microHome = filepath.Dir(exe)
	}
	ConfigDir = microHome

@hellishvictor
Copy link
Author

Thank you very much for you help and for create this awesome tool :)
Cheers.

@hellishvictor
Copy link
Author

Hi, finally I got some time today and tried to build it, but with that modification it shows the following:

# github.com/zyedidia/micro/v2/internal/config
..\..\internal\config\config_original.go:11:5: ConfigDir redeclared in this block
        ..\..\internal\config\config.go:11:5: other declaration of ConfigDir
..\..\internal\config\config_original.go:15:6: InitConfigDir redeclared in this block
        ..\..\internal\config\config.go:15:6: other declaration of InitConfigDir
..\..\internal\config\config.go:8:2: "github.com/mitchellh/go-homedir" imported as homedir and not used

@niten94
Copy link
Contributor

niten94 commented May 22, 2024

I think there was an error when building because ConfigDir and InitConfigDir are declared in 2 files. I have not tested and I do not know why there was a message about go-homedir not being used, but I think config_original.go can be renamed as something like config_original.go.txt so that the file will not be included when building.

By the way, I do not know if you were thinking that I created micro but I am not the one that created it.

@hellishvictor
Copy link
Author

Ok, moving out the config_original.go, it showed:

# github.com/zyedidia/micro/v2/internal/config
..\..\internal\config\config.go:8:2: "github.com/mitchellh/go-homedir" imported as homedir and not used

So I removed that line from micro\internal\config\config.go, and it worked!
Thank you very much, man!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants