1. 47
  1.  

  2. 11

    Good command, but I think I prefer it sorting in reverse chronological order, like git log. To make this change, simply prepend “-” to the --sort key. Added with that small modification to my bag of $HOME tricks here.

    1. 6

      I like it.

      This general space (maybe “reheating cold context”?) has been interesting to me (read: my achilles’ heel?) for a while.

      Things I already do or have done:

      • open a terminal tab for a distinct project (sometimes more than one, for distinct sub-tasks/sub-projects)
      • keep tabs around for ongoing but inactive projects, so that I can review what I was doing
      • working on a project-oriented shell-history module to help sand down some rough edges for the above
      • working on an ST3 extension to sand down some sharp edges around ST3 projects (group multiple to open/close them together; have a persistent list of these meta projects that won’t get scrolled off of the recent-project list each time I open a bunch of related work projects…)

      I’ve also daydreamed about:

      • some sort of editor plugin/extension that keeps a contextual log of what you’ve been touching
      • some affordance for annotating shell history, and probably for grouping+annotating common command sequences (probably eventually part of or paired with the shell-history module) that (ideally) does things like:
        • passively notice common patterns and prompt me to annotate them (I notice you run these 4 commands in this order a lot; would you like me to help you annotate it, create a shortcut (script? function? alias?) and remind you about it when I see you manually run the commands?)
        • make it easy to see annotations + context (frequency, location, project, etc) by command/directory/project/etc.
        • maybe notice when I’m fumbling around with a command (you probably don’t need two guesses :)
        • maybe append/prepend/wrap/annotate the syntax help or manpage with my own invocations
      1. 12

        I am a bash history junkie somehow; I’d rather have one-liners in my history when I notice they are long but simple to come up with (e.g. find usages with several options). That means I don’t need to pollute $PATH with writable directories in order to reach these commands from the current working directory.

        So, far from being an automated process, when I notice I will need to run my-lengthy-one-liner more than once over the next couple of hours, I annotate them like this:

        : mnemonic ; my-lengthy-one-liner
        

        Then I can search for mnemonic on my shell history anytime I want to use that command.

        1. 2

          Oh, wow, that’s brilliant, thanks for sharing!

        2. 2

          maybe notice when I’m fumbling around with a command (you probably don’t need two guesses :)

          perhaps you want one or both of tldr and thefuck?

          brew install tldr

          https://github.com/nvbn/thefuck

          1. 2

            Some useful tips there. I also keep tabs around (browser and terminal).

            Terminal: it certainly helps being able to rename the title so context shows up in the tab. There is also a way to add colour to iTerm2 tabs for almost a tag system. 1

            Browser-wise I use Tree-Style Tabs which allows me to set a project “parent” tab, say the git repo, and then collapse it’s children when I’m not working on it.

            As for shell history, I often find myself doing things along the lines of

            % command -with weird -flags i -wont remember # some additional context here about what I’m doing so all my notes get written to my eternal shell history (which is also in git)
            
          2. 3

            Nice, I’ve got something similar. It’s unfortunate git branch doesn’t support this via some flag. I also find it useful to set alias branch = branch -vv, then it also displays the relation to origin and the commit message header next to the branch name.

            1. 2

              There’s a variant of this, git recent from https://csswizardry.com/2017/05/little-things-i-like-to-do-with-git/ which is worth looking at if you like wip but also want to see the latest commit message first-line.

              1. 2

                Oh, boy. This just reminds me that I need to clear out a lot of branches on my work computer…

                1. 2

                  I use this monstrosity, which I found here https://ses4j.github.io/2020/04/01/git-alias-recent-branches/

                  lb = !git reflog show --pretty=format:'%gs ~ %gd' --date=relative | grep 'checkout:' | grep -oE '[^ ]+ ~ .*' | awk -F~ '!seen[$1]++' | head -n 10 | awk -F' ~ HEAD@{' '{printf(\"  \\033[33m%s: \\033[37m %s\\033[0m\\n\", substr($2, 1, length($2)-1), $1)}'
                  

                  It does almost the same thing as the one in the OP. The difference is it shows every branch you’ve checked out, rather than every branch you’ve actually changed. Granted, the alias is insanely ugly, but I find it more useful as a list of recent “work in progress”. That’s because my definition of “work” includes reading code as well as writing it.

                  1. 1

                    Interested to hear what you all’s most useful git alias in your arsenal is.

                    1. 2

                      For myself, I wrote a small fuzzy branch finder (really just figured out the command to get fzf to do fuzzy branch matching). Now I don’t have to remember branch names! The line from my git config:

                      !git for-each-ref --format='%(refname:short)' refs/heads | fzf | xargs git checkout
                      

                      I have it aliased to fco (Fuzzy CheckOut).

                    2. 1

                      I am using this alias:

                      branches = "!f() { git for-each-ref --sort=committerdate refs/heads/$1** refs/heads/$1* refs/heads/$1/** --format='%(HEAD) %(color:yellow)%(refname:short)%(color:reset) — %(contents:subject) (%(color:green)%(committerdate:relative)%(color:reset))'; }; f"
                      

                      As I am using prefixes for branch names, I can do git branches fix/ for example.

                      1. 1

                        Rather than just git commits (which I always forget while I’m knee deep in a session) I think I’d rather see most recent lines changed, especially when I’m debugging a failed build. With system APIs you can get files edited, so having a view of most recent files edited (not by git commit) and then showing git diffs within that time (including uncommitted changes) might be super useful for my workflow.