solus-packages/common/Scripts/helpers.zsh
Rune Morling f501790397
helpers*sh: Update/add cpesearch for bash/fish/zsh
Now supports showing usage if '-h' and '--help' are supplied as arguments

Signed-off-by: Rune Morling <ermo@serpentos.com>
2024-01-31 21:31:03 +01:00

71 lines
1.9 KiB
Bash
Executable file

#!/usr/bin/env zsh
autoload -U +X compinit && compinit
autoload -U +X bashcompinit && bashcompinit
# Primitive CPE search tool
function cpesearch() {
if [[ -z $1 || $1 == "--help" || $1 == "-h" ]]; then
echo "usage: cpesearch <package-name>"
else
curl -s -X POST https://cpe-guesser.cve-search.org/search -d "{\"query\": [\"$1\"]}" | jq .
echo "Verify successful hits by visiting https://cve.circl.lu/search/\$VENDOR/\$PRODUCT"
echo "- CPE entries for software applications have the form 'cpe:2.3:a:\$VENDOR:\$PRODUCT'"
fi
}
# Goes to the root directory of the solus packages
# git repository from anywhere on the filesystem.
# This function will only work if this script is sourced
# by your zsh shell.
function gotosoluspkgs() {
SCRIPT_PATH=$functions_source[gotosoluspkgs]
cd $(dirname $(readlink "${SCRIPT_PATH}"))/../../
}
# Goes to the root directory of the git repository
function goroot() {
cd $(git rev-parse --show-toplevel)
}
# Change into a package directory
function gotopkg() {
cd $(git rev-parse --show-toplevel)/packages/*/$1
}
# Re-index the local repo and update eopkg's cache
function localrepo_reindex() {
sudo eopkg index --skip-signing /var/lib/solbuild/local/ --output /var/lib/solbuild/local/eopkg-index.xml && \
sudo eopkg update-repo
}
# What provides a lib
function whatprovides() {
grep $1 $(git rev-parse --show-toplevel)/packages/*/*/abi_libs
}
# What uses a lib
function whatuses() {
grep $1 $(git rev-parse --show-toplevel)/packages/*/*/abi_used_libs
}
# Package name completion
_gotopkg()
{
_list=$(ls $(git rev-parse --show-toplevel)/packages/*/)
local cur prev
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
prev="${COMP_WORDS[COMP_CWORD-1]}"
if [[ $COMP_CWORD -eq 1 ]] ; then
COMPREPLY=( $(compgen -W "${_list}" -- ${cur}) )
return 0
fi
}
complete -F _gotopkg gotopkg