ah is better than history

    It turns out that I spend enough time in the console (terminal), sometimes even more than I would like. Sometimes I even execute some commands there and carefully study their conclusion. It often happens that you have to return to the conclusion of a particular team, and it is constantly lost: either the terminals are slammed, then you tmuxclose the window, or the conclusions of other teams have long ago hammered and buried the very useful line.

    In order to save the output of a utility, I, like many, used it tee. It worked, but constant bustle among the endless error.log, out.log, output.log, err.loglog.log,lll.txtand tp if not driving crazy, then madly annoying; Instead of keeping some order, it was constantly tempting to create a New Folder (1), where to bury these same logs, periodically backing up the burial grounds: the order presupposed some sort of systematization, and in the midst of work I really did not want to remember what to name your file.

    Then I wrote ah , a tiny utility that greatly improved my life.

    ah was supposed to be a small addition to the built-in history command, which is in almost every shell; however ah can only work with two: zsh (since I use it myself) and bash (since almost everyone who does not use zsh uses it). This is by no means a substitute for history, but rather an addition to it. ah, basically, can do 4 things: show history, save the output of command streams, bind it to a number in the history, and show on request. In addition, there is such a trifle as bookmarks (any entry from the history can be given a name).

    Saving command output


    ah knows how to save the combined output of a command, and does the cataloging itself. In the simplest case, just do this:

    ➜ ah t -- find ./app -name "*.go" -type f
    ./app/historyentries/get_commands.go
    ./app/historyentries/parser.go
    ./app/historyentries/keeper.go
    ./app/historyentries/history_entry.go
    ./app/historyentries/history_processor.go
    ./app/environments/environments.go
    ./app/utils/re.go
    ./app/utils/logging.go
    ./app/utils/synchronized_writer.go
    ./app/utils/exec.go
    ./app/utils/utils.go
    ./app/commands/bookmark.go
    ./app/commands/remove_bookmarks.go
    ./app/commands/gc.go
    ./app/commands/list_trace.go
    ./app/commands/tee.go
    ./app/commands/execute.go
    ./app/commands/show.go
    ./app/commands/list_bookmarks.go
    ./app/slices/slices.go
    


    The output is saved (and combined, both with stdout and stderr), and it can be requested later. What is the difference from, say, tee? With tee you can write something like that too

    ➜ find ./app -name "*.go" -type f |& tee output.log
    


    In fact, these commands are not equivalent. The fact is that for tee we redirect stderr to stdout, thereby losing the ability to filter them after tee. ah retains this separation. In other words, we can write

    ➜ ah t -- find ./app -name "*.go" -type f > /dev/null
    


    And get only stderr output on the screen. And what will save ah? It will save both threads. And the return code. Yes, ah ends with the same code that the previous command worked with. Still ah works fine with ssh, even if you run ncurses applications there. If necessary, there is support for pseudo-TTY and the ability to run in a real interactive shell.

    Story display



    ➜ ah s 10
    ...
    !10109  (02.11.14 18:05:14)    nvim main.go
    !10110  (02.11.14 21:48:12) *  ah t -- find ./app -name "*.go" -type f
    


    Yes, ah can show your content HISTFILEand knows about HISTTIMEFORMAT. Guess why there are exclamation marks next to the number. But what does the star mean before ah t...? This means that ah stores the output of this command. You can view the output using a subcommand l.

    ➜ ah l 10110
    ./app/historyentries/get_commands.go
    ./app/historyentries/parser.go
    ./app/historyentries/keeper.go
    ./app/historyentries/history_entry.go
    ./app/historyentries/history_processor.go
    ./app/environments/environments.go
    ./app/utils/re.go
    ./app/utils/logging.go
    ./app/utils/synchronized_writer.go
    ./app/utils/exec.go
    ./app/utils/utils.go
    ./app/commands/bookmark.go
    ./app/commands/remove_bookmarks.go
    ./app/commands/gc.go
    ./app/commands/list_trace.go
    ./app/commands/tee.go
    ./app/commands/execute.go
    ./app/commands/show.go
    ./app/commands/list_bookmarks.go
    ./app/slices/slices.go
    


    By the way, 10 in ah s 10literally means "show the last 10 teams." At the same time, the slice syntax is supported (1: 1 as in Python): it ah s 10 20will show all commands from 11 to 20, ah s 10 _20- from 11 to 20 from the end ( _but not -). You can also search by regular expressions + there is a primitive fuzzy matching.

    In addition, you can make bookmarks with the subcommand b, scroll through them lb, delete them rb, clean old conclusions with gt, but these are trifles.

    I hope that someone else will live easier.

    So there.
    github.com/9seconds/ah

    Also popular now: