Skip to content

Commit

Permalink
rm: simplify cleanup logic, leaning on new list commands for export
Browse files Browse the repository at this point in the history
Signed-off-by: Luca Di Maio <luca.dimaio1@gmail.com>
  • Loading branch information
89luca89 committed Feb 25, 2024
1 parent 448986a commit 22bc081
Showing 1 changed file with 9 additions and 20 deletions.
29 changes: 9 additions & 20 deletions distrobox-rm
Original file line number Diff line number Diff line change
Expand Up @@ -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}"

Expand Down

0 comments on commit 22bc081

Please sign in to comment.