trash command: if args are existing files, don't find files based on filter, just trash args
This commit is contained in:
parent
7fdb8052c4
commit
379428509c
2 changed files with 60 additions and 10 deletions
|
@ -10,6 +10,7 @@ import (
|
|||
|
||||
"git.burning.moe/celediel/gt/internal/filter"
|
||||
"github.com/charmbracelet/log"
|
||||
"github.com/dustin/go-humanize"
|
||||
)
|
||||
|
||||
type File struct {
|
||||
|
@ -28,6 +29,33 @@ func (f File) Modified() time.Time { return f.modified }
|
|||
func (f File) Filesize() int64 { return f.filesize }
|
||||
func (f File) IsDir() bool { return f.isdir }
|
||||
|
||||
func New(path string) (File, error) {
|
||||
info, err := os.Stat(path)
|
||||
if err != nil {
|
||||
return File{}, err
|
||||
}
|
||||
|
||||
abs, err := filepath.Abs(path)
|
||||
if err != nil {
|
||||
log.Errorf("couldn't get absolute path for %s", path)
|
||||
abs = path
|
||||
}
|
||||
|
||||
name := filepath.Base(abs)
|
||||
base_path := filepath.Dir(abs)
|
||||
|
||||
log.Debugf("%s (base:%s) (size:%s) (modified:%s) exists",
|
||||
name, base_path, humanize.Bytes(uint64(info.Size())), info.ModTime())
|
||||
|
||||
return File{
|
||||
name: name,
|
||||
path: base_path,
|
||||
filesize: info.Size(),
|
||||
modified: info.ModTime(),
|
||||
isdir: info.IsDir(),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func Find(dir string, recursive bool, f *filter.Filter) (files Files, err error) {
|
||||
if dir == "." || dir == "" {
|
||||
var d string
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue