Keep track of 1000 + aliases

Vektor

Active Member
Joined
Oct 15, 2023
Messages
100
Reaction score
59
Credits
686
I am curious how everyone here keeps track of all the aliases they have. So many to forget. Is there an app to do this or do you refer to a text file.


I have chosen to echo mine in various .bashrc-xxx files and choose them with the numpad 00 - 10 as of this time. 00 is like a table of contents showing what is available. The screenshots and fikes are here


Link ---



I just double click , paste then enter and Wallah!


This idea is basically a launcher for anything on the operating system but keeps the overhead low.


Any comments are welcome.


Vektor
 
Last edited:


I don't use a huge number of aliases, so I have all of my aliases in my ~/.bashrc.
You can see the number of aliases you have set up via the command:
alias | wc -l
I can see I have 78 aliases set up. Which is quite a lot, but certainly nowhere near thousands.

But if you have a really large number of aliases, you could put them in a separate .bash_aliases file in your home directory. That way they're all together in a discrete file and won't be polluting/complicating your .bashrc.

To see what aliases you have defined, simply use the alias command and it will list all of the aliases that you have set up.

If you have a large number of aliases, consider piping the output from alias to a pager like more, or less, or to a terminal based browser like w3m or lynx.
e.g.
Bash:
alias | less
or
Bash:
alias | w3m

That way the pager/browser will receive the output from the alias command and you can scroll through your list of aliases to find the aliases you're looking for.

Regarding managing aliases - I don't see any point in numbering your aliases, or anything like that.
Numnbering your aliases isn't going to make them memorable. Give them short names that help you to remember what they do.

I sometimes forget which aliases I have set up. If I ever want to know what aliases I've got set up for a particular tool, I'll pipe the output of alias to something like grep or ag (AKA The Silver Searcher - a multi-threaded grep on steroids) to search for matching aliases.

So for example, I use cmus (terminal based audio player) a LOT. I have a bunch of aliases set up for various tasks in cmus.
Rather than looking through a list of all 78 of my current aliases, I can see any aliases which use cmus by entering the command:
Bash:
alias | \grep cmus

And that yields me the following list of aliases:
Code:
alias cmaddl='cmus-remote -l'
alias cmaddp='cmus-remote -P'
alias cmaddq='cmus-remote -q'
alias cmstats='cmus-remote -Q'
alias next='cmus-remote -n;nowplay'
alias pause='cmus-remote -u;'
alias play='cmus-remote -p;nowplay'
alias prev='cmus-remote -r;nowplay'
alias resume='cmus-remote -u;nowplay'
alias shf='cmus-remote -S; echo "Shuffle: $(cmus-remote -Q | \grep shuffle | awk '\''{ print $3 }'\'')"'
alias stop='cmus-remote -s'

In the above, I can see all of the aliases I've set up for cmus.
Again, if I potentially had a large number of aliases set up for a particular command - I might also consider piping the output to a pager.

So for example, if I have a couple hundred aliases set up which use ssh to connect to different servers, I might use something like
Bash:
alias | \grep ssh | w3m
Where w3m is my preferred terminal based pager/browser. You could swap that out for less, or more, or lynx, or whatever.

So for me at least, managing my aliases is just down to using the alias command in conjunction with other standard tools to see the aliases that I'm interested in.
If I want to add a new temporary alias, for the life of the current terminal session - I'll just quickly enter a new alias. If I want to temporarily remove an alias, I'll use the unalias command.

If I want to add, a new permanent alias (or remove a permanent alias), I'll edit my .bashrc and then reload/re-source it in any open terminals to apply it. In fact, to do this I actually use an alias called bashr, which looks like this:
Bash:
alias bashr='vim ~/.bashrc; . ~/.bashrc'
Above will open my .bashrc in vim. I can edit my .bashrc to make any changes I want (including adding/removing aliases). After saving and exiting vim, the running terminal then uses the . builtin to re-load my .bashrc - allowing any changes to be picked up in the currently running shell.

Going back to the topic of making your aliases memorable:
For a while I called it basher (which in my head stands for .BASHrc Edit and Re-init - I find that using mnemonics and acronyms in your aliases can sometimes help you to remember them.).
Eventually, I dropped the e and renamed it to bashr, purely to save me from having to enter one extra character. What can I say? I'm supremely lazy! The less characters I have to type to get something done, the better!
As much as I like entering as few characters as possible, I wouldn't be so keen on numbering all of my aliases because it would be much more difficult to remember what each one did.

