Live data from Hacker News

Show HN: Redo – Command line utility for quickly creating shell functions

github.com

21–30 of 32 posts

Re: Show HN: Redo – Command line utility for quickly creating shell functions

#21
post #15

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 sam…

I've always just written that as \ls to call the non-alias

Re: Show HN: Redo – Command line utility for quickly creating shell functions

#23

I do this whenever working on terminal. 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.

You should combine this into one command.

http://www.modernperlbooks.com/mt/2009/10/remove-the-little-...

Re: Show HN: Redo – Command line utility for quickly creating shell functions

#24
post #15

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 sam…

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 shell functions

#26
post #19

Earlier quoted context omitted.

Note there is one possibly important difference; aliases are resolved before globbing.

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 "$@" }

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 shell functions

#27
post #19

Earlier quoted context omitted.

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 "$@" }

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

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 shell functions

#28
post #19

Earlier quoted context omitted.

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 "$@" }

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

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 shell functions

#29
post #15

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 sam…

I've always just written that as \ls to call the non-alias

Won't work with functions, so be careful.

    $ function ls () {
    > echo denied
    > }
    $ ls
    denied
    $ \ls
    denied

Re: Show HN: Redo – Command line utility for quickly creating shell functions

#30
My workflow looks like this:

hack hack, then run

    nuscript-bash something
Hit C-x C-h, select some lines, edit, then run

    something
To do maintenance:

    edcom something
I wrote a little more about it here: https://blag.felixhummel.de/basics/bash/wrapper-scripts.html
Post reply on HN