Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

How to? sort history in tcexit.btm

May
31
0
I'm trying to save a sorted history list when exiting tcc, but it doesn't seem to be working. If I edit history.txt externally when tcc isn't running, I can sort and save the file, but I can't seem to accomplish the same thing from within tcc.
 
What are you trying (and what goes wrong)? I'd try (with paths if necessary):
Code:
sort history.txt /o history.txt
 
What are you trying (and what goes wrong)? I'd try (with paths if necessary):
Code:
sort history.txt /o history.txt

Thank you! I used your code in tcstart.btm, before loading the history file. For some reason, though, it did not work in tcexit. I got no error message, but the history file still contained unsorted entries at the end.

Tom
 
It worked here in TCEXIT.BTM. Of course if that's TCC's real history file and you load it when TCC starts, any new commands will (typically) be put at the end.
 
Here is my current history as viewed from the command line:

h
x
sort history.txt /o history.txt

h is an alias for history, x is an alias for exit.

Currently the command

sort "C:\Program Files\JPSoft\TCMD16x64\history.txt" /o "C:\Program Files\JPSoft\TCMD16x64\history.txt"

is in my tcstart file.

If history.txt were getting sorted prior to starting a tcc session, then the sort command should be between the h and x commands. When I exit and then restart tcc, the history command produces the result above.

Now it appears the contents of history.txt are NOT the same as the results obtained when the history command is executed at the command prompt:

[C:\Program Files\JPSoft\TCMD16x64]type history.txt
..
b
dir
dir history.txt
e tcexit.btm
e tcstart.btm
h
sort history.txt /o history.txt
t tcstart.btm
type history.txt
x

[C:\Program Files\JPSoft\TCMD16x64]h
h
x
sort history.txt /o history.txt
t tcstart.btm
e tcstart.btm
e tcexit.btm
..
dir
dir history.txt
b
type history.txt
 
Commands in TCSTART.BTM (or any BTM) don't go into the history. Commands entered at the command line go into the history, but there are a few options which determine **how** they go into the history. See the OPTION dialog, "Command Line" tab ... Command History ... Help ... read about "Copy to end", Move to end", "Save first", and "Save last". You can probably get it working as you wish.
 
The nearest I can figure is, tcexit is sorting the history file BEFORE the current history is written to file. How can I override this and make the saved history file sorted - including the most recently entered commands???

If I somehow stop history from being saved, then all the current (most recent) commands are lost. But - for some inexplicable reason - the history that's being saved is a different animal from the history file that's already saved. Does this make any sense?
 
How about ... don't use the automatic history file (clear the "History file" box in the OPTION dialog) and "roll your own".

In TCEXIT, save/sort the history manually.

Code:
history | sort > (path\)myhistory.txt

And in TCSTART, read the history back.

Code:
history /r (path\)myhistory.txt
 
Doesn't work: I had to run tcexit manually to see this:

TCC: C:\Program Files\JPSoft\TCMD16x64\TCEXIT.btm [4] Exceeded batch nesting limit
TCC: C:\Program Files\JPSoft\TCMD16x64\TCEXIT.btm [4] Exceeded batch nesting limit

tcexit looks like this:
 

Attachments

Tom, I'm curious. What advantage to you see in sorting the history? After ~25 years of hanging around here, I don't recall anyone asking about it. I think most users want recent commands at the end so they're easily recalled, and sequences of commands to remain in sequence as much as possible.
 
Doesn't work: I had to run tcexit manually to see this:

TCC: C:\Program Files\JPSoft\TCMD16x64\TCEXIT.btm [4] Exceeded batch nesting limit
TCC: C:\Program Files\JPSoft\TCMD16x64\TCEXIT.btm [4] Exceeded batch nesting limit

tcexit looks like this:
(My mistake) TCC is starting another TCC to execute sort. That TCC also executes TCEXIT.BTM ... and so on. Use an "in-process" pipe.

Code:
history |! sort > (path\)myhistory.txt
 
doesn't work. History is still unsorted. To answer your earlier question, I was curious when I discovered that there is a sort command in TCC, but when I execute "help sort" at the command prompt I get "this program cannot display the webpage" (???) This led me to wonder about sorting the history list as an exercise.

It seems that TCC just doesn't want the history to get sorted.
 
There's no sort command in TCC.
Code:
v:\> which sort
sort is an external : C:\Windows\system32\sort.EXE

The last approach (history |! sort > (path\)myhistory.txt) definitely works here.
 
your approach works - but the problem remains that the history in memory (unsorted) replaces the sorted history list on exit.

Thank you for your patience in dealing with me on this. The fact that you're the only person who's responded to my concern suggests that others may think I'm an idiot for wanting to sort history in the first place... :-)
 
Tom - are you LOGging every command? If so you can't modify a file the same time a utility is - like SORT ...

LOG OFF
history >! %temp\MyHistory.txt
SORT %temp\MyHistory.txt /o outpath\outname.ext
LOG ON
 
your approach works - but the problem remains that the history in memory (unsorted) replaces the sorted history list on exit.
Did you clear the "History File" box in the OPTION dialog ("Command Line" tab)? If you don't, TCC will have the last word.
 
Tom - are you LOGging every command? If so you can't modify a file the same time a utility is - like SORT ...

LOG OFF
history >! %temp\MyHistory.txt
SORT %temp\MyHistory.txt /o outpath\outname.ext
LOG ON
Logging should be using a file different from the "History file". I have command log files going back years (10-12 MB). The log mechanism should have no effect on the command history mechanism.
 
I tried clearing the box, and then got a zero-length history file.
Hmmm! I've been using TCC (and it's predecessors) for over 20 years. I've never used a command history file and I've never seen one. I just looked very hard for one and I couldn't find one. Lets start over.

Clear the "history file" box. The only line in TCEXIT.BTM that refers to history should be something like (notice the change to use SORT's "/o" instead of redirection, because redirection can fail if you have NOCLOBBER set).
Code:
history |! sort /o (path\)history.txt
The only line in TCSTART.BTM that refers to history should be something like
Code:
history /r (path\)history.txt

I just tried this and it worked. When I exited and restarted TCC, I had a perfectly sorted history.

Note that if you ever get this working, you might hate it. My history is about 164,000 bytes and when I performed the experiment above, it took 1 second to save it in TCEXIT.BTM and 10 seconds (!) to load it in TCSTART.BTM.
 
Hmmm! I've been using TCC (and it's predecessors) for over 20 years. I've never used a command history file and I've never seen one. I just looked very hard for one and I couldn't find one. Lets start over.

Clear the "history file" box. The only line in TCEXIT.BTM that refers to history should be something like (notice the change to use SORT's "/o" instead of redirection, because redirection can fail if you have NOCLOBBER set).
Code:
history |! sort /o (path\)history.txt
The only line in TCSTART.BTM that refers to history should be something like
Code:
history /r (path\)history.txt

I just tried this and it worked. When I exited and restarted TCC, I had a perfectly sorted history.

Note that if you ever get this working, you might hate it. My history is about 164,000 bytes and when I performed the experiment above, it took 1 second to save it in TCEXIT.BTM and 10 seconds (!) to load it in TCSTART.BTM.

I don't use NOCLOBBER.

Well, it seems I finally got what I wanted. My TCSTART contains only history /r, and TCEXIT contains the following:
Code:
history /n >"C:\Program Files\JPSoft\TCMD16x64\history.txt"
history |! sort > "C:\Program Files\JPSoft\TCMD16x64\history.txt"

I think I'll leave well enough alone. Thanks again for all your help.

Tom
 
... and TCEXIT contains the following:
Code:
history /n >"C:\Program Files\JPSoft\TCMD16x64\history.txt"
history |! sort > "C:\Program Files\JPSoft\TCMD16x64\history.txt"
"HISTORY /N" produces no output; it just removes duplicates in place ... in memory. Your 0-byte file (earlier) was probably coming from the first line above. You can prevent duplicates getting into the history in the first place by choosing (Duplicates) "Save first" or "Save last" in the OPTION dialog.

If you ever decide against the sorting, you might consider SHRALIAS or some other popular way of using the history. I'll tell you what I want from it and how I accomplish it. Maybe others will too.

I want a big history so I can type a few letters and up-arrow until I find a command in the history. And I don't want starting/stopping TCC to be slowed down by loading/saving a history file. So I don't use the "history file" mechanism, I use a global history, and, in a BTM that runs at Windows login, I do
Code:
cdd %shralias_save_path
for %c in ( history dirhistory alias function ) %c /r %c.sav
delay 3
shralias

SHRALIAS (read about it) is a process that guards the in-memory lists (history, dirhistory, ...) so they're not lost when no TCCs are running. All TCCs that use a global history (dirhistory, et al.) attach to these lists instantly. I never think about it again. At logoff, Windows asks the SHRALIAS process to close and if the (user or system) environment variable "shralias_save_path" is defined, SHRALIAS saves the lists and gracefully exits.

There's not much discussion of SHRALIAS in these forums, so I imagine others want/get something else. Perhaps they will share their goals and solutions.
 
Back
Top
[FOX] Ultimate Translator
Translate