Outils pour utilisateurs

Outils du site


issue189:c_c

Ceci est une ancienne révision du document !


Welcome back to another edition of FCM, may your year be filled with Ubuntu.

Since we have been spending a lot of time in the terminal, let’s discuss some terminal tips. Bring on the disco fonts as we do some tinkering and a little deeper dive (just so you know what you are copying from some random website) for the total n00bs.

Before we start, this is a how and why, rather than a copy-paste job.

OK, just kidding – we won’t be going that far, I mean lolcat and rotflcat is fun, but you do not want to pump everything through there. Then again, Pimp my Ride was as fake as a $9 note, so we will skip pre-made scripts.

Bash is everywhere, chances of you finding another shell when you connect to another machine are low. Yes, we know things like Fish exist, but bash is functional and usually ships with Ubuntu by default.

Bash is a collection of variables, which simply means things that can change. (Yes, sometimes it does things too, but let’s go with the flow).

Here are some environment variables that an average user may encounter: • PWD – Current working directory. • HOME – The user’s home directory location. • SHELL – Current shell (bash, zsh, etc.). • LOGNAME – Name of the user. • UID – User’s unique identifier. • HOSTNAME – Device’s hostname on the network. • MAIL – User’s mail directory. • EDITOR – The Linux system default text editor. • TEMP – Directory location for temporary files.

To view all environment variables use the “printenv” command to view all environment variables. Since there are many variables on the list, use the less command to control the view:

printenv | less

or we can taste the rainbow, but only once:

printenv | less | lolcat

If you were paying attention, you would see that they are all in caps, and because they are variables, they need to be prefixed by a $ - dollar sign, when you use them in commands; for instance, if I wanted to see my LOGNAME, I’d type: echo $LOGNAME.

Since I always create three users, ed, edd and eddy to test things with, it can be handy for me to see which profile I am in, you may have only one, but the idea stands.

Environmental variables can be stored in a few places, like ~/.bashrc or .bash-profile or just .profile – so be sure to look at what “dotfiles” you have. Dotfiles are hidden configuration files, much like Windows .cfg or .ini files. If you use a fancy GPU-Accelerated terminal, you can set it in your $TERM variable.

There are four commands you need to remember here, to manipulate your environment variables, namely: export, env, set, and unset

A lot of the settings can be set from a modern terminal, and as these vary from terminal to terminal, you may need to dig some. Here we will just look at a standard terminal. Usually things like, unlimited scroll back, can now be a tick-box away, though you may want to set that in the bashrc in your /etc/ folder, but that is out of the scope of this article.

Fonts, colours, background images are just a setting away if you open your terminal preferences. As you can see here, usually on the first three tabs. A word of warning about fonts: you may see a font you like, that looks good on a web page, that looks terrible on the terminal. Always test first!

Let’s talk about customising your prompt:

The prompt simply says, ‘you can type here’. The default prompt on most distro’s out of the box is usually USER@HOST that you set in the PS1 variable. You should see a $ at the end if you are a normal user, or a # if you are root. It does not need to say, user at host, it can say whatever you please. I’ll demonstrate at the end. (Don’t judge, I am not artistic.)

TIP: If you use ‘nerd fonts’ (https://www.nerdfonts.com/) or powerline fonts, you can use fancy symbols to make images in your prompt.

On that note, you can peek at your selected font’s glyphs: https://www.nerdfonts.com/cheat-sheet

We are not going to list out all the backslash-escaped special characters you need to pimp your terminal, as it would just be reinventing the wheel. We will, however, point you to a great resource: https://www.cyberciti.biz/tips/howto-linux-unix-bash-shell-setup-prompt.html as this is an explanation, not a how-to.

Another thing to remember is that modern terminals do not only support colors, but font weights too, so you may have something in bold or dimmed.

Lastly, as a n00b, you may notice that your changes are not happening once you have made them. This is because you need to reload the current session to apply the changes.

This is done by:

source ~/.bashrc

We hope this brings a better understanding and a desire to have your own prompt rather than something you saw on the internet that every second terminal has.

issue189/c_c.1675020602.txt.gz · Dernière modification : 2023/01/29 20:30 de d52fr