mirror of
https://forge.chapril.org/tykayn/workflow
synced 2025-10-04 17:04:55 +02:00
up ckeck installed
This commit is contained in:
parent
3942a254b6
commit
cb1e4934b5
5 changed files with 90 additions and 284 deletions
|
@ -1,167 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Script to search for installed packages in bash and zsh history
|
||||
# It looks for installations via apt, apt-get, snap, pipx, pip, and npm
|
||||
|
||||
# Define arrays to store package names
|
||||
declare -a APT_PACKAGES=()
|
||||
declare -a APTGET_PACKAGES=()
|
||||
declare -a SNAP_PACKAGES=()
|
||||
declare -a PIPX_PACKAGES=()
|
||||
declare -a PIP_PACKAGES=()
|
||||
declare -a NPM_PACKAGES=()
|
||||
|
||||
# Function to extract package names from apt install commands
|
||||
extract_apt_packages() {
|
||||
local line="$1"
|
||||
# Remove sudo and apt install/apt-get install part
|
||||
local packages=$(echo "$line" | sed -E 's/^.*apt(-get)? install(-y)? //g')
|
||||
# Split by spaces and add to array
|
||||
for pkg in $packages; do
|
||||
# Skip options that start with -
|
||||
if [[ ! "$pkg" =~ ^- ]]; then
|
||||
APT_PACKAGES+=("$pkg")
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
# Function to extract package names from apt-get install commands
|
||||
extract_aptget_packages() {
|
||||
local line="$1"
|
||||
# Remove sudo and apt-get install part
|
||||
local packages=$(echo "$line" | sed -E 's/^.*apt-get install(-y)? //g')
|
||||
# Split by spaces and add to array
|
||||
for pkg in $packages; do
|
||||
# Skip options that start with -
|
||||
if [[ ! "$pkg" =~ ^- ]]; then
|
||||
APTGET_PACKAGES+=("$pkg")
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
# Function to extract package names from snap install commands
|
||||
extract_snap_packages() {
|
||||
local line="$1"
|
||||
# Remove sudo and snap install part
|
||||
local packages=$(echo "$line" | sed -E 's/^.*snap install //g')
|
||||
# Split by spaces and add to array
|
||||
for pkg in $packages; do
|
||||
# Skip options that start with -
|
||||
if [[ ! "$pkg" =~ ^- && ! "$pkg" =~ ^--classic$ ]]; then
|
||||
SNAP_PACKAGES+=("$pkg")
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
# Function to extract package names from pipx install commands
|
||||
extract_pipx_packages() {
|
||||
local line="$1"
|
||||
# Remove pipx install part
|
||||
local packages=$(echo "$line" | sed -E 's/^.*pipx install //g')
|
||||
# Split by spaces and add to array
|
||||
for pkg in $packages; do
|
||||
# Skip options that start with -
|
||||
if [[ ! "$pkg" =~ ^- ]]; then
|
||||
PIPX_PACKAGES+=("$pkg")
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
# Function to extract package names from pip install commands
|
||||
extract_pip_packages() {
|
||||
local line="$1"
|
||||
# Remove pip/pip3 install part
|
||||
local packages=$(echo "$line" | sed -E 's/^.*(pip|pip3) install //g')
|
||||
# Split by spaces and add to array
|
||||
for pkg in $packages; do
|
||||
# Skip options that start with -
|
||||
if [[ ! "$pkg" =~ ^- ]]; then
|
||||
PIP_PACKAGES+=("$pkg")
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
# Function to extract package names from npm install commands
|
||||
extract_npm_packages() {
|
||||
local line="$1"
|
||||
# Remove npm install part
|
||||
local packages=$(echo "$line" | sed -E 's/^.*npm install(-g)? //g')
|
||||
# Split by spaces and add to array
|
||||
for pkg in $packages; do
|
||||
# Skip options that start with -
|
||||
if [[ ! "$pkg" =~ ^- ]]; then
|
||||
NPM_PACKAGES+=("$pkg")
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
echo "Searching for installed packages in bash and zsh history..."
|
||||
|
||||
# Parse bash history if it exists
|
||||
if [ -f ~/.bash_history ]; then
|
||||
echo "Parsing bash history..."
|
||||
while IFS= read -r line; do
|
||||
if [[ "$line" =~ apt\ install ]]; then
|
||||
extract_apt_packages "$line"
|
||||
elif [[ "$line" =~ apt-get\ install ]]; then
|
||||
extract_aptget_packages "$line"
|
||||
elif [[ "$line" =~ snap\ install ]]; then
|
||||
extract_snap_packages "$line"
|
||||
elif [[ "$line" =~ pipx\ install ]]; then
|
||||
extract_pipx_packages "$line"
|
||||
elif [[ "$line" =~ (pip|pip3)\ install ]]; then
|
||||
extract_pip_packages "$line"
|
||||
elif [[ "$line" =~ npm\ install ]]; then
|
||||
extract_npm_packages "$line"
|
||||
fi
|
||||
done < ~/.bash_history
|
||||
else
|
||||
echo "Bash history file not found."
|
||||
fi
|
||||
|
||||
# Parse zsh history if it exists
|
||||
if [ -f ~/.zsh_history ]; then
|
||||
echo "Parsing zsh history..."
|
||||
while IFS= read -r line; do
|
||||
# ZSH history has a different format, we need to extract the command part
|
||||
# Format is typically: : timestamp:0;command
|
||||
cmd=$(echo "$line" | sed -E 's/^: [0-9]+:[0-9];(.*)$/\1/')
|
||||
|
||||
if [[ "$cmd" =~ apt\ install ]]; then
|
||||
extract_apt_packages "$cmd"
|
||||
elif [[ "$cmd" =~ apt-get\ install ]]; then
|
||||
extract_aptget_packages "$cmd"
|
||||
elif [[ "$cmd" =~ snap\ install ]]; then
|
||||
extract_snap_packages "$cmd"
|
||||
elif [[ "$cmd" =~ pipx\ install ]]; then
|
||||
extract_pipx_packages "$cmd"
|
||||
elif [[ "$cmd" =~ (pip|pip3)\ install ]]; then
|
||||
extract_pip_packages "$cmd"
|
||||
elif [[ "$cmd" =~ npm\ install ]]; then
|
||||
extract_npm_packages "$cmd"
|
||||
fi
|
||||
done < ~/.zsh_history
|
||||
else
|
||||
echo "ZSH history file not found."
|
||||
fi
|
||||
|
||||
# Display results
|
||||
echo -e "\n=== Packages installed via apt ==="
|
||||
printf '%s\n' "${APT_PACKAGES[@]}" | sort -u
|
||||
|
||||
echo -e "\n=== Packages installed via apt-get ==="
|
||||
printf '%s\n' "${APTGET_PACKAGES[@]}" | sort -u
|
||||
|
||||
echo -e "\n=== Packages installed via snap ==="
|
||||
printf '%s\n' "${SNAP_PACKAGES[@]}" | sort -u
|
||||
|
||||
echo -e "\n=== Packages installed via pipx ==="
|
||||
printf '%s\n' "${PIPX_PACKAGES[@]}" | sort -u
|
||||
|
||||
echo -e "\n=== Packages installed via pip/pip3 ==="
|
||||
printf '%s\n' "${PIP_PACKAGES[@]}" | sort -u
|
||||
|
||||
echo -e "\n=== Packages installed via npm ==="
|
||||
printf '%s\n' "${NPM_PACKAGES[@]}" | sort -u
|
||||
|
||||
echo -e "\nSearch complete."
|
Loading…
Add table
Add a link
Reference in a new issue