8 ms·
Show HN: Redo – Command line utility for quickly creating shell functions
- opan 5y agoThis 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.
- silentprog 5y agoThank 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.
- gjvc 5y agostick with functions
- silentprog 5y agoCare to elaborate?
- gjvc 4y agono
- Crespyl 5y agoNot to be confused with the redo build system[0] [0] https://redo.readthedocs.io/en/latest/ https://redo.readthedocs.io/en/latest/
- junkblocker 5y agoI use this https://github.com/erichs/composure https://github.com/erichs/composure which seems to do more.
- qorrect 5y agoVery cool
- buu700 5y agoCurrently, 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.
- silentprog 5y agoInteresting 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 https://github.com/junegunn/fzf), I can highly recommend it!
- buu700 5y agoHuh, apparently I've already starred that. It must have been posted on HN at some point.
- cyberge99 5y agoInteresting, 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.
- buu700 5y agohttps://unix.stackexchange.com/a/17587/14123 https://unix.stackexchange.com/a/17587/14123
- westurner 5y agoFrom https://westurner.github.io/hnlog/#comment-20671184 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 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/usrlog.sh https://github.com/westurner/dotfiles/blob/master/scripts/us...
- chubot 5y agoFWIW 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!
- emmelaich 5y agoNote there is one possibly important difference; aliases are resolved before globbing.
- chubot 5y agoHm 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 "$@" }
- emmelaich 5y agoI 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 https://aplwiki.com/wiki/Ivy
- stevenhuang 5y agoI 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.
- bmn__ 5y agoYou should combine this into one command. http://www.modernperlbooks.com/mt/2009/10/remove-the-little-pessimizations.html http://www.modernperlbooks.com/mt/2009/10/remove-the-little-...
- unixhero 5y agoThis reminds me of what I had in 1995 with the 4DOS.COM command interpreter (command.com replacement).
- replwoacause 5y agoLove it! I am going to start using it immediately.
- deleted 4y ago[deleted]
- felixhummel 4y agoMy 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 https://blag.felixhummel.de/basics/bash/wrapper-scripts.html