Re:Show HN: Redo – Command line utility for quickly creating...
by emmelaich on Friday April 01, 2022 @07:19PM
(#30884303)
Note there is one possibly important difference; aliases are resolved before globbing.
Re:Show HN: Redo – Command line utility for quickly creating...
by chubot on Friday April 01, 2022 @10:57PM
(#30885509)
Hm what's an example of where you might want to take advantage of that?
In practice
alias 'lspy=ls *.py'
seems to be interchangeable with lspy() {
ls *.py "$@"
}
Re:Show HN: Redo – Command line utility for quickly creating...
by emmelaich on Saturday April 02, 2022 @08:39PM
(#30893053)
I have a semi-made desk calculator with prefix notation.
You can make it an alias of * , / etc, so ...
$ * 4 6
24
$
It would keep it's own stack, but let a persistent process do the actual maths.The persistent process could almost any repl of python, ruby etc.
Or use a 'real' calculator like Pike's ivy; https://aplwiki.com/wiki/Ivy
Re:Show HN: Redo – Command line utility for quickly creating...
by emmelaich on Saturday April 02, 2022 @08:44PM
(#30893091)
Unfortunately, ( is not a valid alias name, so lispy things are difficult.
[ is a valid function name tho so fun could be had there.
Re:Show HN: Redo – Command line utility for quickly creating...
by emmelaich on Saturday April 02, 2022 @08:47PM
(#30893114)
Also = is a valid function name.
So you could use = to start the calc, and use infix or postfix notation.
Re:Show HN: Redo – Command line utility for quickly creating...
by abathur on Friday April 01, 2022 @10:39PM
(#30885439)
You can do some wild ~metaprogramming stuff with aliases.
Re:Show HN: Redo – Command line utility for quickly creating...
by jolmg on Friday April 01, 2022 @11:05PM
(#30885537)
Do you have examples of something neat?
Re:Show HN: Redo – Command line utility for quickly creating...
by silentprog on Saturday April 02, 2022 @03:37AM
(#30886508)
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.
Re:Show HN: Redo – Command line utility for quickly creating...
by 8n4vidtmkvmk on Friday April 01, 2022 @11:52PM
(#30885725)
I've always just written that as \ls to call the non-alias
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!