FWIW the title says "functions", but it apparently uses aliases.
Shell functions have all the same functionality as aliases and they'll catch more syntax errors upon "source myscript". Example:
ls() {
command ls --color=auto "$@"
}
is equivalent to
alias ls='ls --color=auto'
but IMO less error prone. You also get syntax highlighting.
The only tricky thing is to remember the 'command' prefix if the "alias" has the same name as the command. Otherwise you'll get an infinite loop of the function trying to call itself!
It generates functions. Though not with a “$@“ at the end, so passing additional arguments at this moment is not supported. I also run a syntax check before the function is added to the file.
Currently, I'll append a comment to a frequently used command for easy searching from my history. For a simple example, I can access `git diff -w ; git diff -w --cached # gitdiff` by pressing Ctrl+R and typing `# gitd`.
For commands I use frequently or that are clunky to maintain as one-liners, I'll convert them into functions in my bashrc.
This seems like the best of both worlds in many ways, or at least is a great third option to have.
> I log shell commands with a script called usrlog.sh that creates [per-]$USER and per-virtualenv tab-delimited [$_USRLOG] logfiles with unique per-terminal-session identifiers [$_TERM_ID] and ISO8601 timestamps; so it's really easy to just grep for the apt/yum/dnf commands that I ran ad-hoc when I should've just taken a second to create an Ansible role with `ansible-galaxy init ansible-role-name ` and referenced that in a consolidated system playbook with a `when` clause. https://westurner.github.io/dotfiles/usrlog.html#usrlog
Interesting way of aliasing right from where you use it! I actually replaced my default shell history search with fuzzy search using (https://github.com/junegunn/fzf), I can highly recommend it!
alias erc="vim ~/.bash_aliases"
alias src="source ~/.bash_aliases"
Whenever I need to add or modify some shell function or alias (or even make a quick note) I type erc to open the alias file. Then I type src to load it. Very handy.
This looks very cool. I use shell aliases heavily on all my devices and try to avoid typing out the same one-liners more than once or twice when possible.
Thank you! Currently the software is very much alpha, so some bugs are expected. I also use shell aliases a lot, though redo is currently not creating aliases but shell functions. In the future I want to add support for creating actual aliases as well instead of shell functions. A simple solution would be to not create a function but an actual alias and chain the commands with &&, this would work but then you lose the power to edit the function and for example have arguments to some commands and not to others.
Crespyl|3 years ago
[0] https://redo.readthedocs.io/en/latest/
unknown|3 years ago
[deleted]
chubot|3 years ago
Shell functions have all the same functionality as aliases and they'll catch more syntax errors upon "source myscript". Example:
is equivalent to but IMO less error prone. You also get syntax highlighting.The only tricky thing is to remember the 'command' prefix if the "alias" has the same name as the command. Otherwise you'll get an infinite loop of the function trying to call itself!
emmelaich|3 years ago
silentprog|3 years ago
8n4vidtmkvmk|3 years ago
buu700|3 years ago
For commands I use frequently or that are clunky to maintain as one-liners, I'll convert them into functions in my bashrc.
This seems like the best of both worlds in many ways, or at least is a great third option to have.
westurner|3 years ago
> I log shell commands with a script called usrlog.sh that creates [per-]$USER and per-virtualenv tab-delimited [$_USRLOG] logfiles with unique per-terminal-session identifiers [$_TERM_ID] and ISO8601 timestamps; so it's really easy to just grep for the apt/yum/dnf commands that I ran ad-hoc when I should've just taken a second to create an Ansible role with `ansible-galaxy init ansible-role-name ` and referenced that in a consolidated system playbook with a `when` clause. https://westurner.github.io/dotfiles/usrlog.html#usrlog
usrlog.sh: https://github.com/westurner/dotfiles/blob/master/scripts/us...silentprog|3 years ago
cyberge99|3 years ago
junkblocker|3 years ago
stevenhuang|3 years ago
The mnemonic is erc=edit rc, src=source rc.
alias erc="vim ~/.bash_aliases" alias src="source ~/.bash_aliases"
Whenever I need to add or modify some shell function or alias (or even make a quick note) I type erc to open the alias file. Then I type src to load it. Very handy.
bmn__|3 years ago
http://www.modernperlbooks.com/mt/2009/10/remove-the-little-...
felixhummel|3 years ago
hack hack, then run
Hit C-x C-h, select some lines, edit, then run To do maintenance: I wrote a little more about it here: https://blag.felixhummel.de/basics/bash/wrapper-scripts.htmlopan|3 years ago
silentprog|3 years ago
unixhero|3 years ago
replwoacause|3 years ago
qorrect|3 years ago