Open saltlakeryan opened 2 years ago
@saltlakeryan I would like to write a similar shell script for bash so that I can log commands in other contexts. In your script, can you explain what the set CMD_HISTORY
line is doing?
Yeah, my understanding is that echo $*
outputs all of the arguments to the current script. Since the script is called with the arguments of $$, $?, and history 1
, it should echo out something like:
4075 0 25 14:00 vim /tmp/somefile.txt
The cut command uses space as a delimiter and captures everything from the 5th field onward. In the above example, it would get trimmed to:
vim /tmp/somefile.txt
The only issue I've noticed is that wildcards and other special shell interpretations get captured after evaluation. For example, if I execute ls *
in a directory with file1, file2, and file3, it gets stored in the sqlite db as ls file1 file2 file3
. Here's an example of that:
mypc [/tmp/test]% touch file1 file2 file3 file4
mypc [/tmp/test]% ls *
file1 file2 file3 file4
mypc [/tmp/test]% recent -n 1
2022-10-05 14:07:40 ls file1 file2 file3 file4
I've hacked together tcsh support by creating a ~/bin/tcsh-log-recent.sh and configuring .cshrc to call it (similar to the bash setup):