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

@@ -16,7 +16,6 @@ import (
"time"
"unicode/utf8"
"github.com/mitchellh/go-homedir"
"github.com/zyedidia/micro/cmd/micro/highlight"
)
@@ -385,7 +384,6 @@ func (b *Buffer) Serialize() error {
// SaveAs saves the buffer to a specified path (filename), creating the file if it does not exist
func (b *Buffer) SaveAs(filename string) error {
b.UpdateRules()
dir, _ := homedir.Dir()
if b.Settings["rmtrailingws"].(bool) {
r, _ := regexp.Compile(`[ \t]+$`)
for lineNum, line := range b.Lines(0, b.NumLines) {
@@ -408,7 +406,7 @@ func (b *Buffer) SaveAs(filename string) error {
data := []byte(str)
err := ioutil.WriteFile(filename, data, 0644)
if err == nil {
b.Path = strings.Replace(filename, "~", dir, 1)
b.Path = ReplaceHome(filename)
b.IsModified = false
b.ModTime, _ = GetModTime(filename)
return b.Serialize()