oberblastmeister/trashy

Incorrect number of items shown through pipeing to `wc -l`

omernaveedxyz opened this issue · 0 comments

Problem
I am writing a script that first checks if the trash list is empty. My current implementation is trying to read the line count with $ trash list | wc -l, but the command incorrectly reports 1 for both an empty trash directory and one with a single item.

Resolution
$ trash list | wc -l should return different results if the directory is empty vs. contains a single item. Whether an empty directory reports 0 or a single directory reports 2, I am fine with either implementation.

Demonstration
$ cd Desktop
$ touch test
$ trash put test
$ trash list

╭───┬──────┬─────────────────────────╮
│ i │ Time │ Path                    │
├───┼──────┼─────────────────────────┤
│ 0 │ now  │ /home/omer/Desktop/test │
╰───┴──────┴─────────────────────────╯

$ trash list | wc -l

1

$ trash empty --all

1 item will be emptied
╭───┬────────────────┬─────────────────────────╮
│ i │ Time           │ Path                    │
├───┼────────────────┼─────────────────────────┤
│ 0 │ 11 seconds ago │ /home/omer/Desktop/test │
╰───┴────────────────┴─────────────────────────╯
Are you sure? yes

$ trash list

╭───┬──────┬──────╮
│ i │ Time │ Path │
╰───┴──────┴──────╯

$ trash list | wc -l

1