Golang context based shell history

xuanbao · · 503 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>I find myself needing the git branch I was on when I executed a statement. Or, needing to see the STDOUT text that the command displayed. Simply using unix history cmd does not suffice. Is there a tool for this in golang? In any language? Curious, as I might make it my weekend project and write it in go :)</p> <hr/>**评论:**<br/><br/>epiris: <pre><p>This is easy to do, change your history format to begin with the current working directory, I do this myself. From there you could query the hist file however you wanted to. For example add a alias in your bash rc that makes &#34;ctx&#34; into history | grep &#34;<sup>${PWD}&#34;.</sup></p></pre>knotdjb: <pre><p>You want to capture the history of your session including the stdin/stdout? There&#39;s <a href="https://linux.die.net/man/1/script" rel="nofollow">script(1)</a> for that, or <a href="https://asciinema.org/" rel="nofollow">asciinema</a> (which went from python-&gt;go-&gt;python).</p></pre>dasizzle007: <pre><p>but also the git branch I was on, and the time. Something extendable so that I can include functionality I may need in the future.</p></pre>knotdjb: <pre><p>So asciinema uses an <a href="https://github.com/asciinema/asciinema/blob/master/doc/asciicast-v1.md" rel="nofollow">asciicast</a> format which includes duration for each command. You can probably shove a start timestamp on the file itself, and you got something with the time.</p> <p>Anyway, if you want to do you own, go for it.</p></pre>kemitche: <pre><p>Is this something you just need for seeing what happened in your shell? Is your shell scrollback enough, but you also want to know the branch? You could set your PS1 (shell prompt) appropriately so that it shows current time &amp; git branch.</p></pre>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

503 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传