Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a script to set up shell aliases for linutil #354

Closed
wants to merge 8 commits into from
37 changes: 37 additions & 0 deletions tabs/applications-setup/shell-aliases.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/sh
adamperkowski marked this conversation as resolved.
Show resolved Hide resolved

. ../common-script.sh

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
adamperkowski marked this conversation as resolved.
Show resolved Hide resolved
if command_exists ${shells[$i]}; then
adamperkowski marked this conversation as resolved.
Show resolved Hide resolved
echo "Found ${shells[$i]}. Adding the alias..."
adamperkowski marked this conversation as resolved.
Show resolved Hide resolved
config_file="$HOME/${configs[$i]}"
adamperkowski marked this conversation as resolved.
Show resolved Hide resolved
if [ ! -f "$config_file" ]; then
if [ "${shells[$i]}" == "fish" ] || [ "${shells[$i]}" == "nu" ]; then # Change config dirs for specific shells
adamperkowski marked this conversation as resolved.
Show resolved Hide resolved
config_dir="$XDG_CONFIG_HOME/${shells[$i]}"
adamperkowski marked this conversation as resolved.
Show resolved Hide resolved
mkdir -p "$config_dir"
config_file="$config_dir/${configs[$i]}"
adamperkowski marked this conversation as resolved.
Show resolved Hide resolved
elif [ "${shells[$i]}" == "bash" ] && [ -f "/etc/skel/.bashrc" ]; then # Default distro-specific config for bash
adamperkowski marked this conversation as resolved.
Show resolved Hide resolved
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
adamperkowski marked this conversation as resolved.
Show resolved Hide resolved
echo "${aliases[$i]}" >> "$config_file"
adamperkowski marked this conversation as resolved.
Show resolved Hide resolved
echo "Alias added."
else
echo "Alias already exists."
fi
echo
fi
done
9 changes: 9 additions & 0 deletions tabs/applications-setup/tab_data.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,12 @@ script = "rofi-setup.sh"
[[data]]
name = "ZSH Prompt"
script = "zsh-setup.sh"

[[data]]
name = "Shell aliases for linutil"
script = "shell-aliases.sh"

[[data.preconditions]]
matches = false
data = "command_exists"
values = [ "linutil" ]