i use this one a lot
i use this one a lot
i use this one a lot
And then you can immediately solve the issue with programs arbitrarily adding things to your rc file by running:
add exit
programs 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
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_aliases that does alias > ~/.bash_aliases. alias on 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 resorting sed or cut shenanigans on the output of the alias command.
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-here already do that? That or I didn't get what you mean.
alias name-here yields the line alias name-here='contents-of-alias-here' as output, and if you want just the part between the single quotes from that, sed, cut or, 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 somefilespec to watch a directory listing for changes to a file. But commands fed to watch don't go through the alias mechanism, leaving the output somewhat different to my preferences.
It's wordy, but watch ${BASH_ALIASES["ls"]} -l somefilespec mostly achieves what I want.
Unfortunately, watch also causes the stripping of colour codes and I have --color=auto, not --color=force in my ls alias, 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 ls alias is currently:
alias ls='LC_ALL=C ls --color=auto --group-directories-first --time-style="+ %F %T"'
what i do is type out the alias and then hit enter, and then up arrow, quote, ctrl+a, add quote
I'd call it rcappnd instead of add tho
As a fish user i relate to this
As a fish user i relate to this
Because we fish users don't need to write a new function for this, because we already have an option on alias for it?
In man alias in fish:
-s or --save Saves the function created by the alias into your fish configuration directory using funcsave.
In man alias in bash:
OPTIONS
None.
(PS, though, still perhaps handy, if not liking how alias -s saves your aliases.)
I'd much rather keep my rc organised, so I just have a pair of aliases to quickly open it in an editor and another to reload.
alias cfge="$EDITOR ~/.bashrc" alias cfgs="source ~/.bashrc"I basically do the same, but in a single command and I have all my aliases (and functions) in ~/.aliases.
cfg....you wouldn't happen to know anything about context free grammars, would you? i'm a linguist who specializes in syntax, so i use cfgs a lot
This is likely is an abbreviation of "config"/"configuration".
i have
cur() { open /Applications/Cursor.app "$@" }and then
alias cb="cur ~/.bash_rc"