11 ms·
The one I use most often is undoubtedly `g` for `git`. Then I have many aliases inside Git for all kinds of regularly done things, quite a few lifted from Mercu
by chrismorgan 8y ago
The one I use most often is undoubtedly `g` for `git`. Then I have many aliases inside Git for all kinds of regularly done things, quite a few lifted from Mercurial and then extended; some just shorter names (ci = commit, glog = log --graph) and some more advanced like these three:
fixup = "!f() { TARGET=\"$(git rev-parse \"$1\")\"; shift; git commit --fixup=\"$TARGET\" \"$@\" && git -c core.editor=true rebase --interactive --autostash --autosquash \"$TARGET^\"; }; f"
in = "!f() { case \"x$1\" in x-*|x) branch=;; *) branch=\"$1\"; shift;; esac; git glog \"$branch..$branch@{upstream}\" \"$@\"; }; f"
out = "!f() { case \"x$1\" in x-*|x) branch=;; *) branch=\"$1\"; shift;; esac; git glog \"$branch@{upstream}..$branch\" \"$@\"; }; f"
My most recent addition to my shell profile (a couple of weeks ago) enhances ts from the moreutils package. ts provides timestamps (relative to process execution or absolute) at the start of each line of stdout. My enhancement makes it cover stderr as well, so that stdout lines get a green timestamp and stderr lines get a red timestamp. Due to how interlacing works, and the fact that I commonly pair this with concurrency in the form of `make -j8`, it’s not perfect (can end up with a line possessing both green and red timestamps, and then none on the next line), but it’s still really helpful. I just need to get round to adding something to it to make programs still colour their own output. `script` can do that, I think.
It’s currently this shell function:
ts-fancy() {
((("$@" 2>&1 1>&3 3>&-) | ts -s "^[[91m[%H:%M:%.S]^[[m") 3>&1 1>&2) | ts -s "^[[92m[%H:%M:%.S]^[[m"
}
(Each ^[ shown there is a literal ␛.) ts-fancy was the temporary name I gave it at first, haven’t renamed it to anything more permanent yet, so it’ll probably stay that way forever.
Usage, `ts-fancy make -j8 --keep-going` and things like that. It’s proving really helpful when figuring out what’s slow in something that verbosely logs, and also in highlighting error output mixed in with normal output.
This exercise made me wish for a smarter terminal that kept track of timestamps and whether output went to stdout or stderr itself (at the character level, even, to resolve the problems of this line-based approach). I shouldn’t have to do this, and you know how often you think after the fact that it’d be nice to have timestamps?
- delian66 8y agoVery nice! Thanks you for sharing this! It really seems very useful to have timestamps for every line of output. I have tried to approximate this in the past, by setting my bash prompt to be: export PS1='\[\e[00;37m\]$?\[\e[0m\]\[\033[1;32m\]\[\033[1;32m\][\t]\[\033[1;41m\]\u\[\033[1;41m\]@\[\033[1;41m\]\h:\[\033[0m\] \[\033[1;32m\]\w\[\033[0m\] \$ ' ... which shows the previous command exit code, the current time (with second resolution) and the ordinary stuff like username host and working dir, so it looks somewhat like: 0[21:20:18]delian66@mypc: ~/Work $ slow_command .... 0[21:22:19]delian66@mypc: ~/Work $
- chrismorgan 8y agoI contemplated that for a while a few years back, but decided against it for several reasons: ① I didn’t like an overly-long prompt. On my own machine I already exclude username and hostname, so it’s just `~/Work$ `. (Sometimes PWD gets a bit long, but generally not too much.) ② It was fairly rare that I actually cared about such a timestamp in any way—if I did, it was normally about time taken, and so I could pipe the program through `time` (this was before I discovered `ts` when figuring “someone must have made a program to do this” a couple of weeks ago when preparing to optimise a build process at work), or execute `date; …; date`. ③ Such a timestamp is only written when the prompt is output, rather than when the program is executed (there may be a sane way to have it work otherwise—I didn’t investigate in any way thoroughly—but my initial thoughts suggested any hacky attempt to move the cursor after the fact would interact badly with commands that cause the command line to span multiple lines). This made it useless for well over 90% of the cases when I might have benefited from it (retroactive timing of the duration of a command, rather than at what o’clock I… probably did something). I return to the desire for a very mildly intelligent terminal that notes when characters were written to screen when not in raw mode, for optional viewing.
- delian66 8y agoI've just made this [0], based on your idea (differently colored timestamps for both stderr and stdout). It just spawns the actual command in a sub process, but may be the output may be more ordered than that of a pipe of ts commands. [0] https://github.com/spytheman/gostamp https://github.com/spytheman/gostamp