[HN Gopher] Jog: Print the last 10 commands you ran in the curre...
       ___________________________________________________________________
        
       Jog: Print the last 10 commands you ran in the current directory
        
       Author : ngngngng
       Score  : 31 points
       Date   : 2021-11-08 22:12 UTC (47 minutes ago)
        
 (HTM) web link (github.com)
 (TXT) w3m dump (github.com)
        
       | simias wrote:
       | I'm not sure I love littering the filesystem with dotfiles (it
       | gives me svn PTSD). Although the advantage is that it'll stay in
       | the directory if it's renamed/moved/compressed etc...
       | 
       | But then the inconvenient is that it'll stay in the directory if
       | it's renamed/moved/compressed etc... Better be careful if you
       | tend to input sensitive data on the command line.
        
       | csdvrx wrote:
       | This is for zsh.
       | 
       | If you are using bash, here's an alternative to save the
       | commands, their start time, stop time, and eventual error code,
       | in a SQLite database that you can query with fzy:
       | https://github.com/csdvrx/bash-timestamping-sqlite
       | 
       | With the mappings, Ctrl-R will do a search history restricted to
       | the current directory _AND_ to successful execution (return ==
       | 0), while Ctrl-T will do a global history search for all
       | directories and return values.
       | 
       | EDIT: to answer a question I've seen posted below, if you want to
       | only navigate the commands from the current directory, do Ctrl-R
       | then use the arrows: the command are by default sorted by the
       | time they where previously run. If you then start typing letters,
       | it will filter these commands using fzy.
        
       | kbd wrote:
       | I always respect when people take the time to put a small but
       | useful thing like this up in a repo by itself.
       | 
       | It has always been a frustration that the current working
       | directory metadata isn't saved along with history entries, so you
       | can never really reconstruct what was run.
       | 
       | Edit: I should really try out https://github.com/larkery/zsh-
       | histdb. There's no reason a modern system's history shouldn't
       | store start and finish timestamps, return code, current working
       | directory, etc.
        
         | visarga wrote:
         | > It has always been a frustration that the current working
         | directory metadata isn't saved along with history entries, so
         | you can never really reconstruct what was run.
         | 
         | And git branch if applicable.
        
           | version_five wrote:
           | Yes, underrated idea. I recently kept a spreadsheet of
           | commands I'd ran, which branch, and where the output went. It
           | would be great to see this tracked.
        
             | visarga wrote:
             | I keep shell sessions logged to individual files, collected
             | for years back. I often reuse past commands. But if the
             | command run from a git folder it's hard to tell which
             | branch.
        
         | kortex wrote:
         | Zsh-histdb is one of my absolute lifesavers. It's literally the
         | first thing I install on new systems, after zsh itself and oh-
         | my-zsh. I could never go back to working without it.
        
           | arthurcolle wrote:
           | Thanks I'll check this out! Any other useful zsh plugins you
           | want to call out? It's been my favorite shell for a while
           | mostly because of OMZ but always interested in some new
           | magic!
        
         | ngngngng wrote:
         | > It has always been a frustration that the current working
         | directory metadata isn't saved along with history entries
         | 
         | Agreed. Wild that's not built in at this point.
        
         | simias wrote:
         | That's a cool idea. I have a similar, but less elegant setup: I
         | just append every single command that I type to a global
         | (synchronized between machines) history file, one file per
         | month, then I use fzf to search through these when I need
         | something (which is plugged into the usual ^R shell binding).
         | Every command I've typed over the past couple of years is
         | accessible immediately that way.
         | 
         | It's not scoped by directory though, but I'm not sure I'd
         | personally need that feature.
        
       | barosl wrote:
       | This is such a great idea, but what's even more useful would be
       | to make arrow keys only traverse the commands ran in the current
       | directory. Would there be any prior art?
        
         | ngngngng wrote:
         | I like it. I'll add that to the to-do list.
        
       | zhs wrote:
       | Why not use fzf? https://github.com/junegunn/fzf
        
         | jez wrote:
         | Using fzf to power ^R (reverse history search) is such a huge
         | productivity win. Also it has the side effect of showing you
         | the last 10 commands without any other config or setup.
        
       | mongol wrote:
       | I am unsure how shell history works when there are many terminals
       | open at once. The history within a single shell is not mixed up
       | by this, but I have never learned what happens when the terminals
       | closes. I often wondered what would be the ideal way for history
       | to work with many shells.
        
       | ngngngng wrote:
       | I've posted this here in a comment before, but I just made some
       | small updates and figured I'd submit. A while back I wished I
       | could see what commands I'd run in a directory I hadn't worked in
       | for months. I found a couple projects that could accomplish this
       | but consisted of thousands of lines of code and a database
       | install. I wanted a more "unix" solution so I built this.
        
       | alhirzel wrote:
       | CTRL+R is a bigger timesaver for me, but I could see this being
       | useful if my memory weren't as keyword-based.
        
       ___________________________________________________________________
       (page generated 2021-11-08 23:00 UTC)