This project is heavily influenced by trash-cli, but it makes use of the power of fzf and add other functionality making listing and restoring trashed files and directories particularly easy.
- works from any mount point and with root privilege if necessary
- is compliant with the FreeDesktop.org Trash specification
- creates trash directories automatically when required
- sends files/directories to trash
- easily allows to:
- inspect the trash content
- restore trashed files/directories
- empty the trash fully, or selectively based on cutoff date, pattern, specific files, specific dates, etc.
- fzf allows incremental search to find trashed files/directories very easily from pattern, name, path, or date
- files are listed chronologically (in reverse chronological order so that the last deleted file/directory is the easiest to access)
- trashed directories are identified with a “D” to distinguish them from trashed files
- all files in the trash are listed, even if their meta data is missing for whatever reason
- it is possible to list and restore only the files which were trashed from the current directory (trash-cli’s behaviour), but it is also possible to list all files/directories in the trash and restore any of them from any directory
- trashed files can be previewed with fzf with syntax highlighting
- in case of a conflict between a new file and a restored trashed file, instead of exiting with error (trash-cli’s behaviour), tra.sh will restore the file and turn the already existing file into a backup file with the suffix
~conflict-with-restored-file
- while trash-cli’s
trash-empty
delete files from all the trashes of all mount points (except for the root trash which requiressudo trash-empty
), tra.sh will empty only the trash of the current mount point. This prevents the accidental deletion of files in the trash of an external drive when cleaning the user’s trash, or reciprocally, the deletion of files in the user’s trash when cleaning an external drive’s trash - multiple files/directories can be selected to be restored or cleaned from the trash at once
- trash-cli’s
trash-rm
allows to remove all files/directories matching a pattern from the trash. But you have to trust that your pattern is correct as you do not get to see what will get removed (or not). tra.sh, thanks to fzf, allows to see what gets selected by a certain pattern before removing the selection from the trash. The pattern can be applied to the files/directories’ paths but also on their deletion dates since both are submitted to fzf - files/directories matching a pattern can be restored (with the on-the-fly feed-back of fzf described above)
These scripts require fzf.
They are written on linux for zsh. Known incompatibilities:
- with other shells: the
/*(D)
notation (to include dot files) is zsh specific - with other OS:
date -d
requires GNU date, which is not the default on macOS
I would welcome contributions to make the project portable to other shells and other OS.
Simply clone this repository or download these scripts in your $PATH
.
Simply run any of the scripts from the command line (or from ranger, rofi, or your usual way to run commands).
You might want to set aliases (in your .zshrc
file, or alias.zsh
file, or .bashrc
file, or wherever you normally define shell aliases). That way, you only have to call the alias to run the corresponding script.
Below are suggested aliases and a summary table of all the commands using those aliases. If you set up those aliases, all you have to run is what is in the column “alias”.
Command | Option | Alias | Alias explanation |
---|---|---|---|
Send to trash | |||
ts | “trash send” | ||
List trash content | |||
entire trash from current mountpoint | tls | “trash list” | |
only files/dirs trashed from current directory | tld | “trash list directory” | |
entire trash from current mountpoint, with preview | tlp | “trash list preview” | |
only files/dirs trashed from current dir, with preview | tlb | “trash list both” | |
Restore from trash | |||
entire trash from current mountpoint | trs | “trash restore” | |
only files/dirs trashed from current directory | trd | “trash restore directory” | |
entire trash from current mountpoint, with preview | trp | “trash restore preview” | |
only files/dirs trashed from current dir, with preview | trb | “trash restore both” | |
Delete from trash | |||
entire trash from current mountpoint | tdl | “trash delete” | |
only files/dirs trashed from current directory | tdd | “trash delete directory” | |
entire trash from current mountpoint, with preview | tdp | “trash delete preview” | |
only files/dirs trashed from current dir, with preview | tdb | “trash delete both” | |
Clean trash | |||
entire trash from current mountpoint | tcl | “trash clean” | |
same, for files/dirs trashed up to (including) <n> days | tcd <n> | “trash clean date” |
Notes:
- “both” stands for “both from current directory and with preview”
- Replace
<n>
by an integer representing the number of days - Multi selections are possible with <tab>, select/unselect all with <ctrl-o>
alias ts='zsh <path-to-tra.sh>/tra_sd.sh'
- all
alias tls='zsh <path-to-tra.sh>/tra_ls.sh'
- only those trashed from the current directory
alias tld='zsh <path-to-tra.sh>/tra_ls_dir.sh'
- all, with preview
alias tlp='zsh <path-to-tra.sh>/tra_ls_p.sh'
- only those trashed from the current directory, with preview
alias tlb='zsh <path-to-tra.sh>/tra_ls_dir_p.sh' # b for 'both' directory and preview
Multiple files can be selected/unselected with the <tab> key (and <shift-tab> to move upward) in the fzf drop-down list.
To restore files/directories matching a pattern, type the pattern in the fzf search, then select/unselect all with the <ctrl-o> key (the key can be customized in the tra_rs scripts if needed). The pattern can be based on the path, the file name, and/or the deletion date.
- any
alias trs='zsh <path-to-tra.sh>/tra_rs.sh'
- only those trashed from current directory
alias trd='zsh <path-to-tra.sh>/tra_rs_dir.sh'
- any, with preview
alias trp='zsh <path-to-tra.sh>/tra_rs_p.sh'
- only those trashed from current directory, with preview
alias trb='zsh <path-to-tra.sh>/tra_rs_dir_p.sh' # b for 'both' directory and preview
As with the restore scripts, multiple files can be selected/unselected with the <tab> key. And to select files/directories matching a pattern for deletion, the pattern can be searched with fzf and all files selected/unselected with the <ctrl-o> key.
- any
alias tdl='zsh <path-to-tra.sh>/tra_dl.sh'
- only those trashed from current directory
alias tdd='zsh <path-to-tra.sh>/tra_dl_dir.sh'
- any, with preview
alias tdp='zsh <path-to-tra.sh>/tra_dl_p.sh'
- only those trashed from current directory, with preview
alias tdb='zsh <path-to-tra.sh>/tra_dl_dir_p.sh' # b for 'both' directory and preview
- permanently delete all files/directories in the trash from current mount point (other trashes untouched)
alias tcl='zsh <path-to-tra.sh>/tra_cl.sh'
- only delete files/directories in the trash which are n days old or older
alias tcd='zsh <path-to-tra.sh>/tra_cl_date.sh'
# Add the number of days after this command
# For example, in order to delete all files/directories 3 days old or older, type:
# tcld 3