•  brie   ( @brie@beehaw.org ) 
    link
    fedilink
    English
    41 year ago

    For fun, a shell script for the same functionality:

    #!/bin/sh
    br="$(printf "\n")" # Obtain a line-break
    
    # If RM_CMD is unset, use trash-cli
    if [ -z ${RM_CMD+y} ]; then RM_CMD="trash"; fi
    
    # List of apps. The leading br is necessary for later pattern matching
    apps="$br$(flatpak list --columns=application)" || exit 1
    
    cd ~/.var/app || exit 1
    
    for app in *; do
    	case "$apps" in
    		*"$br$app$br"*) ;; # Matches if $app is in the list (installed)
    		*)
    			printf 'Removing app data %s\n' "${app}"
    			"$RM_CMD" "./${app}"
    			;;
    	esac
    done
    

    (May eat your files)

    • 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."
      
      • 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 is kind of a shortcoming of all package management in general; should deleting the package delete your user data? There’s an argument to be made that data should be removed with the application, but deleting data irrecoverably as the default isn’t necessarily the easiest approach.

      There’s also another problem, which is that the behaviour of deleting data may make sense for per-user applications, but for system-wide apps, should uninstalling an application start nuking data in people’s homedirs?