63
submitted 1 year ago by d3Xt3r@beehaw.org to c/foss@beehaw.org
you are viewing a single comment's thread
view the rest of the comments
[-] Pantherina@feddit.de 3 points 1 year ago

Pretty complicated

#!/bin/bash

# List contents of ~/.var/app/
files=$(ls -1 ~/.var/app/)

# Loop through each element of the folder
for file in $files; do
    # Set the name as a variable
    app_name="${file##*/}"

    # Check if a flatpak app of that name is installed
    if ! flatpak list 2> /dev/null | grep -qw $app_name; then
        # Ask the user to delete the folder
        read -p "The app $app_name is not installed. Do you want to delete its folder? (y/n): " choice
        case "$choice" in
            [Yy]* )
                # Remove the folder recursively
                rm -rf ~/.var/app/$file;;
            [Nn]* )
                echo "Skipping deletion of $app_name folder.";;
            * )
                echo "Invalid input. Skipping deletion of $app_name folder.";;
        esac
    fi
done

echo "All Apps checked."
[-] brie@beehaw.org 1 points 1 year ago

The check for if a package is installed can be simplified using flatpak info.

$ flatpak info com.example.Nonexistent &>/dev/null; echo $?
1
$ flatpak info org.mozilla.firefox &>/dev/null; echo $?    
0
this post was submitted on 05 Aug 2023
63 points (100.0% liked)

Free and Open Source Software

17729 readers
13 users here now

If it's free and open source and it's also software, it can be discussed here. Subcommunity of Technology.


This community's icon was made by Aaron Schneider, under the CC-BY-NC-SA 4.0 license.

founded 2 years ago
MODERATORS