Can't get alias to work

Essentially I’m trying to update mirrors for my CachyOS repos via rate-mirrors and to just do it via one alias (like I do for EOS and Chaotic-AUR), however the sed -i parts of both aliases do not work and are need to tell the repos to get the x86_64_v3/v4 packages. I was wandering if there was an alternative to sed or and thing else.

alias cachyos-mirrors="rate-mirrors cachyos | sudo tee /etc/pacman.d/cachyos-mirrorlist \
&& sudo tee /etc/pacman.d/cachyos-v3-mirrorlist /etc/pacman.d/cachyos-v4-mirrorlist < /etc/pacman.d/cachyos-mirrorlist >/dev/null;" \
sudo sed -i 's|/repo/$arch/|/repo/$arch_v3/|g' /etc/pacman.d/cachyos-v3-mirrorlist \ 
&& sudo sed -i 's|/repo/$arch/|/repo/$arch_v4/|g' /etc/pacman.d/cachyos-v4-mirrorlist"

alias sed_test="sudo sed -i 's|/repo/$arch/|/repo/$arch_v3/|g' /etc/pacman.d/cachyos-v3-mirrorlist && sudo sed -i 's|/repo/$arch/|/repo/$arch_v4/|g' /etc/pacman.d/cachyos-v4-mirrorlist"

Instead of alias, why not use a function?
Also, if you write this as a script, you can debug it with bashdb.

You have unbalanced double quotes (example above), best stick it in a script or function as @manuel says.

1 Like

Try:

alias cachyos-mirrors="rate-mirrors cachyos | sudo tee /etc/pacman.d/cachyos-mirrorlist \
&& sudo tee /etc/pacman.d/cachyos-v3-mirrorlist /etc/pacman.d/cachyos-v4-mirrorlist < /etc/pacman.d/cachyos-mirrorlist >/dev/null; \
sudo sed -i 's|/repo/$arch/|/repo/\arch_v3/|g' /etc/pacman.d/cachyos-v3-mirrorlist \ 
&& sudo sed -i 's|/repo/$arch/|/repo/$arch_v4/|g' /etc/pacman.d/cachyos-v4-mirrorlist"

That ended up happening because I had broke the script into 2 parts to test the sed command.

Only reason this isn’t a function is because I’m just more comfortable with aliases.

The sed commands still do not work in alias form but work when just ran normally.

Functions are straight forward:

funcname() {
do-first
do-next
do-last
the-end
}

## so
mirrors() {
rate-mirrors cachyos | sudo tee /etc/pacman.d/cachyos-mirrorlist 

sudo tee /etc/pacman.d/cachyos-v3-mirrorlist /etc/pacman.d/cachyos-v4-mirrorlist < /etc/pacman.d/cachyos-mirrorlist >/dev/null

sudo sed -i 's|/repo/$arch/|/repo/\arch_v3/|g' /etc/pacman.d/cachyos-v3-mirrorlist

sudo sed -i 's|/repo/$arch/|/repo/$arch_v4/|g' /etc/pacman.d/cachyos-v4-mirrorlist
}

Can’t test - at work :frowning:

Thank you all I’ve just convert all my rate-mirror aliases into bash and fish functions

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.