micro
micro copied to clipboard
Feature request: locate config files on the folder where the executable is.
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 problem is, so this way it can be used as portable on a USB pendrive or whatever.
Cheers.
You can already do this with micro -config-dir .
.
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%" %*
@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.
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!
\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
?
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
Thank you very much for you help and for create this awesome tool :) Cheers.
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
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.
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!