mirror of
https://github.com/89luca89/distrobox.git
synced 2025-02-25 18:55:25 -06:00
rm: simplify cleanup logic, leaning on new list commands for export
Signed-off-by: Luca Di Maio <luca.dimaio1@gmail.com>
This commit is contained in:
29
distrobox-rm
29
distrobox-rm
@@ -320,32 +320,21 @@ delete_container() {
|
||||
;;
|
||||
esac
|
||||
|
||||
IFS='@'
|
||||
IFS='
|
||||
'
|
||||
printf "Removing exported binaries...\n"
|
||||
# Remove exported binaries from this container in default path
|
||||
binary_files="$(grep -rl "# distrobox_binary" "${HOME}/.local/bin" 2> /dev/null | sed 's/./\\&/g' |
|
||||
xargs -I{} grep -le "# name: ${container_name}$" "{}" | sed 's/./\\&/g' |
|
||||
xargs -I{} printf "%s@" "{}" 2> /dev/null || :)"
|
||||
for file in ${binary_files}; do
|
||||
printf "Removing exported binary %s...\n" "${file}"
|
||||
rm -f "${file}"
|
||||
for i in $("$(dirname "$(realpath "${0}")")/distrobox-enter" "${container_name}" -- distrobox-export --list-binaries); do
|
||||
bin="$(echo "${i}" | cut -d'|' -f1 | sed 's/[ ]*$//' | sed 's/^[ ]*//')"
|
||||
dir="$(echo "${i}" | cut -d'|' -f2- | sed 's/[ ]*$//' | sed 's/^[ ]*//')"
|
||||
"$(dirname "$(realpath "${0}")")/distrobox-enter" "${container_name}" -- distrobox-export --bin "${bin}" --export-path "$(dirname "${dir}")" --delete
|
||||
done
|
||||
|
||||
# Remove exported gui apps from this container in default path
|
||||
# shellcheck disable=SC2086,SC2038
|
||||
desktop_files="$(find "${HOME}/.local/share/applications/${container_name}"* -type f -o -type l 2> /dev/null | sed 's/./\\&/g' |
|
||||
xargs -I{} grep -le "Exec=.*${container_name} " "{}" | sed 's/./\\&/g' |
|
||||
xargs -I{} printf "%s@" "{}" 2> /dev/null || :)"
|
||||
for file in ${desktop_files}; do
|
||||
if [ -e "${file}" ]; then
|
||||
app="$(grep -Eo "Name=.*" "${file}" | head -n 1 | cut -d' ' -f1 | cut -d'=' -f2)"
|
||||
|
||||
printf "Removing exported app %s...\n" "${app}"
|
||||
"$(dirname "$(realpath "${0}")")/distrobox-enter" "${container_name}" -- distrobox-export --delete --app "${app}" > /dev/null 2> /dev/null || :
|
||||
fi
|
||||
done
|
||||
IFS=' '
|
||||
"$(dirname "$(realpath "${0}")")/distrobox-enter" "${container_name}" -- sh -c "distrobox-export --list-apps | cut -d'|' -f1 | sed 's/[ ]*$//' | xargs -I{} distrobox-export --app \"{}\" -d"
|
||||
|
||||
# Remove the container
|
||||
printf "Removing exported apps...\n"
|
||||
# shellcheck disable=SC2086,SC2248
|
||||
${container_manager} rm ${force_flag} "${container_name}"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user