TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Show HN: Replify – Create a REPL for any command

112 pointsby danielrw7almost 9 years ago

8 comments

kazinatoralmost 9 years ago
Here is my version:<p><pre><code> #!&#x2F;bin&#x2F;bash printf &quot;REPL for %s\n&quot; &quot;$@&quot; notblank() { [ $# -gt 0 ] } while true ; do printf &quot;%s&gt; &quot; &quot;$@&quot; read -r || break; notblank $REPLY || continue; eval command \&quot;\$@\&quot; &quot;$REPLY&quot; done </code></pre> We keep the original parameters and expand them with &quot;$@&quot;. There is a Bash feature that read with no args reads the line into the REPLY variable. We want that to be subject to splitting.<p>If $REPLY expands to nothing, including multiple whitespace, then we just want to print the prompt again: not quit and not run the command with no additional arguments.<p>The eval trick allows $REPLY to undergo expansion and splitting, so that shell syntax can freely be used in the REPL.<p>Test:<p><pre><code> $ ~&#x2F;test&#x2F;replify&#x2F;replify.sh git REPL for git git&gt; rev-parse HEAD 7ac594319e417266764a6bc041b74807f2fe13bd git&gt; branch -r origin&#x2F;HEAD -&gt; origin&#x2F;master origin&#x2F;master origin&#x2F;origin&#x2F;master git&gt; checkout &quot;$TERM $TERM&quot; error: pathspec &#x27;xterm xterm&#x27; did not match any file(s) known to git. git&gt; checkout $TERM error: pathspec &#x27;xterm&#x27; did not match any file(s) known to git. </code></pre> Cute, but not terribly useful without history recall and related features. This wants to be a feature of Bash. The regular Bash repl should have a prefix variable so it can appear to be in a sub-mode for a particular command.<p>Submit a patch for Bash to do this, and maybe you have something. Bash has a hook feature for command execution, IIRC, so this may be somehow doable without modifying Bash.
评论 #12322736 未加载
评论 #12322677 未加载
danielrw7almost 9 years ago
I just found out about a very similar command [1] that has more features.<p>[1] <a href="https:&#x2F;&#x2F;github.com&#x2F;mchav&#x2F;With" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;mchav&#x2F;With</a>
continuationalalmost 9 years ago
It&#x27;s only a REPL in the most trivial sense if it doesn&#x27;t remember variables or results between commands. I suppose it would be easy to store the output in $LAST or $R1, $R2, ..., and then eval the input.
unfletchalmost 9 years ago
Another generic `repl` utility, this one in ruby: <a href="https:&#x2F;&#x2F;github.com&#x2F;defunkt&#x2F;repl" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;defunkt&#x2F;repl</a>
评论 #12321966 未加载
评论 #12322362 未加载
tlrobinsonalmost 9 years ago
Related: rlwrap adds some of readline&#x27;s features like history to REPLs that don&#x27;t have those things out of the box.
seibeljalmost 9 years ago
Neat trick - the only change I made is to exit the while loop by typing &quot;exit&quot;. That way the enter key runs the command with no arguments, and you can exit with control+c or by typing &quot;exit&quot;.
评论 #12322854 未加载
AlphaWeaveralmost 9 years ago
This is pretty cool!
vitocalmost 9 years ago
This could significantly enhance my Docker in the CLI user experience.