This commit is contained in:
pika 2025-05-07 22:21:59 +02:00
parent 6c8b3b8b72
commit e5719c245e
2 changed files with 31 additions and 113 deletions

12
yazi.sh
View file

@ -6,6 +6,18 @@
command -v "$@" >/dev/null 2>&1 command -v "$@" >/dev/null 2>&1
} }
# WHY:
# This import will give you the following variables:
# _sudo="sudo -E" <- only if non root user
# distro = <distro name, like 'arch', 'debian', 'fedora'..>
# arch = bool
# fedora = bool
# opensuse = bool....
# You can then use it for, `if $arch; then`
# Also this gives you the _install command, which installs a package pased on the packagemanager/distro used.
# CAUTION:
# This only wokrs for generic package names, like neovim, or vim, or tmux etc..
# not every package packagemanager has the same packagenames for their packages..
if command_exists curl; then if command_exists curl; then
eval "$(curl -fsSL https://git.k4li.de/scripts/imports/raw/branch/main/distros.sh)" eval "$(curl -fsSL https://git.k4li.de/scripts/imports/raw/branch/main/distros.sh)"
else else

128
ytgo.sh
View file

@ -1,124 +1,30 @@
#!/usr/bin/env sh #!/usr/bin/env sh
# ╭───────────────╮
# │ env functions │
# ╰───────────────╯
# ───────────────────────────────────< ANSI color codes >───────────────────────────────────
RED='\033[0;31m'
CYAN='\033[0;36m'
YELLOW='\033[0;33m'
LIGHT_GREEN='\033[0;92m'
BOLD='\033[1m'
NC='\033[0m' # No Color
echo_error() {
printf "${BOLD}${RED}ERROR: ${NC}${RED}%s${NC}\n" "$1" >&2
}
echo_info() {
printf "${BOLD}${CYAN}INFO: ${NC}${CYAN}%s${NC}\n" "$1"
}
echo_warning() {
printf "${BOLD}${YELLOW}WARNING: ${NC}${YELLOW}%s${NC}\n" "$1"
}
echo_note() {
printf "${BOLD}${LIGHT_GREEN}NOTE: ${NC}${LIGHT_GREEN}%s${NC}\n" "$1"
}
command_exists() { command_exists() {
command -v "$@" >/dev/null 2>&1 command -v "$@" >/dev/null 2>&1
} }
# ─────────────< Check if the user is root and set sudo variable if necessary >───────────── # WHY:
check_root() { # This import will give you the following variables:
if [ "$(id -u)" -ne 0 ]; then # _sudo="sudo -E" <- only if non root user
if command_exists sudo; then # distro = <distro name, like 'arch', 'debian', 'fedora'..>
echo_info "User is not root. Using sudo for privileged operations." # arch = bool
_sudo="sudo" # fedora = bool
else # opensuse = bool....
echo_error "No sudo found and you're not root! Can't install packages." # You can then use it for, `if $arch; then`
return 1 # Also this gives you the _install command, which installs a package pased on the packagemanager/distro used.
fi # CAUTION:
else # This only wokrs for generic package names, like neovim, or vim, or tmux etc..
echo_info "Root access confirmed." # not every package packagemanager has the same packagenames for their packages..
_sudo="" if command_exists curl; then
fi eval "$(curl -fsSL https://git.k4li.de/scripts/imports/raw/branch/main/distros.sh)"
} else
echo "curl is required, but missing.."
# ──────────────────────< Check if the given command exists silently >──────────────────────
command_exists() {
command -v "$@" >/dev/null 2>&1
}
# ╭────────────────────────────────────╮
# │ insert your scripts/functions here │
# ╰────────────────────────────────────╯
# ─< Distribution detection and installation >────────────────────────────────────────
get_packager() {
if [ -e /etc/os-release ]; then
echo_info "Detecting distribution..."
. /etc/os-release
# ─< Convert $ID and $ID_LIKE to lowercase >──────────────────────────────────────────────
ID=$(printf "%s" "$ID" | tr '[:upper:]' '[:lower:]')
ID_LIKE=$(printf "%s" "$ID_LIKE" | tr '[:upper:]' '[:lower:]')
case "$ID" in
ubuntu | pop) _install() {
$_sudo apt-get install --assume-yes "$@"
} ;;
debian) _install() {
$_sudo apt-get install --assume-yes "$@"
} ;;
fedora) _install() {
$_sudo dnf install -y "$@"
} ;;
alpine) inst_alpine ;;
arch | manjaro | garuda | endeavour) _install() {
$_sudo pacman -S --noconfirm "$@"
} ;;
opensuse*) inst_opensuse ;;
*)
if [ "${ID_LIKE#*debian}" != "$ID_LIKE" ]; then
_install() {
$_sudo apt-get install --assume-yes "$@"
}
elif [ "${ID_LIKE#*ubuntu}" != "$ID_LIKE" ]; then
_install() {
$_sudo apt-get install --assume-yes "$@"
}
elif [ "${ID_LIKE#*arch}" != "$ID_LIKE" ]; then
_install() {
$_sudo pacman -S --noconfirm "$@"
}
elif [ "${ID_LIKE#*fedora}" != "$ID_LIKE" ]; then
_install() {
$_sudo dnf install -y "$@"
}
elif [ "${ID_LIKE#*suse}" != "$ID_LIKE" ]; then
inst_opensuse
else
echo_error "Unsupported distribution: $ID"
exit 1 exit 1
fi fi
;;
esac
else
echo_error "Unable to detect distribution. /etc/os-release not found."
exit 1
fi
}
_dependencies() { _dependencies() {
get_packager
if [[ "$ID" == "arch" || "$ID_LIKE" == *"arch"* ]]; then
_deps="go git mpv yt-dlp" _deps="go git mpv yt-dlp"
else
_deps="golang git mpv yt-dlp"
fi
for dependency in $_deps; do for dependency in $_deps; do
if ! command_exists "$dependency"; then if ! command_exists "$dependency"; then