add original-path flag for list/restore/clean files in trash
This commit is contained in:
parent
dddc6f6d33
commit
4d929160d1
|
@ -77,7 +77,7 @@ func (is Infos) Show(width int) {
|
|||
fmt.Println(is.Table(width))
|
||||
}
|
||||
|
||||
func FindFiles(trashdir string, f *filter.Filter) (files Infos, outerr error) {
|
||||
func FindFiles(trashdir, ogdir string, f *filter.Filter) (files Infos, outerr error) {
|
||||
outerr = filepath.WalkDir(trashdir, func(path string, d fs.DirEntry, err error) error {
|
||||
if err != nil {
|
||||
log.Debugf("what happened?? what is %s?", err)
|
||||
|
@ -107,6 +107,10 @@ func FindFiles(trashdir string, f *filter.Filter) (files Infos, outerr error) {
|
|||
return err
|
||||
}
|
||||
|
||||
if ogdir != "" && filepath.Dir(basepath) != ogdir {
|
||||
return nil
|
||||
}
|
||||
|
||||
if f.Match(filename, date) {
|
||||
log.Debugf("%s: deleted on %s", filename, date.Format(trash_info_date_fmt))
|
||||
files = append(files, Info{
|
||||
|
|
35
main.go
35
main.go
|
@ -26,13 +26,13 @@ const (
|
|||
)
|
||||
|
||||
var (
|
||||
loglvl string
|
||||
f *filter.Filter
|
||||
o, b, a, g, p string
|
||||
ung, unp string
|
||||
workdir string
|
||||
recursive bool
|
||||
termwidth int
|
||||
loglvl string
|
||||
f *filter.Filter
|
||||
o, b, a, g, p string
|
||||
ung, unp string
|
||||
workdir, ogdir cli.Path
|
||||
recursive bool
|
||||
termwidth int
|
||||
|
||||
trashDir = filepath.Join(xdg.DataHome, "Trash")
|
||||
|
||||
|
@ -111,13 +111,13 @@ var (
|
|||
Name: "list",
|
||||
Aliases: []string{"ls"},
|
||||
Usage: "list trashed files",
|
||||
Flags: slices.Concat(filter_flags),
|
||||
Flags: slices.Concat(alreadyintrash_flags, filter_flags),
|
||||
Before: before_commands,
|
||||
Action: func(ctx *cli.Context) error {
|
||||
log.Debugf("searching in directory %s for files", trashDir)
|
||||
|
||||
// look for files
|
||||
files, err := trash.FindFiles(trashDir, f)
|
||||
files, err := trash.FindFiles(trashDir, ogdir, f)
|
||||
|
||||
var msg string
|
||||
if f.Blank() {
|
||||
|
@ -144,13 +144,13 @@ var (
|
|||
Name: "restore",
|
||||
Aliases: []string{"re"},
|
||||
Usage: "restore a trashed file or files",
|
||||
Flags: slices.Concat(filter_flags),
|
||||
Flags: slices.Concat(alreadyintrash_flags, filter_flags),
|
||||
Before: before_commands,
|
||||
Action: func(ctx *cli.Context) error {
|
||||
log.Debugf("searching in directory %s for files", trashDir)
|
||||
|
||||
// look for files
|
||||
files, err := trash.FindFiles(trashDir, f)
|
||||
files, err := trash.FindFiles(trashDir, ogdir, f)
|
||||
if len(files) == 0 {
|
||||
fmt.Println("no files to restore")
|
||||
return nil
|
||||
|
@ -178,10 +178,10 @@ var (
|
|||
Name: "clean",
|
||||
Aliases: []string{"cl"},
|
||||
Usage: "clean files from trash",
|
||||
Flags: slices.Concat(filter_flags),
|
||||
Flags: slices.Concat(alreadyintrash_flags, filter_flags),
|
||||
Before: before_commands,
|
||||
Action: func(ctx *cli.Context) error {
|
||||
files, err := trash.FindFiles(trashDir, f)
|
||||
files, err := trash.FindFiles(trashDir, ogdir, f)
|
||||
if len(files) == 0 {
|
||||
fmt.Println("no files to clean")
|
||||
return nil
|
||||
|
@ -276,6 +276,15 @@ var (
|
|||
Destination: &workdir,
|
||||
},
|
||||
}
|
||||
|
||||
alreadyintrash_flags = []cli.Flag{
|
||||
&cli.PathFlag{
|
||||
Name: "original-path",
|
||||
Usage: "restore files trashed from this `DIRECTORY`",
|
||||
Aliases: []string{"O"},
|
||||
Destination: &ogdir,
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
|
Loading…
Reference in a new issue