This commit is contained in:
pika 2025-07-05 13:32:29 +02:00
parent 84e0d3b4b4
commit a5528e68f4
2 changed files with 39 additions and 115 deletions

View file

@ -41,12 +41,8 @@ else
alias hl="grep --passthrough"
fi
ffile() {
if [ -z $2 ]; then
find -type f "${1:-./**}"
else
find -type f "'${1:-./**}'" -name "${2}"
fi
hm() {
find -type f -name "${1}" | wc -l
}
if command_exists dog; then
@ -238,82 +234,10 @@ __docker__() {
alias dr="docker run --rm -it"
alias drs="docker compose down && docker compose up -d --remove-orphans --force-recreate"
alias ds="docker ps -a --format 'table {{.ID}}\t{{.Image}}\t{{.Status}}\t{{.Ports}}'"
alias dcs="docker compose ps -a --format 'table {{.Name}}\t{{.Image}}\t{{.Status}}\t{{.Ports}}'"
alias dl="docker compose logs -f"
alias dc="docker compose"
# check_for_updates() {
# if ! command -v jq &>/dev/null; then
# echo -e "${RED}Error: jq is required but not installed. Please install jq.${NC}"
# return 1
# fi
#
# if ! docker compose version &>/dev/null; then
# echo -e "${RED}Error: docker compose is not available.${NC}"
# return 1
# fi
#
# local updated=false
# local images
# images=$(docker compose config --format json | jq -r '.services[] | .image' 2>/dev/null)
#
# if [[ -z "$images" ]]; then
# echo -e "${RED}Error: No Docker images found in the compose configuration.${NC}"
# return 1
# fi
#
# for image in $images; do
# echo -e "${CYAN}Checking for updates for image: ${YELLOW}$image${NC}"
#
# # Get local image digest
# local local_digest
# local_digest=$(docker image inspect "$image" --format '{{index .RepoDigests 0}}') # 2>/dev/null
#
# # If no local digest exists, force check
# if [[ -z "$local_digest" ]]; then
# echo -e "${YELLOW}Image not present locally. Update needed.${NC}"
# updated=true
# continue
# fi
#
# # Get remote digest using pull --dry-run
# local remote_digest
# remote_digest=$(docker pull --quiet "$image" 2>/dev/null | awk '/Digest:/{print $2}')
#
# # Fallback to manifest inspect if dry-run fails
# if [[ -z "$remote_digest" ]]; then
# remote_digest=$(DOCKER_CLI_EXPERIMENTAL=enabled docker manifest inspect -v "$image" | jq -r '.Descriptor.digest')
# fi
#
# if [[ -z "$remote_digest" ]]; then
# echo -e "${RED}Failed to retrieve remote digest. Performing forced check...${NC}"
# # Fallback method: Pull image and compare before/after digests
# local pre_pull_digest=$(docker image inspect "$image" --format '{{index .RepoDigests 0}}')
# docker pull --quiet "$image" >/dev/null
# local post_pull_digest=$(docker image inspect "$image" --format '{{index .RepoDigests 0}}')
#
# if [[ "$pre_pull_digest" != "$post_pull_digest" ]]; then
# echo -e "${GREEN}Update found during forced pull${NC}"
# updated=true
# fi
# continue
# fi
#
# # Compare digests
# if [[ "$local_digest" != "$remote_digest" ]]; then
# echo -e "${GREEN}Update available for $image${NC}"
# updated=true
# else
# echo -e "${YELLOW}No update available for $image${NC}"
# fi
# done
#
# if $updated; then
# echo -e "${CYAN}Pulling updates and recreating containers...${NC}"
# docker compose pull --quiet && docker compose up -d --force-recreate
# else
# echo -e "${GREEN}All images are up to date. No action needed.${NC}"
# fi
# }
alias dcs="docker compose ps -a --format 'table {{.Name}}\t{{.Image}}\t{{.Status}}\t{{.Ports}}'"
alias dlog="docker compose logs"
# Check for required dependencies
check_for_updates() {
local compose_cmd
@ -664,6 +588,40 @@ source-script() {
fi
}
resolve() {
local quiet=false
if [[ "$1" == "-q" ]]; then
quiet=true
shift
fi
local ip="$1"
local server="$2"
local dig_out
dig_out=$(command dig +noall +answer -x "$ip" ${server:+@$server} 2>/dev/null)
local line ptr hostname time
line=$(grep 'PTR' <<<"$dig_out")
ptr=$(awk '{print $4}' <<<"$line")
time=$(awk '{print $2}' <<<"$dig_out")
hostname=$(awk '{print $5}' <<<"$line" | sed 's/\.$//')
if $quiet; then
[[ -n "$hostname" ]] && echo "$hostname"
return
fi
if [[ -n "$hostname" ]]; then
# ✅ resolved
printf "${BOLD}${GREEN}%s${NC} \033[1;90m%s${NC} \033[32m%s${NC} \033[2m%s ms${NC}\n" \
"$ptr" "$ip" "$hostname" "$time"
else
# ❌ not resolved
printf "❌ \033[1;31m%s${NC} \033[1;90m%s${NC} \033[1;31mNOT FOUND${NC} \033[2m%s ms\033[0m\n" \
"PTR" "$ip" "${time:-0}"
fi
}
main() {
# ─< g stands for GIT >─────────────────────────────────────────────────────────────────────
if command_exists git; then

34
.zshrc
View file

@ -352,37 +352,3 @@ main() {
if check_root; then
main
fi
resolve() {
local quiet=false
if [[ "$1" == "-q" ]]; then
quiet=true
shift
fi
local ip="$1"
local server="$2"
local dig_out
dig_out=$(command dig +noall +answer -x "$ip" ${server:+@$server} 2>/dev/null)
local line ptr hostname time
line=$(grep 'PTR' <<<"$dig_out")
ptr=$(awk '{print $4}' <<<"$line")
time=$(awk '{print $2}' <<<"$dig_out")
hostname=$(awk '{print $5}' <<<"$line" | sed 's/\.$//')
if $quiet; then
[[ -n "$hostname" ]] && echo "$hostname"
return
fi
if [[ -n "$hostname" ]]; then
# ✅ resolved
printf "${BOLD}${GREEN}%s${NC} \033[1;90m%s${NC} \033[32m%s${NC} \033[2m%s ms${NC}\n" \
"$ptr" "$ip" "$hostname" "$time"
else
# ❌ not resolved
printf "❌ \033[1;31m%s${NC} \033[1;90m%s${NC} \033[1;31mNOT FOUND${NC} \033[2m%s ms\033[0m\n" \
"PTR" "$ip" "${time:-0}"
fi
}