Skip to content

Commit 22bc081

Browse files
committed
rm: simplify cleanup logic, leaning on new list commands for export
Signed-off-by: Luca Di Maio <[email protected]>
1 parent 448986a commit 22bc081

File tree

1 file changed

+9
-20
lines changed

1 file changed

+9
-20
lines changed

distrobox-rm

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -320,32 +320,21 @@ delete_container() {
320320
;;
321321
esac
322322

323-
IFS='@'
323+
IFS='
324+
'
325+
printf "Removing exported binaries...\n"
324326
# Remove exported binaries from this container in default path
325-
binary_files="$(grep -rl "# distrobox_binary" "${HOME}/.local/bin" 2> /dev/null | sed 's/./\\&/g' |
326-
xargs -I{} grep -le "# name: ${container_name}$" "{}" | sed 's/./\\&/g' |
327-
xargs -I{} printf "%s@" "{}" 2> /dev/null || :)"
328-
for file in ${binary_files}; do
329-
printf "Removing exported binary %s...\n" "${file}"
330-
rm -f "${file}"
327+
for i in $("$(dirname "$(realpath "${0}")")/distrobox-enter" "${container_name}" -- distrobox-export --list-binaries); do
328+
bin="$(echo "${i}" | cut -d'|' -f1 | sed 's/[ ]*$//' | sed 's/^[ ]*//')"
329+
dir="$(echo "${i}" | cut -d'|' -f2- | sed 's/[ ]*$//' | sed 's/^[ ]*//')"
330+
"$(dirname "$(realpath "${0}")")/distrobox-enter" "${container_name}" -- distrobox-export --bin "${bin}" --export-path "$(dirname "${dir}")" --delete
331331
done
332332

333333
# Remove exported gui apps from this container in default path
334-
# shellcheck disable=SC2086,SC2038
335-
desktop_files="$(find "${HOME}/.local/share/applications/${container_name}"* -type f -o -type l 2> /dev/null | sed 's/./\\&/g' |
336-
xargs -I{} grep -le "Exec=.*${container_name} " "{}" | sed 's/./\\&/g' |
337-
xargs -I{} printf "%s@" "{}" 2> /dev/null || :)"
338-
for file in ${desktop_files}; do
339-
if [ -e "${file}" ]; then
340-
app="$(grep -Eo "Name=.*" "${file}" | head -n 1 | cut -d' ' -f1 | cut -d'=' -f2)"
341-
342-
printf "Removing exported app %s...\n" "${app}"
343-
"$(dirname "$(realpath "${0}")")/distrobox-enter" "${container_name}" -- distrobox-export --delete --app "${app}" > /dev/null 2> /dev/null || :
344-
fi
345-
done
346-
IFS=' '
334+
"$(dirname "$(realpath "${0}")")/distrobox-enter" "${container_name}" -- sh -c "distrobox-export --list-apps | cut -d'|' -f1 | sed 's/[ ]*$//' | xargs -I{} distrobox-export --app \"{}\" -d"
347335

348336
# Remove the container
337+
printf "Removing exported apps...\n"
349338
# shellcheck disable=SC2086,SC2248
350339
${container_manager} rm ${force_flag} "${container_name}"
351340

0 commit comments

Comments
 (0)