mirror of
https://github.com/akiyosi/goneovim.git
synced 2025-08-29 22:19:33 +02:00
Fix to set the application CWD to the HOME directory (#122)
This commit is contained in:
parent
2c24538941
commit
2307784a46
3 changed files with 30 additions and 13 deletions
|
@ -11,6 +11,7 @@ import (
|
|||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/akiyosi/goneovim/util"
|
||||
frameless "github.com/akiyosi/goqtframelesswindow"
|
||||
clipb "github.com/atotto/clipboard"
|
||||
"github.com/jessevdk/go-flags"
|
||||
|
@ -188,6 +189,19 @@ func InitEditor() {
|
|||
e.cleanup()
|
||||
})
|
||||
|
||||
// Set the current working directory of the application to the HOME directory.
|
||||
// If this process is not executed, CWD is set to the root directory, and
|
||||
// nvim plugins called as descendants of the application will not work due to lack of permission.
|
||||
// e.g. #122
|
||||
path := core.QCoreApplication_ApplicationDirPath()
|
||||
absHome, err := util.ExpandTildeToHomeDirectory(home)
|
||||
if err == nil {
|
||||
if path != absHome {
|
||||
qdir := core.NewQDir2(path)
|
||||
qdir.SetCurrent(absHome)
|
||||
}
|
||||
}
|
||||
|
||||
e.initFont()
|
||||
e.initSVGS()
|
||||
e.initColorPalette()
|
||||
|
|
|
@ -308,7 +308,7 @@ func (s *Fuzzy) processSource() {
|
|||
if !ok {
|
||||
s.pwd = ""
|
||||
}
|
||||
path, err := expand(s.pwd)
|
||||
path, err := gonvimUtil.ExpandTildeToHomeDirectory(s.pwd)
|
||||
if err == nil {
|
||||
s.pwd = path
|
||||
}
|
||||
|
@ -326,7 +326,7 @@ func (s *Fuzzy) processSource() {
|
|||
if !ok {
|
||||
dir = ""
|
||||
}
|
||||
path, err := expand(dir)
|
||||
path, err := gonvimUtil.ExpandTildeToHomeDirectory(dir)
|
||||
if err == nil {
|
||||
dir = path
|
||||
}
|
||||
|
@ -765,14 +765,3 @@ func insertAtIndex(in string, i int, newChar string) string {
|
|||
// return int(iface.(uint64))
|
||||
// }
|
||||
|
||||
func expand(path string) (string, error) {
|
||||
if len(path) == 0 || path[0] != '~' {
|
||||
return path, nil
|
||||
}
|
||||
|
||||
usr, err := user.Current()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return filepath.Join(usr.HomeDir, path[1:]), nil
|
||||
}
|
||||
|
|
|
@ -2,6 +2,8 @@ package util
|
|||
|
||||
import (
|
||||
"strings"
|
||||
"os/user"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/therecipe/qt/core"
|
||||
"github.com/therecipe/qt/gui"
|
||||
|
@ -268,3 +270,15 @@ func NewVFlowLayout(spacing int, padding int, paddingTop int, rightIdex int, wid
|
|||
})
|
||||
return layout
|
||||
}
|
||||
|
||||
func ExpandTildeToHomeDirectory(path string) (string, error) {
|
||||
if len(path) == 0 || path[0] != '~' {
|
||||
return path, nil
|
||||
}
|
||||
|
||||
usr, err := user.Current()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return filepath.Join(usr.HomeDir, path[1:]), nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue