sindresorhus / trash-cli Goto Github PK
View Code? Open in Web Editor NEWMove files and folders to the trash
License: MIT License
Move files and folders to the trash
License: MIT License
When you trash asdf.txt
and asdf.txt
does not exist, no feedback is given to the user.
Is this planned to be so? Should there not be some message that informs the user the file he is trying to sent to the trashbin is not there?
When trying to trash a folder with any content (be it other folders or files) an error is thrown:
at ChildProcess.exithandler (child_process.js:303:12)
at ChildProcess.emit (events.js:321:20)
at maybeClose (internal/child_process.js:1026:16)
at Socket.<anonymous> (internal/child_process.js:441:11)
at Socket.emit (events.js:321:20)
at Pipe.<anonymous> (net.js:672:12)
I have checked and no process is currently using the folder or any files/folders within it.
I'm also able to trash files just fine, as well as folders that do not have any content.
My system:
OS: Windows 10 Home Version 1909 Build 18363
NodeJS: v13.9.0
trash-cli: 3.0.0
trash: 6.1.1
Env: PowerShell 6.2.4
The ability to specify a list of glob patterns which skip going to the trash
.trashignore
.DS_Store
node_modules
This would be beneficial as deleting node_modules from the trash can take a long time.
>trash build
Error: Command failed: (project_path)\node_modules\trash\lib\win-trash.exe (project_path)\build
at ChildProcess.exithandler (child_process.js:204:12)
at emitTwo (events.js:106:13)
at ChildProcess.emit (events.js:191:7)
at maybeClose (internal/child_process.js:886:16)
at Socket.<anonymous> (internal/child_process.js:342:11)
at emitOne (events.js:96:13)
at Socket.emit (events.js:188:7)
at Pipe._handle.close [as _onclose] (net.js:501:12)
npm ERR! Windows_NT 6.2.9200
npm ERR! argv "C:\Program Files\nodejs\node.exe" "C:\Program Files\nodejs\node_modules
\npm\bin\npm-cli.js" "run" "build"
npm ERR! node v6.10.1
npm ERR! npm v3.10.10
npm ERR! code ELIFECYCLE
npm ERR! (project_name)@0.0.1 build: trash build
npm ERR! Exit status 1
...
...
Seem --dot
option not supported yet?
Ubuntu 18.04.1 LTS on Windows 10 x86_64
Maybe something to do with WSL?
npm audit
shows a HIGH vulnerability in a dependency of trash-cli:
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ High │ Prototype Pollution │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package │ dot-prop │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in │ >=5.1.1 │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ trash-cli [dev] │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path │ trash-cli > update-notifier > configstore > dot-prop │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info │ https://npmjs.com/advisories/1213 │
└───────────────┴──────────────────────────────────────────────────────────────┘
Please consider updating and putting out a new release to resolve this.
How do I uninstall this?
windows-trash.exe
silently fails to remove files if the path is in a subst
virtual drive.windows-trash.exe
successfully removes the same files if the full, non-virtual drive paths are used.P:\tmp>subst
&REM Show subst virtual drive maping:
P:\: => V:\Insync\Dropbox\p
P:\tmp>windows-trash.exe FILE_TO_TRASH
&REM Running from virtual drive silently fails to remove file:
P:\tmp>dir
06/18/2023 12:15 AM 0 FILE_TO_TRASH
06/17/2023 11:10 PM 28,672 windows-trash.exe
P:\tmp>v:
&REM Switch to non-virtual drive.
V:\Insync\Dropbox\p\tmp>windows-trash.exe FILE_TO_TRASH
&REM Running from non-virtual drive successfully to removes file:
V:\Insync\Dropbox\p\tmp>dir
06/17/2023 11:10 PM 28,672 windows-trash.exe
I was trying to debug or workaround this error:
/p/tmp
$ trash FILE_TO_TRASH
Error: Command failed: V:\pnpm-home\global\5\.pnpm\[email protected]\node_modules\trash\lib\windows-trash.exe P:\tmp\FILE_TO_TRASH
at ChildProcess.exithandler (node:child_process:419:12)
at ChildProcess.emit (node:events:513:28)
at maybeClose (node:internal/child_process:1091:16)
at ChildProcess._handle.onexit (node:internal/child_process:302:5)
The error does not happen if not in a virtual drive:
/v/Insync/Dropbox/p/tmp
$ trash FILE_TO_TRASH
/v/Insync/Dropbox/p/tmp
$ ls
windows-trash.exe*
Also the error only occurs after trash-cli version 3.0.0. (So my workaround is to use version 2.0.0)
Environment:
Like restore -last
, restore -last=<n>
, n means the last nth file/folder removed to trash.
I recently updated my version of trash-cli, and I have been getting the following error:
/usr/local/lib/node_modules/trash-cli/node_modules/update-notifier/index.js:74
(async () => {
^
SyntaxError: Unexpected token (
at createScript (vm.js:56:10)
at Object.runInThisContext (vm.js:97:10)
at Module._compile (module.js:542:28)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/usr/local/lib/node_modules/trash-cli/cli.js:3:24)
I'm on npm version 6.9.0 - not sure if anyone else is seeing this.
Not sure if this an issue I should open with the update-notifier module or not
❯ npm install --global trash-cli
npm ERR! Darwin 16.4.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install" "--global" "trash-cli"
npm ERR! node v7.7.2
npm ERR! npm v4.1.2
npm ERR! Invalid name: "@sindresorhus/df"
npm ERR!
npm ERR! If you need help, you may report this error at:
npm ERR! <https://github.com/npm/npm/issues>
npm ERR! Please include the following file with any support request:
npm ERR! /Users/username/settings/npm-debug.log
Unless there's a distinction I do not understand, the Readme both advise aliasing rm
to trash
... and not doing it.
You should not alias rm to trash however as that would break most scripts relying on rm behavior.
Add alias rm=trash to your .zshrc/.bashrc to reduce typing & safely trash files: $ rm unicorn.png.
Running node 0.12.7 on OS X 10.10.5:
$ npm i --global trash-cli
npm WARN engine [email protected]: wanted: {"node":">=4"} (current: {"node":"0.12.7","npm":"2.11.3"})
/Users/hfp/.nvm/versions/node/v0.12.7/bin/trash -> /Users/hfp/.nvm/versions/node/v0.12.7/lib/node_modules/trash-cli/cli.js
[email protected] /Users/hfp/.nvm/versions/node/v0.12.7/lib/node_modules/trash-cli
├── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected])
├── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected])
└── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected])
$ trash .bash_profile
/Users/hfp/.nvm/versions/node/v0.12.7/lib/node_modules/trash-cli/cli.js:4
const updateNotifier = require('update-notifier');
^^^^^
SyntaxError: Use of const in strict mode.
at exports.runInThisContext (vm.js:73:16)
at Module._compile (module.js:443:25)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Function.Module.runMain (module.js:501:10)
at startup (node.js:129:16)
at node.js:814:3
Hello,
For some reason, when I invoke trash
, it reports an error like this. See: https://gist.github.com/sivabudh/7fc1d56d3cb283b193b9
When I did sudo trash
, then, it was okay.
I installed npm
via nvm
. See:
https://gist.github.com/0f1416b3337f54d0158d
sudo npm install --global trash-cli
npm WARN engine [email protected]: wanted: {"node":">=4"} (current: {"node":"0.10.37","npm":"1.4.28"})
npm WARN engine [email protected]: wanted: {"node":">=0.12.0","iojs":">=1.0.0"} (current: {"node":"0.10.37","npm":"1.4.28"})
npm ERR! 404 Not Found
npm ERR! 404
npm ERR! 404 'sindresorhus/df' is not in the npm registry.
npm ERR! 404 You should bug the author to publish it
npm ERR! 404 It was specified as a dependency of 'xdg-trashdir'
npm ERR! 404
npm ERR! 404 Note that you can also install from a
npm ERR! 404 tarball, folder, or http url, or git url.
npm ERR! System Linux 3.16.0-55-generic
npm ERR! command "/usr/bin/node" "/usr/bin/npm" "install" "--global" "trash-cli"
npm ERR! cwd /home/rakesh
npm ERR! node -v v0.10.37
npm ERR! npm -v 1.4.28
npm ERR! code E404
npm ERR! not ok code 0
Using zsh on kubuntu 16.04.
✘ ~ sudo npm install --global trash-cli
/usr/local/bin/trash -> /usr/local/lib/node_modules/trash-cli/cli.js
/usr/local/lib
`-- [email protected]
~ take new
~/new ..
~ trash new
/usr/bin/env: ‘node’: No such file or directory
~ touch hello
~ trash hello
/usr/bin/env: ‘node’: No such file or directory
Notes from my build:
Step #3: > trash build
Step #3:
Step #3: internal/modules/run_main.js:54
Step #3: internalBinding('errors').triggerUncaughtException(
Step #3: ^
Step #3:
Step #3: Error [ERR_UNSUPPORTED_ESM_URL_SCHEME]: Only file and data URLs are supported by the default ESM loader
Step #3: at Loader.defaultResolve [as _resolve] (internal/modules/esm/resolve.js:669:11)
Step #3: at Loader.resolve (internal/modules/esm/loader.js:97:40)
Step #3: at Loader.getModuleJob (internal/modules/esm/loader.js:243:28)
Step #3: at ModuleWrap. (internal/modules/esm/module_job.js:42:40)
Step #3: at link (internal/modules/esm/module_job.js:41:36) {
Step #3: code: 'ERR_UNSUPPORTED_ESM_URL_SCHEME'
Step #3: }
Step #3: npm ERR! code ELIFECYCLE
Step #3: npm ERR! errno 1
Step #3: npm ERR! @0.0.1 clean: trash build
Step #3: npm ERR! Exit status 1
Step #3: npm ERR!
In the readme.md
of this repository there's a reference to a file named unicorn.png
.
Considering that this tool (trash
) is amazing, simple logic tells us that the unicorn must also be amazing.
For purposes of:
please include the (amazing) unicorn.png
image file in this repository. Thank you.
On Ubuntu 20.04 I installed using sudo npm install --global trash-cli
but then running trash
gives:
Traceback (most recent call last):
File "/usr/local/bin/trash", line 4, in <module>
from trashcli.put import main as main
ImportError: No module named trashcli.put
Issue:
Some systems do not have the liberty to run/install node. This prevents being able to easily provision trash-cli on these systems.
Request
Update release flow to release compiled binaries.
This can be accomplished using npm's pkg (https://www.npmjs.com/package/pkg)
I'm on macOS 10.15.2
❯ sudo mkdir /Users/wow
❯ sudo mkdir /Users/wow
mkdir: /Users/wow: File exists # ✅
❯ trash /Users/wow
Error: Command failed: /usr/local/lib/node_modules/trash-cli/node_modules/trash/lib/macos-trash /Users/wow
“wow” couldn’t be moved to the trash because you don’t have permission to access it.
❯ sudo trash /Users/wow
Error: Command failed: /usr/local/lib/node_modules/trash-cli/node_modules/trash/lib/macos-trash /Users/wow
“wow” couldn’t be moved to the trash because you don’t have permission to access it.
❯ sudo rm -rf /Users/wow
❯ test -d /Users/wow || echo 'no folder'
no folder
I tried to delete all my node_modules
folders, but it seems like I hit some limit. Would it be possible to fix this by letting the trash-cli split up the expanded glob before performing the work?
❯ trash '**/node_modules'
Error: spawn E2BIG
at exports._errnoException (util.js:1012:11)
at ChildProcess.spawn (internal/child_process.js:302:11)
at exports.spawn (child_process.js:372:9)
at exports.execFile (child_process.js:139:15)
at /usr/local/lib/node_modules/trash-cli/node_modules/pify/index.js:29:7
at /usr/local/lib/node_modules/trash-cli/node_modules/pify/index.js:12:10
at ret (/usr/local/lib/node_modules/trash-cli/node_modules/pify/index.js:56:34)
at module.exports (/usr/local/lib/node_modules/trash-cli/node_modules/trash/lib/osx.js:37:32)
at module.exports (/usr/local/lib/node_modules/trash-cli/node_modules/trash/index.js:22:45)
at Object. (/usr/local/lib/node_modules/trash-cli/cli.js:27:1)
~/Devel 1m 49s
On mounted partition, when I trash $somedir$
, it just works fine as the $somedir$ is moved to my OS's home trash directory. But, a directory named .Trash is automatically generated in the path I executed the command. If I tried to trash .Trash
, it fails like the below.
This result happened on Ubuntu 18.04.
➜ SHARE trash .Trash
Alias tip: th .Trash
Traceback (most recent call last):
File "/usr/bin/trash", line 5, in <module>
sys.exit(main())
File "/usr/lib/python2.7/dist-packages/trashcli/cmds.py", line 10, in put
).run(sys.argv)
File "/usr/lib/python2.7/dist-packages/trashcli/trash.py", line 548, in run
self.trash_all(args)
File "/usr/lib/python2.7/dist-packages/trashcli/trash.py", line 557, in trash_all
self.trash(arg)
File "/usr/lib/python2.7/dist-packages/trashcli/trash.py", line 560, in trash
self.trashcan.trash(arg)
File "/usr/lib/python2.7/dist-packages/trashcli/trash.py", line 324, in trash
trashed_file = trash_dir.trash(file)
File "/usr/lib/python2.7/dist-packages/trashcli/trash.py", line 80, in trash
move(path, trashed_file.actual_path)
File "/usr/lib/python2.7/dist-packages/trashcli/fs.py", line 47, in move
return shutil.move(path, str(dest))
File "/usr/lib/python2.7/shutil.py", line 312, in move
raise Error, "Cannot move a directory '%s' into itself '%s'." % (src, dst)
shutil.Error: Cannot move a directory '.Trash' into itself '/media/user/SHARE/.Trash/1000/files/.Trash'.
It would be useful to have a flag for verbose mode.
$ trash -v unicorn.png rainbow.png
removed 'unicorn.png'
removed 'rainbow.png'
$ trash --help
Usage
$ trash [flags] <path|glob> [...]
Examples
$ trash unicorn.png rainbow.png
$ trash '*.png' '!unicorn.png'
$ trash -v unicorn.png rainbow.png
Running trash
or trash-put
on macOS Mojave (10.14.3) simply rm
s (hard-deletes) the file. It is not in the trash bin!
If I drag a file into trash, I can right click and choose put back.
However, if I use trash-cli, there is no put back option.
It seems that trash-cli do weird stuff with symlinks.
I have a Download folder on a separate partition, wich I symlinked to my home folder.
If I trash-put file
inside it, I am not able to restore the file with trash-restore
; neither from /home/user/Download nor /mountpoint/Download.
EDIT: it seems that I am unable to restore files trashed on this partition.
Hi @sindresorhus please be aware that the name you choose for the project can cause confusion in users as it is the same of my trash-cli project [1].
As a example I found this issue [2] in my trash-cli project
[1] https://github.com/andreafrancia/trash-cli
[2] andreafrancia/trash-cli#155
Inside the README it says:
Add alias
rm=trash
to your .zshrc/.bashrc to reduce typing & safely trash files
But the in your rm is dangerous guide you wrote:
You should no alias rm to trash as it will break external scripts relying on the behavior of rm. Instead use it directly
https://github.com/sindresorhus/guides/blob/master/how-not-to-rm-yourself.md#safeguard-rm
One of them needs updating? :)
When I delete files via Finder, then the deleted files in Trash have a helpful "Put Back" context menu entry. Files deleted via trash
do not have this. It would be really nice if that was available as well.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.