2024-01-01 18:30:46 +01:00
|
|
|
# Do not use this script, this is slow and it's not moving files to the
|
|
|
|
# windows recycle bin since it's impossible from WSL
|
|
|
|
|
2024-01-01 18:07:07 +01:00
|
|
|
function trash --description "Move file or directory to the windows recycle bin."
|
|
|
|
# Get function name
|
|
|
|
set current_name $(status current-function)
|
|
|
|
|
|
|
|
# Check if no arguments were provided
|
|
|
|
if test -z $argv[1]
|
|
|
|
echo -e "Usage: $current_name path/to/file"
|
|
|
|
return 0
|
|
|
|
end
|
|
|
|
|
|
|
|
# Move file to trash
|
2024-01-01 18:26:56 +01:00
|
|
|
set file (wslpath -w $argv[1])
|
2024-01-01 18:07:07 +01:00
|
|
|
powershell.exe -Command "& {" \
|
|
|
|
" Add-Type -AssemblyName 'Microsoft.VisualBasic';" \
|
2024-01-01 18:08:46 +01:00
|
|
|
" Get-ChildItem -Path '$file' | ForEach-Object {" \
|
|
|
|
" if (\$_ -is [System.IO.DirectoryInfo]) {" \
|
2024-01-01 18:07:07 +01:00
|
|
|
" [Microsoft.VisualBasic.FileIO.FileSystem]::DeleteDirectory(\$_.FullName, 'OnlyErrorDialogs', 'SendToRecycleBin')" \
|
|
|
|
" } else {" \
|
|
|
|
" [Microsoft.VisualBasic.FileIO.FileSystem]::DeleteFile(\$_.FullName, 'OnlyErrorDialogs', 'SendToRecycleBin')" \
|
|
|
|
" }" \
|
|
|
|
" }" \
|
|
|
|
"}"
|
|
|
|
end
|