So to round up, the best way of managing aliases (in my opinion) is simply to use the alias command in conjunction with other standard tools. And to give your aliases short names that help to describe what they do.

I do have some really short, one character aliases:
Bash:
alias j='jobs -l'
alias l='ls -CF --color=auto'
alias v='vim'
Again - using single letter aliases might not very memorable. I remember these OK. But anything that is short and memorable will work.

My only golden rule with aliases is:
If the name of an alias contains more characters than the actual command/commands it aliases - don't bother aliasing it!
 
Last edited:
I have one main alias Brickwizard, I have been called that for over 40 years so is sensible to keep as my face to the world. I have 2 others [one for friends and family only and one for when I have to sign up to a company I may never use again, they also have different e-mails]
 
@Vektor
On looking at the .png files of VIC-TERMINAL-LAUNCHER at the link in post #1, it wasn't clear to me how this was used to give effect to 1000 aliases, but it looked interesting :).

It's worth noting that the bash manual is very supportive of functions as suitable replacements for aliases. Along with that notion is the sense that functions have greater power than aliases, if the user wants to make use of it. These statements, in relation to aliases, are from the bash man page under the heading: ALIASES:
There is no mechanism for using arguments in the replacement text (i.e. the text of the alias). If arguments are needed, use a shell function
....
For almost every purpose, aliases are superseded by shell functions.

In my own case, both aliases and functions are used, but it's clear that all the aliases used could be turned into functions, but the reverse is not the case.

A few aliases used are common ones:
Code:
alias ll='ls -lh'
alias ll.='ls -lhd .*'
alias l.='ls -d .*'
alias xpdf="xpdf -rv"
alias who="who -aH"
alias rxvt="rxvt &"
alias cal="ncal -b"
alias fff="finger"

Conversion of alias to function is straight forward, for example the alias fff for the output of finger::
Code:
fff() { finger; }

Additionally, functions can use the dynamic aspect of scripting, for example:
Code:
rem() {
mv "$1" ~/.local/share/Trash/
}

This function named: rem, will remove a single file named on the command line to the allocated Trash directory.

None of this means that aliases are altogether redundant, but thinking in terms of functions offers more to the user I think.
 
Last edited:
I keep track of mine by the simplest method I can - I simply forget they exist. :)

I have only nine aliases defined, all set up in the default .ashrc in my distro.

Three are shortcuts for options to ls.
Three are safeties for rm, cp and mv, adding -i to each.
Two are output formatters for df and du, adding -h each.

One is a shortcut to cd to a (distro-specific / installation-specific) system directory path which is a bit cumbersome to type. Since I, until about ten minutes ago, had no idea this alias existed, I long ago created a symlink that makes it unnecessary.
 
Hi osprey

The different pages contain the aliases. I simply copy (double click) and paste back into the terminal and the alias can open a file browser or a text editor or whatever it is set to do. Just a bunch of shortcuts. I have looked for a program launcher to display many items at one time and cannot find any that compare. The outline of folder hierarchies is the biggest reason for doing this.

Vektor
 
I have updated the G-Drive share with two files. Place them with your .bashrc and add

. /root/.bashrc-MAIN-ROOT
alias 06='/root/.bashrc-06'

to your .bashrc file.

I use KDE with Dolphin and Kwrite, so if you use another DE the pointers will need to be changed.

As usual, I hope someone finds this idea useful or ridiculous.

Vektor
 
I would use as less aliases as possible as I found the better way to handle this is through scripting. If using "commands" from the command line, it's hard enough to keep track of files and commands in or not in your PATH, I would avoid having an additional layer of redefined commands. It's also hard to share single aliases with other machines, while scripts and file you just copy one by one as desired. I think aliases are an administration nightmare.
 
Once again I have updated the GDrive link in my first post and included the files I am using at this point in time.

I really like the freedom of not depending on an OS with any desktop.

Am working to change all the pointers for dedicated programs and use "xdg-open" to let the OS determine the default program.

This is so cool.

Vektor
 

Members online


Latest posts

Top