From c1a7e13c31610d9342eddf0d3b6f8c47be6a5ad4 Mon Sep 17 00:00:00 2001 From: eshanized Date: Sun, 12 Jan 2025 19:36:41 +0530 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=80=20feat:=20ad=20pacman=20fallback?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .bashrc | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/.bashrc b/.bashrc index 8bb6175..77aa6f5 100644 --- a/.bashrc +++ b/.bashrc @@ -336,4 +336,34 @@ alias k-exec="kubectl exec -it" # Execut alias ansible-play="ansible-playbook" # Run an Ansible playbook alias terraform-init="terraform init" # Initialize Terraform project alias terraform-apply="terraform apply" # Apply Terraform configuration to provision resources -alias terraform-plan="terraform plan" # Preview changes Terraform will make to infrastructure \ No newline at end of file +alias terraform-plan="terraform plan" # Preview changes Terraform will make to infrastructure + +# Function to install packages with pacman and fallback to yay +install_package() { + local package_name="$1" # The name of the package to install + + if [[ -z "$package_name" ]]; then + echo "Usage: install_package " + return 1 + fi + + echo "Attempting to install '$package_name' with pacman..." + sudo pacman -S --noconfirm "$package_name" + if [[ $? -eq 0 ]]; then + echo "'$package_name' installed successfully with pacman!" + return 0 + fi + + echo "Package '$package_name' could not be installed with pacman. Trying yay..." + yay -S --noconfirm "$package_name" + if [[ $? -eq 0 ]]; then + echo "'$package_name' installed successfully with yay!" + return 0 + fi + + echo "Failed to install '$package_name' with both pacman and yay." + return 1 +} + +# Alias for convenience +alias syay="install_package"