Live data from Hacker News

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

github.com

11–20 of 32 posts

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

#11
post #2

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

stick with functions

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

#12
post #7

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…

Interesting, I think there’s a shopt that I’m missing. When I append a comment, it’s not recorded in bash history, as I’d expect.

https://unix.stackexchange.com/a/17587/14123

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

#13
post #7

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…

From https://westurner.github.io/hnlog/#comment-20671184 ::

> 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

  stid \#tutorial; echo "$_TERM_ID"

  tail -n11 $_USRLOG
  ut -n11

  grep "$_TERM_ID" "$_USRLOG"
  usrlog_grep "$_TERM_ID"
  ug "$_TERM_ID"

  usrlog_grep_parse "$_TERM_ID"
  ugp "$_TERM_ID" # `type ugp`
usrlog.sh: https://github.com/westurner/dotfiles/blob/master/scripts/us...

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

#14
post #11

Earlier quoted context omitted.

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

stick with functions

Care to elaborate?

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

#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 same name as the command. Otherwise you'll get an infinite loop of the function trying to call itself!

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

#16
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…

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

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

#17
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.

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

#18
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…

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

You can do some wild ~metaprogramming stuff with aliases.

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

#19
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…

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

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

#20
post #18

Earlier quoted context omitted.

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

You can do some wild ~metaprogramming stuff with aliases.

Do you have examples of something neat?
Post reply on HN