diff --git a/.config/bash/module/Docker.sh b/.config/bash/module/Docker.sh index 2638e91..f5bc8fa 100644 --- a/.config/bash/module/Docker.sh +++ b/.config/bash/module/Docker.sh @@ -20,11 +20,6 @@ function docker_update() { docker images --format "{{.Repository}}:{{.Tag}}" | xargs -L1 docker pull } -# Prune everything. -function docker_prune() { - docker system prune --volumes --all -} - # Docker compose shortcut. function dc() { docker compose "${@}" diff --git a/.config/bash/module/Nix.sh b/.config/bash/module/Nix.sh index fae7603..7e85c05 100644 --- a/.config/bash/module/Nix.sh +++ b/.config/bash/module/Nix.sh @@ -26,12 +26,6 @@ function nix_update() { nix flake update "${_nix_system_config}" } -# Free up root space. -function nix_prune() { - nix-collect-garbage -d - _is_root && nix-store --gc -} - # Spawn shell with specified nix environment. # Uses flake.nix in current dir by default. # Usage: nix_shell [NAME] diff --git a/.config/bash/module/Prune.sh b/.config/bash/module/Prune.sh new file mode 100644 index 0000000..1905d07 --- /dev/null +++ b/.config/bash/module/Prune.sh @@ -0,0 +1,25 @@ +export _flatpakcfg_path="${HOME}/.config/linux/Flatpak.txt" + +# Prune everything unused in docker. +function prune_docker() { + docker system prune --volumes --all +} + +# Prune Nix Store. +function prune_nix() { + nix-collect-garbage -d + _is_root && nix-store --gc +} + +# Uninstall flatpaks not listed in the config. +function prune_flatpak() { + local IFS=$'\n' + local config=($(cat ${_flatpakcfg_path} | cut -f2)) + local installed=($(flatpak list --app | cut -f2)) + + process() { + _contains ${target} ${config[@]} || flatpak uninstall ${target} + } + + _iterate_targets process ${installed[@]} +} diff --git a/.doc/Bash.md b/.doc/Bash.md index 2f231be..f399c5f 100644 --- a/.doc/Bash.md +++ b/.doc/Bash.md @@ -132,7 +132,6 @@ Command|Description `docker_health`| Check if any container exited. `docker_ip `|Find out container's IP address. `docker_update`| Update all docker images. -`docker_prune`| Prune everything. `dc`| Docker compose shortcut. `dcu [SERVICES]`|Docker compose up. `dcd [SERVICES]`|Docker compose down. @@ -270,7 +269,6 @@ Command|Description `nix_rebuild [HOSTNAME]`|Rebuild system. Optionally force the hostname. `nix_switch [HOSTNAME]`|Rebuild and switch system. Optionally force the hostname. `nix_update`|Update system versions. -`nix_prune`| Free up root space. `nix_shell [NAME]`|Spawn shell with specified nix environment. Uses flake.nix in current dir by default. `nix_tmpshell `|Spawn nix-shell with specified packages. `nix_live`| Build live image. @@ -321,6 +319,14 @@ Command|Description `perm_share`| Recursively change permissions to allow read sharing with group and others. `perm`| Recursively change permissions to restrict access for group and others. +## Prune. + +Command|Description +---|--- +`prune_docker`| Prune everything unused in docker. +`prune_nix`| Prune Nix Store. +`prune_flatpak`| Uninstall flatpaks not listed in the config. + ## Ps. Command|Description