diff --git a/tabs/applications-setup/shell-aliases.sh b/tabs/applications-setup/shell-aliases.sh old mode 100644 new mode 100755 index 7609b680e..e475e0331 --- a/tabs/applications-setup/shell-aliases.sh +++ b/tabs/applications-setup/shell-aliases.sh @@ -7,199 +7,36 @@ if command_exists linutil; then exit 1 fi -# Bash alias setup script -setup_bash() { - BASHRC_FILE="$HOME/.bashrc" - - echo - - if [ ! -f "$BASHRC_FILE" ]; then # Checks if the default config exists - echo ".bashrc not found." - - if [ -f "/etc/skel/.bashrc" ]; then - echo "Defaults found. Copying." - cp "/etc/skel/.bashrc" "$BASHRC_FILE" # Copies distro-specific defaults +shells=(bash zsh fish tcsh ksh nu) # Supported shells +configs=(.bashrc .zshrc config.fish .tcshrc .kshrc config.nu) # Shell config filenames +aliases=("alias linutil=\"curl -fsSL https://christitus.com/linux | sh\"" # Alias structures for different shell configs + "alias linutil=\"curl -fsSL https://christitus.com/linux | sh\"" + "alias linutil \"curl -fsSL https://christitus.com/linux | sh\"" + "alias linutil \"curl -fsSL https://christitus.com/linux | sh\"" + "alias linutil='curl -fsSL https://christitus.com/linux | sh'" + "alias linutil = curl -fsSL https://christitus.com/linux | sh") + +for ((i=0; i<${#shells[@]}; i++)); do + if command_exists ${shells[$i]}; then + echo "Found ${shells[$i]}. Adding the alias..." + config_file="$HOME/${configs[$i]}" + if [ ! -f "$config_file" ]; then + if [ "${shells[$i]}" == "fish" ] || [ "${shells[$i]}" == "nu" ]; then # Change config dirs for specific shells + config_dir="$XDG_CONFIG_HOME/${shells[$i]}" + mkdir -p "$config_dir" + config_file="$config_dir/${configs[$i]}" + elif [ "${shells[$i]}" == "bash" ] && [ -f "/etc/skel/.bashrc" ]; then # Default distro-specific config for bash + cp "/etc/skel/.bashrc" "$config_file" + else + touch "$config_file" + fi + fi + if ! grep -Fxq "${aliases[$i]}" "$config_file"; then # Check if alias already exists + echo "${aliases[$i]}" >> "$config_file" + echo "Alias added." else - echo "Default .bashrc not found. Creating a new one." - touch "$BASHRC_FILE" + echo "Alias already exists." fi - - echo - fi - - if grep -Fxq 'alias linutil="curl -fsSL https://christitus.com/linux | sh"' "$BASHRC_FILE"; then # Checks if alias already exists - echo "Alias already exists." - echo - else - echo 'alias linutil="curl -fsSL https://christitus.com/linux | sh"' >> "$BASHRC_FILE" # Adds the alias - - echo "Alias added." - echo - fi -} - -# Zsh alias setup script -setup_zsh() { - ZSHRC_FILE="$HOME/.zshrc" - - echo - - if [ ! -f "$ZSHRC_FILE" ]; then # Checks if the default config exists - echo ".zshrc not found. Creating a new one." - touch "$ZSHRC_FILE" - echo - fi - - if grep -Fxq 'alias linutil="curl -fsSL https://christitus.com/linux | sh"' "$ZSHRC_FILE"; then # Checks if alias already exists - echo "Alias already exists." - echo - else - echo 'alias linutil="curl -fsSL https://christitus.com/linux | sh"' >> "$ZSHRC_FILE" # Adds the alias - - echo "Alias added." echo fi -} - -# Fish alias setup script -setup_fish() { - FISHCONF_DIR="$XDG_CONFIG_HOME/fish" - FISHCONF_FILE="$FISHCONF_DIR/config.fish" - - echo - - if [ ! -d "$FISHCONF_DIR" ]; then - mkdir "$FISHCONF_DIR" - fi - - if [ ! -f "$FISHCONF_FILE" ]; then # Checks if the default config exists - echo "config.fish not found. Creating a new one." - touch "$FISHCONF_FILE" - echo - fi - - if grep -Fxq 'alias linutil "curl -fsSL https://christitus.com/linux | sh"' "$FISHCONF_FILE"; then # Checks if alias already exists - echo "Alias already exists." - echo - else - echo 'alias linutil "curl -fsSL https://christitus.com/linux | sh"' >> "$FISHCONF_FILE" # Adds the alias - - echo "Alias added." - echo - fi -} - -# TCSH alias setup script -setup_tcsh() { - TCSHRC_FILE="$HOME/.tcshrc" - - echo - - if [ ! -f "$TCSHRC_FILE" ]; then # Checks if the default config exists - echo ".tcshrc not found. Creating a new one." - touch "$TCSHRC_FILE" - echo - fi - - if grep -Fxq 'alias linutil "curl -fsSL https://christitus.com/linux | sh"' "$TCSHRC_FILE"; then # Checks if alias already exists - echo "Alias already exists." - echo - else - echo 'alias linutil "curl -fsSL https://christitus.com/linux | sh"' >> "$TCSHRC_FILE" # Adds the alias - - echo "Alias added." - echo - fi -} - -# Ksh alias setup script -setup_ksh() { - KSHRC_FILE="$HOME/.kshrc" - - echo - - if [ ! -f "$KSHRC_FILE" ]; then # Checks if the default config exists - echo ".kshrc not found. Creating a new one." - touch "$KSHRC_FILE" - echo - fi - - if grep -Fxq "alias linutil='curl -fsSL https://christitus.com/linux | sh'" "$KSHRC_FILE"; then # Checks if alias already exists - echo "Alias already exists." - echo - else - echo "alias linutil='curl -fsSL https://christitus.com/linux | sh'" >> "$KSHRC_FILE" # Adds the alias - - echo "Alias added." - echo - fi -} - -# Nushell alias setup script -setup_nu() { - NUCONF_DIR="$XDG_CONFIG_HOME/nushell" - NUCONF_FILE="$NUCONF_DIR/config.nu" - - echo - - if [ ! -d "$NUCONF_DIR" ]; then - mkdir "$NUCONF_DIR" - fi - - if [ ! -f "$NUCONF_FILE" ]; then # Checks if the default config exists - echo "config.nu not found. Creating a new one." - touch "$NUCONF_FILE" - echo - fi - - if grep -Fxq 'alias linutil = curl -fsSL https://christitus.com/linux | sh' "$NUCONF_FILE"; then # Checks if alias already exists - echo "Alias already exists." - echo - else - echo 'alias linutil = curl -fsSL https://christitus.com/linux | sh' >> "$NUCONF_FILE" # Adds the alias - - echo "Alias added." - echo - fi -} - -# Function to check for installed shells and invoke setups -check_shells() { - echo "Checking if Bash is installed..." - if command_exists bash; then - echo "Found Bash. Adding the alias..." - setup_bash - fi - - echo "Checking if ZSH is installed..." - if command_exists zsh; then - echo "Found ZSH. Adding the alias..." - setup_zsh - fi - - echo "Checking if Fish is installed..." - if command_exists fish; then - echo "Found Fish. Adding the alias..." - setup_fish - fi - - echo "Checking if TCSH is installed..." - if command_exists tcsh; then - echo "Found TCSH. Adding the alias..." - setup_tcsh - fi - - echo "Checking if KornShell is installed..." - if command_exists ksh; then - echo "Found KSH. Adding the alias..." - setup_ksh - fi - - echo "Checking if Nushell is installed..." - if command_exists nu; then - echo "Found Nu. Adding the alias..." - setup_nu - fi -} - -check_shells \ No newline at end of file +done