Adding aliases for Linux's bash

in #linux6 years ago

First of all, what are aliases?

My friend mentioned this to me a long time ago - in human terms, it is something that allows you to define shortcut commands that can do a big bunch of stuff which would otherwise require you type lines of commands line by line. It's like a good alternative to writing bash files for the tiniest tasks that you like to simplify - like, it would be funny to just write a bash file called cleanup.sh when it only runs two separate rm commands to delete stuff from some place you like. Alternatively, you can just set an alias named cleanup to run those commands for you when you type this alias into your terminal. Sounds not too convincing? You type ./cleanup.sh for the former, and only cleanup for the latter. Less keystokes are always good, right?

I'm writing this because I plan to add some aliases into my system, but before I dive into how I am going to do so (aka a tutorial to do so), I would just like to take a little time to explain why...


In fact, I am still a little puzzled on how Wi-Fi works on Linux - the wireless device is automatically brought up and enabled when I boot the laptop up, but it just refuses to connect to anything until I manually push it off and scan for Wi-Fi networks again. Well, it's not too big of a hassle, but two commands to connect to one Wi-Fi network is just annoying. sudo ip link set wlo1 down and sudo wifi-menu, it would be cool if I can just reduce everything down into wifi and it runs both of them, with the latter automatically following up after the first one is done. Someone I know from Discord told me about the phrase "don't let your dreams be dreams", so...yeah, here we go.

Given that this is actually a popular thing, we can just search on how it can be done...of course, I can scroll my chat history, it should be there, but no. I don't want to scroll 6 months worth of messages while unsure if what I want is really there. Live smart :3

I almost followed what this page is telling me to do, but I scrolled all the way down to the bottom.

image.png

Apparently there is something called .bash_aliases. Learned something new today, but let's start to add things into that file. I don't have that file yet, but it's actually expected, else why would this comment exist?

So here we go. In the file, I added this line.

alias wifi="sudo ip link set wlo1 down && sudo ip link set wlo1 up && sudo wifi-menu"

I purposely set it to pull it down and set it to be up again so that this command works every time - else, it would just fail if the Wi-Fi device is already on at that moment (wifi-menu can't scan a thing without an enabled Wi-Fi device). It should work when I first boot the computer anyways. If not, I can just add another alias called wifistart or something like that...

Since we can do that much with this, let's be a little more lazy. Clipboard commands, underclocking, resetting CPU frequency, performance mode...why not?

image.png

Yes, I know ununderclock is a funny name.

It's worth mentioning that you need to run source .bash_aliases every time after the file gets edited so that the changes are applied. I'm not sure if it will automatically be applied after reboot, but why? Save the hassle and just run that single command to save more time. Reboot takes 10 seconds, the command takes 2. But I have to mention that if you put them into that file called .bash_aliases, you will need to somehow run source .bash_aliases every time you start a new terminal. Probably you can run the command somewhere at .bashrc, but I decided to just dump all of these lines into the latter. Since...it's not too cluttered? It works anyway.

Now, things are a little more productive. Or should I say, a lot...?

image.png
image.png

Finally I don't have to pass anymore arguments. Best of all, all these aliases can be autocompleted :D

If you use Linux too and frequently works with the command line, you would probably love this :3 Go set it up and play it on your own! See you next time~

--Lilacse

Coin Marketplace

STEEM 0.19
TRX 0.15
JST 0.029
BTC 62629.89
ETH 2572.37
USDT 1.00
SBD 2.74