fix trash-restore script
This commit is contained in:
parent
1fe1faea2a
commit
a35af6880b
|
@ -1,4 +1,5 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
getfsroot() {
|
getfsroot() {
|
||||||
printf "%s" "$(df "$1" --output=target | tail -1)"
|
printf "%s" "$(df "$1" --output=target | tail -1)"
|
||||||
|
@ -6,26 +7,34 @@ getfsroot() {
|
||||||
list() {
|
list() {
|
||||||
# 1st arg is trash files directory
|
# 1st arg is trash files directory
|
||||||
# 2nd arg is directory to match trash files for
|
# 2nd arg is directory to match trash files for
|
||||||
[ ! "$(ls -A "$1")" ] && exit 1
|
[ ! "$(command ls -A "$1")" ] && exit 1
|
||||||
for file in "$1"/*; do
|
for file in "$1"/*; do
|
||||||
[ "$(head -1 "$file")" = "[Trash Info]" ] &&
|
[ "$(head -1 "$file")" = "[Trash Info]" ] &&
|
||||||
fpath=$(grep Path "$file" | cut -d '=' -f2) &&
|
filepath=$(grep Path "$file" | cut -d '=' -f2) &&
|
||||||
echo "$fpath" | grep -qP "^$2/[^/]+$" &&
|
echo "$filepath" | grep -qP "^$2/[^/]+$" &&
|
||||||
printf "%s %s %s\n" \
|
printf "%s %s %s\n" \
|
||||||
"$(basename "$file")" \
|
"$(basename "$file")" \
|
||||||
"$fpath" \
|
"$filepath" \
|
||||||
"$(date -d "$(grep Date "$file" | cut -d '=' -f2)" +'%x %X')"
|
"$(date -d "$(grep Date "$file" | cut -d '=' -f2)" +'%x %X')"
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
[ -n "$1" ] && dir="$(realpath "$1")" || dir="$(getfsroot "$PWD")"
|
if [ -n "$1" ]; then
|
||||||
|
dir="$(realpath "$1")"
|
||||||
|
else
|
||||||
|
dir="$(realpath "$PWD")"
|
||||||
|
fi
|
||||||
|
|
||||||
fsroot="$(getfsroot "$dir")"
|
fsroot="$(getfsroot "$dir")"
|
||||||
[ "$fsroot" = "$(getfsroot "${XDG_DATA_HOME:-$HOME/.local/share}")" ] &&
|
|
||||||
basedir="${XDG_DATA_HOME:-$HOME/.local/share}/Trash" ||
|
if [ "$fsroot" = "$(getfsroot "${XDG_DATA_HOME:-$HOME/.local/share}")" ]; then
|
||||||
|
basedir="${XDG_DATA_HOME:-$HOME/.local/share}/Trash"
|
||||||
|
else
|
||||||
basedir="${fsroot}/.Trash"
|
basedir="${fsroot}/.Trash"
|
||||||
|
fi
|
||||||
|
|
||||||
sel="$(list "$basedir/info" "$dir" | fzf)"
|
sel="$(list "$basedir/info" "$dir" | fzf)"
|
||||||
file="$basedir/files/$(echo "$sel" | cut -d ' ' -f1)"
|
file="$basedir/files/$(echo "$sel" | cut -d '' -f1)"
|
||||||
dest="$(echo "$sel" | cut -d ' ' -f2)"
|
dest="$(echo "$sel" | cut -d '' -f3)"
|
||||||
command mv -ib "$file" "$dest"
|
command mv -ib "$file" "$dest"
|
||||||
command rm "$basedir/info/$(echo "$sel" | cut -d ' ' -f1)"
|
command rm "$basedir/info/$(echo "$sel" | cut -d '' -f1)"
|
||||||
|
|
Loading…
Reference in New Issue