ajgreeny wrote: ⤴Thu Jun 24, 2021 11:39 am
I am quite happy to admit that I use a lot of aliases, though I also run command
alias fairly often to remind myself what is possible using them as it is quite easy to forget some of them.
You might like my wee
LAD (List & Describe) program, then. It basically lists (sorted) and describes your aliases and functions in a pretty and easy-to-digest way. You have to write the descriptions yourself, of course, but once it's done, it's done. Here's what it shows for me:
Code: Select all
$ lad
FUNCTIONS (/home/ichy/.bash_functions)
bins - A lite version of what lsbins(1) achieves.
brn - Batch-rename a bunch of files or directories.
suppress - Execute command ($1) and omit specified ($2) output.
touched - Tell the user how many commits have touched the given file(s).
ALIASES (/home/ichy/.bash_aliases)
alertme - Sound the bell and flash the terminal (white) thrice.
apt-get - Much nicer output for the apt-get command.
bat - Output the percentage of battery power remaining.
sd - Change the CWD to: /media/$USER
I have plenty more than what is listed, but I drastically shrunk it to save taking up tons of space.
Lady Fitzgerald wrote: ⤴Fri Jun 25, 2021 6:13 pm
For my commands I use a lot I just place them in /usr/local/bin/ and chmod +x them.
Is there a better way?
Depending on the use-case, yes.
An
alias is a string (a single unit of one or more characters) which acts as a placeholder that is expanded to its true value (one or more commands to which it's assigned) when the user enters the string on the command-line. For example: I have an alias called
sd
('sd' being the string), which, when I enter it on the terminal, gets expanded to the command
cd /media/$USER
prior to execution.
This:
Becomes this:
Then
that is executed.
The reason I say it depends on the use-case is because your method affects
all users on the system, which is especially not ideal in professional environments or for aliases involving some sort of sensitive information. Furthermore, if you install something which overwrites one of those files, you lose the ability to use it. It can also be easier to transfer your BASH configuration along with all of your aliases than it is to transfer each of your '/usr/local/bin' scripts.
While more advanced, another solution, which is sometimes a much better solution, is to use functions. Finally, for more complicated matters, people write scripts or programs, and it's then they typically install them into
$PATH
directory, or, if it's just for personal use, '~/bin' is a popular location.
To clarify,
$PATH
is an environment variable storing primary directories the system looks for executable files to be executed as
commands, such as
mkdir(1),
ls(1), and
find(1). Something you might find interesting to know, is that builtins, aliases, and functions all take priority over
$PATH
executables.