confOS/.config/fish/functions/trash.fish
2024-01-01 18:30:46 +01:00

26 lines
1 KiB
Fish

# 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
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
set file (wslpath -w $argv[1])
powershell.exe -Command "& {" \
" Add-Type -AssemblyName 'Microsoft.VisualBasic';" \
" Get-ChildItem -Path '$file' | ForEach-Object {" \
" if (\$_ -is [System.IO.DirectoryInfo]) {" \
" [Microsoft.VisualBasic.FileIO.FileSystem]::DeleteDirectory(\$_.FullName, 'OnlyErrorDialogs', 'SendToRecycleBin')" \
" } else {" \
" [Microsoft.VisualBasic.FileIO.FileSystem]::DeleteFile(\$_.FullName, 'OnlyErrorDialogs', 'SendToRecycleBin')" \
" }" \
" }" \
"}"
end