by aaronharnly · 7y ago · 0 comments
I find this super-helpful to remind me of the context for projects – cd in, then up-arrow to whatever that command is I usually run to launch this server, grep this logfile, etc.
There are some downsides – sometimes I want to run the same command in directory X and also in subdirectory X/Y, but I love doing it this way.
Anyone else done something similar?
Thus, all of the `cd` commands that get written to my history use absolute paths and are re-usable no matter where I am.
It would be cool if this sort of functionality were generalizable to all commands where you type a relative path, not just `cd`.
https://github.com/dasl-/settings/blob/3143bbfe23bd75c3e35c7...
This isn't specific to `cd` commands either. It's useful if you are `rsync`ing different directories to different places, or checkout different `git` branches, etc.
Like, for example, would it handle this properly?
$ (cd /source;tar -cf - .) | (cd /dest;tar -xf -)
My particular configuration is at https://github.com/YenTheFirst/dotfiles/blob/master/.bash_cd...
90% of the time, the bash history is super relevant to the current context. A small amount of the time, I remember that I issued a command, but not in which directory - in these cases, I can just search the history directory, and get both the context of what the command was, and also where I was when I originally issued it.
https://github.com/oilshell/oil/issues/320
It seems like a weird hack but apparently it works for tons of things!
[1] Latest status: Success With the Interactive Shell http://www.oilshell.org/blog/2019/02/05.html . Oil runs a bunch of interactive programs like bash-completion, virtualenv, and git-prompt.
The good thing is that it includes context: current directory, session, date.
I use it together with ssh-suggestions which can use SQL queries to find the most relevant command. You can program rules such as: use the most frequent command in that session, if you none do it for the current directory in the last 6 months, if not, search globally.
function log_history {
echo "`date '+%Y-%m-%d %H:%M:%S'` $HOSTNAME:$$ $PWD ($?) `history 1`" >> $MYHISTFILE
}
which records a timestamp, host name, shell pid, working directory and exit status for each command.Basically a container let's you wrap a part of your filesystem, network, process space in a separate world of its own. And in that world you have only the context related stuff like history, processes, libs etc. Additionally most container environments come with tooling that enables you to make everything reproducable, so that you can share your container with others.
The great thing is you can always live in global space, while switching between what that global space means.
I keep an infinite log by appending a timestamp to the beginning of the lines written to my history file, then merging this into a growing log with an hourly cronjob that runs sort -n | uniq on the file and the new version of the shell history. This way the shell history file is just a buffer. It doesn't get too big to cause corruption or other issues with reverse search on the command line. I just grep my way through the big history file to figure out what I was doing and when.
Specifically, I'm not sure what "this" is that fish does, as I described interaction of multiple pieces of software and I don't think fish includes a terminal multiplexer?
I'm not, but now that you mention this, I think I will. I already use direnv all over the place, and this would be a pretty natural extension. Thanks!