My version is definitely wordier, but I like it.
add-alias() { if [[ -z "$1" || -z "$2" ]]; then echo "Useage: add-alias <alias_name> \"<command_to_alias>\"" return 1 fi echo "alias $1='$2'" >> ~/.bash_aliases source ~/.bash_aliases echo "Alias '$1' for command '$2' added and sourced." }And, of course, the first thing I test it with is
$ add-alias alias-add add-alias.I have an alias called
save_aliasesthat doesalias > ~/.bash_aliases.aliason its own just dumps all the existing aliases to the terminal in a format that can be parsed by Bash.I felt especially clever when I came up with that and used it to save itself.
Bonus fact:
${BASH_ALIASES["name-here"]}is a way to get at the contents of an alias without resortingsedorcutshenanigans on the output of thealiascommand.Bonus fact:
${BASH_ALIASES["name-here"]}is a way to get at the contents of an alias without resorting sed or cut shenanigans on the output of the alias command.Doesn’t
alias name-herealready do that? That or I didn’t get what you mean.alias name-hereyields the linealias name-here='contents-of-alias-here'as output, and if you want just the part between the single quotes from that,sed,cutor, come to think of it, related shell tricks that do the same thing, would be needed to capture and convert it.${BASH_ALIASES["name-here"]}is a name for what’s only between those single quotes.For example, I have a lot of preferences built into my alias for ‘ls’. Occasionally I want to run
watch ls -l somefilespecto watch a directory listing for changes to a file. But commands fed towatchdon’t go through the alias mechanism, leaving the output somewhat different to my preferences.It’s wordy, but
watch ${BASH_ALIASES["ls"]} -l somefilespecmostly* achieves what I want.* Unfortunately,
watchalso causes the stripping of colour codes and I have--color=auto, not--color=forcein mylsalias, so it’s by no means perfect - I have add the latter if I want colour - but I don’t have to type the rest of the preferences I have in there.FWIW, my
lsalias is currently:alias ls='LC_ALL=C ls --color=auto --group-directories-first --time-style="+ %F %T"'
And then you can immediately solve the issue with programs arbitrarily adding things to your rc file by running:
add exitprograms arbitrarily adding things to your .rc
umm why would you ever do that, i only add to my .rc when i come up with an alias i know i’m gonna use a bunch
When I’m contracting at a client sometimes they have boot strap scripts which push configuration out to your rc files that I want to gate. (Usually b/c I am using my own equipment or doing something a little strange.)
When I’m contracting, I…
uh…
dude this is just a hobby for me, I didn’t get serious about it until like a few months ago. Before that I was recovering from a traumatic brain injury, and before that I couldn’t live on my own, and right before that it was December 2014. My first programming class was back in 2005, and I went to a coding bootcamp, but I haven’t actually made an effort to get hired until my fourth manic episode in November of this year.
Sorry. I didn’t mean to offend and it’s not an attack at the project in anyway - sorry if it came across that way. I think tools to help you manage RC files are great. I just dislike tools that automatically inject themselves automatically (like rvm), my statement was in no regards about the tool you wrote.
My bad. I came across a little harsh but I was mostly just answering your question. I haven’t done the kind of things you do because I’m an amateur.
All good. Do you have a dotfiles repo somewhere?
i’ve just started learning C#, so my dotnet projects don’t exist yet
oh you said dotfiles…oh. well i dunno what that is
what i do is type out the alias and then hit enter, and then up arrow, quote, ctrl+a, add quote


