|
1 | 1 | # -*- Mode: shell-script -*-
|
2 | 2 | # shellcheck shell=bash
|
3 | 3 |
|
4 |
| -# We've long appended our bash history upon a command running, using |
5 |
| -# various methods. `trap '...' DEBUG` was causing us to have to write |
6 |
| -# lots of code just to make sure the command being tested was a user |
7 |
| -# command and not some poor shell command, and pay careful attention |
8 |
| -# to make sure it didn't slow down the shell too much. Another probel |
9 |
| -# with `trap '...' DEBUG` method of writing .bash_fullhistory is that |
10 |
| -# if a command doesn't actually run (eg, #blah), then it doesn't get |
11 |
| -# echoed yet to the history file. Problem with PROMPT_COMMAND by |
12 |
| -# itself is that it doesn't write to the history until the command |
13 |
| -# returns. Like |
| 4 | +# We long ago overrode default bash behaviour of only writing the |
| 5 | +# history file when a shell exits in a controlled fashion, instead |
| 6 | +# choosing to attempt to append the history the moment a command has |
| 7 | +# been entered, using various methods (we also do away with any |
| 8 | +# BASH_HISTSIZE etc for the stored file -- any rotation of that file |
| 9 | +# is left to the user to do manually. I've got 1.6million lines in my |
| 10 | +# history file, and it doesn't affect shell loading time. We only |
| 11 | +# read the last 32k of them when starting a new shell). |
| 12 | +# |
| 13 | +# But there's a few ways to do this. `trap '...' DEBUG` was causing |
| 14 | +# us to have to write lots of code just to make sure the command being |
| 15 | +# tested was a user command and not some poor shell command, and pay |
| 16 | +# careful attention to make sure it didn't slow down the shell too |
| 17 | +# much. Another problem with `trap '...' DEBUG` method of writing |
| 18 | +# .bash_fullhistory is that if a command doesn't actually run (eg, |
| 19 | +# #blah), then it doesn't get echoed yet to the history file. Problem |
| 20 | +# with PROMPT_COMMAND by itself is that it doesn't write to the |
| 21 | +# history until the command returns. Like |
14 | 22 | # https://superuser.com/questions/175799/does-bash-have-a-hook-that-is-run-before-executing-a-command
|
15 | 23 | # We were using $PS0 for a while, via signal handlers per
|
16 | 24 | # https://github.com/rcaloras/bash-preexec/issues/28 but that causes
|
@@ -73,9 +81,14 @@ function handleprompt () {
|
73 | 81 | statusbeep $retcode 1$SECONDS 1$CMD_START_SECONDS
|
74 | 82 | fi
|
75 | 83 |
|
76 |
| - # we need to make sure the right history file is loaded, after the |
77 |
| - # previous command, which might have been a `cd` triggering a new |
78 |
| - # history file to be set, before the prompt returns. Do it now. |
| 84 | + # Implement per-directory bash history file: |
| 85 | + # We have a mechanism to load/save different history files per |
| 86 | + # subdirectory that you're in, eg by using `direnv`, to set |
| 87 | + # BASH_FULL_HISTFILE. If you set it for a subdir, and then |
| 88 | + # navigate to somewhere under that dir, direnv changes the value |
| 89 | + # of BASH_FULL_HISTFILE, and our job is to detect this change |
| 90 | + # after `cd` was run, and make sure this new history file is |
| 91 | + # loaded, before the prompt returns. |
79 | 92 | choosehistoryfile
|
80 | 93 |
|
81 | 94 | if [ -n "$EXTRA_PROMPT_SOURCE" ] && [ -e "$EXTRA_PROMPT_SOURCE" ] ; then
|
|
0 commit comments