Skip to content

Commit

Permalink
Moved cleancontainers, cleandockervolumes, base64encodestring a…
Browse files Browse the repository at this point in the history
…nd `base64decodestring` from OS specific `bash_alias` to OS "agnostic" `bash_alias`
  • Loading branch information
missingcharacter committed Mar 22, 2024
1 parent 941baf3 commit 27925f8
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 48 deletions.
24 changes: 0 additions & 24 deletions MacOS/bash_aliases
Original file line number Diff line number Diff line change
Expand Up @@ -34,31 +34,7 @@ function getent() {
dscacheutil -q "${CATEGORY}" -a "${QUERY_KEY}" "${QUERY_VALUE}"
}

function cleancontainers() {
declare -a exited_containers=() dangling_images=()
read -ra exited_containers < <(docker ps -qa -f status=exited)
docker rm "${exited_containers[@]}"
read -ra dangling_images < <(docker images -qa -f dangling=true)
docker rmi "${dangling_images[@]}"
}

function cleandockervolumes() {
declare -a dangling_volumes=()
read -ra dangling_volumes < <(docker volume ls -f dangling=true -q)
docker volume rm "${dangling_volumes[@]}"
}

function cleancolima() {
colima stop
rm -rf ~/.colima ~/.lima ~/Library/Caches/colima ~/Library/Caches/lima
}

function base64encodestring() {
local TEXT="${1}"
base64 <<<"${TEXT}"
}

function base64decodestring() {
local TEXT="${1}"
base64 -D <<<"${TEXT}"
}
24 changes: 0 additions & 24 deletions Ubuntu/bash_aliases
Original file line number Diff line number Diff line change
Expand Up @@ -60,27 +60,3 @@ function aptlistinrepo() {
grep ^Package \
/var/lib/apt/lists/"${REPO}"*_Packages | awk '{print $2}' | sort -u
}

function cleancontainers() {
declare -a exited_containers=() dangling_images=()
read -ra exited_containers < <(sudo docker ps -qa -f status=exited)
sudo docker rm "${exited_containers[@]}"
read -ra dangling_images < <(sudo docker images -qa -f dangling=true)
sudo docker rmi "${dangling_images[@]}"
}

function cleandockervolumes() {
declare -a dangling_volumes=()
read -ra dangling_volumes < <(sudo docker volume ls -f dangling=true -q)
sudo docker volume rm "${dangling_volumes[@]}"
}

function base64encodestring() {
local TEXT="${1}"
base64 -w 0 <<<"${TEXT}"
}

function base64decodestring() {
local TEXT="${1}"
base64 -d -w 0 <<<"${TEXT}"
}
67 changes: 67 additions & 0 deletions bash_aliases
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,73 @@ function delete_line_before_after() {
done
}

function cleancontainers() {
declare -a docker_cmds=()
case "$(uname)" in
Darwin)
docker_cmds+=('docker')
;;
Linux)
docker_cmds+=('sudo' 'docker')
;;
*)
msg_error "Operating System $(uname) is not supported"
;;
esac
"${docker_cmds[@]}" ps -qa -f status=exited | xargs "${docker_cmds[@]}" rm
"${docker_cmds[@]}" images -qa -f dangling=true | xargs "${docker_cmds[@]}" rmi
}

function cleandockervolumes() {
declare -a docker_cmds=()
case "$(uname)" in
Darwin)
docker_cmds+=('docker')
;;
Linux)
docker_cmds+=('sudo' 'docker')
;;
*)
msg_error "Operating System $(uname) is not supported"
;;
esac
"${docker_cmds[@]}" volume ls -f dangling=true -q | xargs "${docker_cmds[@]}" volume rm
}

function base64encodestring() {
local TEXT="${1}"
declare -a base64_cmds=()
case "$(uname)" in
Darwin)
base64_cmds+=('base64')
;;
Linux)
base64_cmds+=('base64' '-w' '0')
;;
*)
msg_error "Operating System $(uname) is not supported"
;;
esac
"${base64_cmds[@]}" <<<"${TEXT}"
}

function base64decodestring() {
local TEXT="${1}"
declare -a base64_cmds=()
case "$(uname)" in
Darwin)
base64_cmds+=('base64' '-D')
;;
Linux)
base64_cmds+=('base64' '-d' '-w' '0')
;;
*)
msg_error "Operating System $(uname) is not supported"
;;
esac
"${base64_cmds[@]}" <<<"${TEXT}"
}

# Sourcing Operating System Specific bash_aliases
if [ -f ~/.bash_os_aliases ]; then
# shellcheck source=/dev/null
Expand Down

0 comments on commit 27925f8

Please sign in to comment.