Only replace '~' with home if at start of path

Ref #757
This commit is contained in:
Zachary Yedidia
2017-09-23 20:56:08 -04:00
parent 5a7ddb8330
commit 12a4dd58f3
5 changed files with 23 additions and 22 deletions

View File

@@ -14,7 +14,6 @@ import (
"strings"
humanize "github.com/dustin/go-humanize"
"github.com/mitchellh/go-homedir"
)
// A Command contains a action (a function to call) as well as information about how to autocomplete the command
@@ -230,8 +229,7 @@ func TabSwitch(args []string) {
// Cd changes the current working directory
func Cd(args []string) {
if len(args) > 0 {
home, _ := homedir.Dir()
path := strings.Replace(args[0], "~", home, 1)
path := ReplaceHome(args[0])
os.Chdir(path)
for _, tab := range tabs {
for _, view := range tab.views {
@@ -325,8 +323,7 @@ func VSplit(args []string) {
CurView().VSplit(NewBufferFromString("", ""))
} else {
filename := args[0]
home, _ := homedir.Dir()
filename = strings.Replace(filename, "~", home, 1)
filename = ReplaceHome(filename)
file, err := os.Open(filename)
fileInfo, _ := os.Stat(filename)
@@ -355,8 +352,7 @@ func HSplit(args []string) {
CurView().HSplit(NewBufferFromString("", ""))
} else {
filename := args[0]
home, _ := homedir.Dir()
filename = strings.Replace(filename, "~", home, 1)
filename = ReplaceHome(filename)
file, err := os.Open(filename)
fileInfo, _ := os.Stat(filename)
@@ -396,8 +392,7 @@ func NewTab(args []string) {
CurView().AddTab(true)
} else {
filename := args[0]
home, _ := homedir.Dir()
filename = strings.Replace(filename, "~", home, 1)
filename = ReplaceHome(filename)
file, err := os.Open(filename)
fileInfo, _ := os.Stat(filename)