代替pacman的apt脚本

发布时间 2023-07-27 16:10:24作者: 星如雨yu

实在受不了pacman命令的抽象了...所以照着文档翻译了个apt的用法

#!/bin/bash
# apt-adapter.sh
# author: xry1029
# date: 2023.7.27
show_usage(){
echo "Usage: apt [update|install|remove|upgrade|search|list|list-installed|list-upgradable|clean] (package)"
exit 1
}
parse_args(){
export args=`echo "$@" | sed "s/${prog}//g"`
}
apt_update(){
pacman -Sy
exit $?
}
apt_install(){
export prog=install
parse_args $@
pacman -S --needed $args
exit $?
}
apt_remove(){
export prog=remove
parse_args $@
pacman -Rs $args
exit $?
}
apt_upgrade(){
pacman --Syu
exit $?
}
apt_search(){
export prog=search
parse_args $@
pacman -Ss $args
exit $?
}
apt_list(){
pacman -Sl #适用于列出所有软件再grep...
exit $?
}
apt_list_installed(){
pacman -Q
exit $?
}
apt_list_upgradable(){
pacman -Qu
exit $?
}
apt_clean(){
pacman -Scc #这里比较狠 清理所有缓存 留仓库缓存的话改成-Sc
rm -rf /usr/share/doc /usr/share/doc-base /usr/share/man #我用不上文档...干脆全删了 要留的注释这行
rm -rf /var/cache/
exit 0
}
[ "$?"x = "1x" ] && show_usage
[ "$1" = "-h" ] && show_usage
[ "$1" = "--help" ] && show_usage
[ "$1" = "update" ] && apt_update
[ "$1" = "install" ] && apt_install $@
[ "$1" = "remove" ] && apt_remove $@
[ "$1" = "upgrade" ] && apt_upgrade
[ "$1" = "search" ] && apt_search $@
[ "$1" = "list" ] && apt_list
[ "$1" = "list-installed" ] && apt_list_installed
[ "$1" = "list-upgradable" ] && apt_list_upgradable
[ "$1" = "clean" ] && apt_clean
show_usage #command not found