added ':delete' builtin command (#121)

* added ':delete' command

* fixed doc

* fixed typo

* added dummy function for delete for windows

* detacted the functionality from the OS

* now deletion works based on selections

* added effective selection

* delete no longer sends 'send sync'

* fixed typo

* fixed typo

* added DOC to effective selection

* added DOC to deleteFiles()

* fixed DOC typos

* added ability to overwrite :delete

* added ability to overwrite :delete
This commit is contained in:
Kallinteris Andreas authored and gokcehan committed 2018-12-29 20:14:20 +03:00
1 parent 3efdfd3bca
commit 7e3f92f049
6 files changed
+49

No files matched your search

+34
View File
@@ -550,6 +550,22 @@ func (nav *nav) unselect() {
nav.selectionInd = 0
}
// effectiveSelection is a pure function that returns the selected files's paths.
// In case the user has not selected a file it returns the file on the user's cursor.
// If the function can't return a selection it returns an error.
func (nav *nav) effectiveSelection() (list []string, err error) {
if len(nav.selections) == 0 {
curr, err := nav.currFile()
if err != nil {
return nil, errors.New("no file selected")
}
return []string{curr.path}, nil
}
return nav.currSelections(), nil
}
func (nav *nav) save(cp bool) error {
if len(nav.selections) == 0 {
curr, err := nav.currFile()
@@ -604,6 +620,24 @@ func (nav *nav) paste() error {
return nil
}
// deleteFiles deletes the user's selected files
// it returns an error if no files are selected or if the OS fails to delete a file
func (nav *nav) deleteFiles() error {
list, err := nav.effectiveSelection()
if err != nil {
return err
}
for _, path := range list {
if err := os.RemoveAll(path); err != nil {
return err
}
}
return nil
}
func (nav *nav) sync() error {
list, cp, err := loadFiles()
if err != nil {