Created
August 29, 2022 10:18
-
-
Save Hayao0819/4dd39ac21d79b1d5b41f8c98a800830f to your computer and use it in GitHub Desktop.
Emergeでパッケージの一覧を取得するシェルスクリプト
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# shellcheck source=/dev/null | |
source /dev/stdin < <(curl -sL "https://raw.githubusercontent.com/Hayao0819/FasBashLib/26e244d6f3839bcf159787dfd3e230df39e4500c/fasbashlib.sh") | |
Fsblib.RequireLib "BetterShell" "ParseArg" "Ini" "Emerge" "Array" | |
# Initial variable | |
SpecifiedRepo=() | |
#PrintRepoName=false | |
Command="None" | |
HelpMsg(){ | |
echo "Usage: elist [option] [command] [args]" | |
echo "A simple tool to print package list" | |
echo | |
echo "Options:" | |
echo " -r, --repo [repo1,repo2 ...]" | |
echo " Print only specified repository (for all)" | |
#echo " -n, --reponame Print repository name" | |
echo " -h, --help Print this help message and exit" | |
echo | |
echo "Commands:" | |
echo " all Print all available packages" | |
echo " instaled Print all installed packages" | |
echo " world Print all world packages" | |
} | |
# Parse arguments | |
ParseArg SHORT="r:nh" LONG="repo:,reponame,help" -- "${@}" || exit 1 | |
eval set -- "${OPTRET[*]}" | |
unset OPTRET | |
while true; do | |
case "${1}" in | |
-r | --repo) | |
SpecifiedRepo+=("$2") | |
shift 2 | |
;; | |
-n | --reponame) | |
#PrintRepoName=true | |
shift 1 | |
;; | |
-h | --help) | |
HelpMsg | |
exit 0 | |
;; | |
--) | |
shift 1 | |
break | |
;; | |
*) | |
Msg.Error "Argument exception error '${1}'" | |
Msg.Error "Please report this error to the developer." 1 | |
;; | |
esac | |
done | |
Command="${1-"$Command"}" | |
case "$Command" in | |
"all") | |
if (( "$(Array.Length SpecifiedRepo)" == 0 )); then | |
Em.GetAllPkgList | |
else | |
Array.ForEach SpecifiedRepo Em.GetRepoPkgList "{}" | |
fi | |
;; | |
"installed") | |
Em.GetInstalledPkgList | |
;; | |
"world") | |
Em.GetWorldPkgList | |
;; | |
"None") | |
Msg.Err "Unknown error." | |
exit 1 | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment