Welcome!

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

SignUp Now!

Fixed EXECSTR failure if you alias 'tail'

Jul
269
6
For the life of me.... I was trying to figure out how having my alises loaded was creating a failure with %@EXECSTR[-2,dirhistory] which returns the 2nd to last folders you were in.

It turns out that me aliasing tail to `call tail.bat` breaks EXECSTR's functionality

Is the implication here that EXECSTR is somehow using tail??
Or an internal tail command which needs an asterisk before it?

Or that we can't realias our tail command?


[History: I have compiled non-cygwin EXEs for lots of unix commands, as such, certain unix command are aliased to call a batfile which detects whether i have cygwin or not and uses the cygwin version if i have cygwin present, and an alternate version if i don't. I've used this for cat/du/fiff/head/uniq/tail/wget and sometimes grep since the 1990s]

Screenshot of me figuring out the problem:

1686245115650.png
 

Attachments

  • 1686244844095.png
    1686244844095.png
    200.6 KB · Views: 77
Last edited:
%@EXECSTR[-2,dirhistory] which returns the last 2 folders you were in.
@EXECSTR always returns one line. In the example above, the second-to-last line of DIRHISTORY's output.

As for the rest, here it is a little more simply.

Code:
v:\> alias tail nonsense

v:\> echo %@execstr[-1,dirhistory]
TCC: Unknown command "nonsense"
ECHO is OFF
 
@EXECSTR always returns one line. In the example above, the second-to-last line of DIRHISTORY's output.


I caught that right after leaving my comment ;) It was the 2nd to last one I'm trying to get.

At issue is, running it with windows terminal overrides the starting folder, so I was trying to examine that value. But I realized it was a concurrency nightmare so I came up with a different way of doing it anyway - creating an autorun script to change to the new folder and having tcstart.btm pick up on the autorun script. I'm also using this for splitting panes in the new paned-view that windows terminal has. I've basically made the unix "bg" command except it runs in a pane so you can see it, but retain use of your command line, without ever having to switch to another window/tab,

and just loving it

but yea i spent like 5 hours writing BAT files hahahahahahahahhaha
 
P.S. I like your more simpler example! I need to get better at coming up with those.
 
At issue is, running it with windows terminal overrides the starting folder
What starting folder is WT overriding?

P.S. I like your more simpler example! I need to get better at coming up with those.
That's the best way to get things fixed/changed. That one (@EXECSTR/TAIL) is probably a bug/oversight and probably easily fixed.
 
What starting folder is WT overriding?

it sticks me in my "home" dir of c:\users\clioc (which is an interesting experience in windows compared to unix, i hardly ever go there) instead of the folder i called it from.

Probably I should have used the start command instead of just calling wt.exe and avoided this, but I went for the simplest invocation, and then added complexity around that rather than trying another invocation. Possible oops.



That's the best way to get things fixed/changed. That one (@EXECSTR/TAIL) is probably a bug/oversight and probably easily fixed.

I will take this to mind!

So like, how do I get this fixed? Just hope they notice? :)
 
it sticks me in my "home" dir of c:\users\clioc (which is an interesting experience in windows compared to unix, i hardly ever go there) instead of the folder i called it from.
Do you have a WT "profile" for TCC?

1686247983630.png


In the profile you can fine-tune the behavior, in particular, the start-up directory.

1686248119881.png
 
Do you have a WT "profile" for TCC?

View attachment 4016

In the profile you can fine-tune the behavior, in particular, the start-up directory.

View attachment 4017

Oh, i tried those options. Hard-coded is a big no-no. Userprofile puts you in homedir. "use parent process directory" has a differing opinion of what that means... it's definitely not the directory you're in when you call it. So I had to store the folder to retrieve it later, via created autorun bat, because none of those 3 options are what I want when launching. Sigh.
 
You can specify the directory of your choice. I have specified v:\.

1686249896875.png

"Use parent process directory" will give you the current working directory of windowsterminal.exe itself. WT doesn't monkey with its CWD. It will either be (1) a directory specified by WT's parent process, or, in the absence of such a specification, (2) the inherited CWD of WT's parent process. So what "Use parent process directory" does will depend on how WT itself was started. I don't know why anyone would want that behavior.
 
Unfortunately, a hard-coded folder doesn't work for me. If i'm in \SOME\DEEP\DIRNAME\ and i want to start another TCC, I want it there. And I don't want to browse there.

Same reason I want my text editor's file->open dialog to open in the last folder it was already in: If i'm doing new things, those new things have the context of what I've already been doing. Don't want to spend my life traversing folders unnecessarily.

In 40 yrs of CLI, I don't know why anyone would ever want any different behavior under any circumstance, to be honest.
 
But i have it working. My command has always been '4' (for 4NT, heh) to open a new one.
And now i have a '5' to do it in windows terminal.
And it always opens in the folder I'm in.

But now with this wonderous windows terminal, i can run commands in the same folder with "bg command" and they will be in another pane visible to me without robbing me of my command line or causing me to have to go to another window to see what's going on. I LOVE IT.

I'll take a video once i make a good demo.
 
For curiosity's sake, here's my 4.bat that i used for 20+ yrs, and it has artifacts indicating that history ;)

followed by my 5.bat to do the same thing in Windows Terminal

and the tcstart.bat which picks up on the generated autorun and autoruns it

it's all working flawlessly for me so far

4.bat
Code:
@Echo OFF

if "%OS"=="7" goto :Win7
                         goto :default

:PreWin7
     start c:\4nt\4nt.exe
goto :END

:default
:Win7
    :We'll allow a parameter to be passed, in case we want an elevated shell:
    unset /q OPTS
    if "%_admin"=="1" set OPTS=/elevated
    start %OPTS% %* c:\tcmd\tcc.exe
    unset /q OPTS
:END


5.bat:


Code:
@Echo OFF

rem Get input values
    set PARAM1=%1

REM validate tools
    set TCC=c:\tcmd\tcc.exe
    call validate-env-var TCC
    call validate-in-path wt



REM split for new/same window/tab:
    set WINDOW_OPTIONS=
    set WINDOW_OPTIONS=%WINDOW_OPTIONS% -w 0
    if "%PARAM1%" eq "same" .or. "%PARAM1%" eq "tab"    set WINDOW_OPTIONS=%WINDOW_OPTIONS% -w 0
    if "%PARAM1%" eq "new"  .or. "%PARAM1%" eq "window" set WINDOW_OPTIONS=



REM create autorun script to change to the folder we involke this in:
     set                                           POST_SPLIT_COMMAND_DIR=c:\TCMD\
     set                POST_SPLIT_COMMAND_SCRIPT=%POST_SPLIT_COMMAND_DIR%\runonce-post-split.bat
     echo @Echo OFF   >%POST_SPLIT_COMMAND_SCRIPT%
     echo %_CWD\     >>%POST_SPLIT_COMMAND_SCRIPT% %+ REM change into the same folder we issue this rom



REM run tcc:
    set COMMAND=wt %WINDOW_OPTIONS% %TCC%
       %COMMAND%
    set WINDOW_OPTIONS=


tcstart.bat:

Code:
    set OS=10
    SET MACHINENAME=DEMONA
    set MOST_SECONDS_TCC_WOULD_EVER_TAKE_TO_START_UP=3
    title TCC
    call c:\bat\environm.btm

rem ::::::::::::::::::: ::::::::::::::::::: WINDOWS TERMINAL USHURED A NEED MORE MORE STARTUP LOGIC:  ::::::::::::::::::::::::::::::::::::::

rem                     1) We had to create an autorun system for window splits so that we could use them efficiently.
rem                     2) We had to create a way to change folders automatically because windows terminal starts us
rem                        in %HOME% instead of where we were when we called it


rem ::::: IS THIS A SPLIT WINDOW? THEN OUR CONVENTION IS TO CHECK THIS FILE, AND RUN IT IF IT'S RELATIVELY FRESH
rem
rem        Some complications we've had to address:
rem          
rem        First, when we added the 'exit' option, if the command was a BAT file, it would never return to exit.
rem               * We addressed this by detecting the command using 'which', extracting the extension,
rem                 and if it is a BAT file, adding 'call' to the beginning.
rem          
rem        Secondly, if the command takes a long time to run, then if we attempt to do this concurrently,
rem                  we won't be able to create the BAT file because it is still running.
rem                  * We addressed this by renaming the script to a unique filename before running it.

            set                    AUTORUN_SCRIPT=c:\tcmd\runonce-post-split.bat
            if exist              %AUTORUN_SCRIPT% (
                call set-fileage  %AUTORUN_SCRIPT%
                if not exist      %AUTORUN_SCRIPT% goto :END
                set      NEWNAME=%[AUTORUN_SCRIPT]%_PID.bat
                set AGE_THRESHOLD=%@EVAL[%MOST_SECONDS_TCC_WOULD_EVER_TAKE_TO_START_UP * 1.5]
                if not exist %AUTORUN_SCRIPT% goto :END
                if  %RESULT lt %AGE_THRESHOLD (
                    if not exist %AUTORUN_SCRIPT%  goto :END
                     ren   /q    %AUTORUN_SCRIPT% %NEWNAME%
                     call         val-env-var      NEWNAME
                     call                         %NEWNAME%
                )
                 copy /s /f /r /md %NEWNAME%  c:\recycled\last-split-autorun.bat >nul
                                              *del  /q /z /f     %NEWNAME%                                     >nul
                if  exist   %AUTORUN_SCRIPT%  *del  /q /z /f     %AUTORUN_SCRIPT%                              >nul
            )
:END
 
Code:
C:\>echo %@execstr[-1,setdos]
VERBOSE=1

C:\>setdos /i-tail

C:\>echo %@execstr[-1,setdos]
/cygdrive/c/bin/cygwin64/bin/tail: cannot open '/n' for reading: No such file or directory
/cygdrive/c/bin/cygwin64/bin/tail: cannot open '1' for reading: No such file or directory
ECHO is OFF

C:\>setdos /i+tail

C:\>echo %@execstr[-1,setdos]
VERBOSE=1

C:\>

Um....
 
Good one, Charles! It still could be just a matter of changing "TAIL" to "*TAIL" somewhere. The bug goes back to at least v24.
 

Similar threads

Back
Top