Welcome!

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

SignUp Now!

Saving aliases

I have been trying to follow the instructions for saving aliases without success. I would like to save an alias in such a way as to cause it to be operational automatically on startup of Take Command. I would be grateful for advice.
 
In my tcstart.btm is this code:
Code:
iff %_shralias eq 0 then
    shralias
    alias /R %JPPath\DAT\alias.dat
    iff %_cmdproc NE TCCLE then
        function /R %JPPath\DAT\function.dat
    endiffendiff
That makes sure shralias is running, loads the aliases and, if not TCC/LE, loads the functions also. One of those aliases is this:
Code:
edal=in %_startpath\..\DAT start /wait notepad %_startpath\..\DAT\alias.dat & alias /r %_startpath\..\DAT\alias.dat
edal is short for edit alias. It edits the alias file and reloads those aliases.
 
In my tcstart.btm is this code:
Code:
iff %_shralias eq 0 then
    shralias
    alias /R %JPPath\DAT\alias.dat
    iff %_cmdproc NE TCCLE then
        function /R %JPPath\DAT\function.dat
    endiffendiff
That makes sure shralias is running, loads the aliases and, if not TCC/LE, loads the functions also. One of those aliases is this:
Code:
edal=in %_startpath\..\DAT start /wait notepad %_startpath\..\DAT\alias.dat & alias /r %_startpath\..\DAT\alias.dat
edal is short for edit alias. It edits the alias file and reloads those aliases.

Wow! How complicated! I will have to find out what all this means. Thanks anyway.
 
I don't use shralias. All you really need is "alias /r C:\Foo\MyAliases.txt". To create the file you can do "alias > C:\Foo\MyAliases.txt".
 
I use shralias because I want my aliases shared between my multiple TCC tabs. It also allows for the dynamic updating of the aliases (edit alias) to be updated across all tabs. If you only have a single TCC and/or would not want dynamic updates to those aliases, then shralias may not be as useful.
 
I think I switched long ago to local aliases because with global aliases, any changes to aliases a btm file makes affects all the tabs. My btm files usually delete all aliases and then define just the ones they need. This way they aren't dependent on my general aliases (which I may change).
 
Wow! How complicated! I will have to find out what all this means.
Not at all. Here's a version (with comments):
Code:
REM I have D:\JPSoft\TCMD15\ and D:\JPSoft\DAT\ where alias and function files are.
REM Set JPPath to the folder above where my TCC is (D:\JPSoft).
set /e JPPath=%@full[%@path[%_cmdspec]..\]
 
iff %_shralias eq 0 then  (If shralias is not loaded)
    shralias  (load shralias)
    alias /R %JPPath\DAT\alias.dat  (load aliases)
    iff %_cmdproc NE TCCLE then  (If my TCC is the full version and not TCC/LE)
        function /R %JPPath\DAT\function.dat  (load functions)
    endiff
endiff

As for the edal alias
Code:
edal=in %_startpath\..\DAT start /wait notepad %_startpath\..\DAT\alias.dat & alias /r %_startpath\..\DAT\alias.dat
It means to run notepad within my D:\JPSoft\DAT folder and edits the alias.dat file, waiting for notepad to exit before continuing. Once notepad exists, the combined '&' command reloads the alias file with any changes. That, plus shralias, allows me to have multiple TCC tabs open, add/edit aliases from any of them, and have the changes updated across all of them.
 
I think I switched long ago to local aliases because with global aliases, any changes to aliases a btm file makes affects all the tabs. My btm files usually delete all aliases and then define just the ones they need. This way they aren't dependent on my general aliases (which I may change).
Look into setlocal/endlocal. It allows for global aliases, but your .btm can redefine them without affecting the shared aliases. Setlocal is usually the second line of my .btm files, right after @echo off. If the .btm does a setlocal, when it exits, it will do an endlocal automatically; no need to call it explicitly.
 
Look into setlocal/endlocal. It allows for global aliases, but your .btm can redefine them without affecting the shared aliases. Setlocal is usually the second line of my .btm files, right after @echo off. If the .btm does a setlocal, when it exits, it will do an endlocal automatically; no need to call it explicitly.

Yes, but if you execute "*UNALIAS *" within SETLOCAL, it will still remove all aliases from all other running TCC tabs until you perform the corresponding ENDLOCAL.

This has bitten me with batch files executing concurrently in different tabs. My solution was to simply skip the "UNALIAS *" part though. Portability of batch files is not a concern for me.
 
Yes, but if you execute "*UNALIAS *" within SETLOCAL, it will still remove all aliases from all other running TCC tabs until you perform the corresponding ENDLOCAL.
Though I've been using TCC since it was 4DOS (20+years?), I don't recall ever globally zapping all aliases in a batch file. I certainly define/clear some, but not '*'. I know being a lazy developer is a good thing (I certainly try), but are the .btms that complicated that the aliases used cannot be tracked? Even my multi-process synched .btms didn't reach that level.
 
I created an alias that I run whenever I create a new alias that I want to keep...
Code:
realias=alias | sort > %@path[%comspec]alias.ini %+ unalias * %+ alias /r %@path[%comspec]alias.ini
... along with loading alias.ini in my tcstart.btm.
 
Though I've been using TCC since it was 4DOS (20+years?), I don't recall ever globally zapping all aliases in a batch file. I certainly define/clear some, but not '*'. I know being a lazy developer is a good thing (I certainly try), but are the .btms that complicated that the aliases used cannot be tracked? Even my multi-process synched .btms didn't reach that level.
I actually once aliased something that wan't aliased before and broke a btm file. Rather than put "*" in front of everything in my btm files, I decided to do "unalias *". I'm not going to search all my btm files every time I fiddle with my aliases to make sure there aren't conflicts.

Also, even if I only change some aliases in a btm file, I don't want my btm files messing with my other TCC sessions while I'm doing things. This seems like just asking for trouble.

Maybe you can remember what you put in a btm file 20 years ago, but my memory isn't that good.
 
Look into setlocal/endlocal. It allows for global aliases, but your .btm can redefine them without affecting the shared aliases. Setlocal is usually the second line of my .btm files, right after @echo off. If the .btm does a setlocal, when it exits, it will do an endlocal automatically; no need to call it explicitly.
Thanks, but I did learn about setlocal a decade or two ago. My btm files usually start with
Code:
*on errormsg cancel
*setlocal
*unalias *
 
Thanks JohnQ, your code is very userful for me....
I was giving aliases straight to tcstart.btm but during time i found out that causing lot of problems (e.g. TCC Here in context menu)
using file alias.txt and your code to update is much better !!! :)
 
I find that my alias list changes very rarely. I tend to forget what I've created anyway so I don't have a very long alias list. I use David Marcus's approach - i.e. I save to a file when I want to update my persistent alias list. And I load the file in TCSTART.BTM.
Here is my complete TCSTART file
Code:
if %_pipe != 0 .or. %_transient != 0 .or. %_ide != 0 quit

alias /r c:\jpsoft\aliases
color bri yellow on black

set s=Y
inkey /c /k"YN[Enter]" /w10 /x Restore Previous Environment? (Yn) %%s
echo.
iff "%s" eq "Y" .OR. "%s" eq "@28" then
  for %%s in (@c:\JPSOFT\drives.dat) do cdd %%s
  set /r c:\JPSOFT\env.dat
  dirhistory /r c:\JPSOFT\dirhist.dat
  history /r c:\jpsoft\history.dat
endiff

set TREEEXCLUDE=d:\;e:\;f:\;g:\;h:\;I:\;J:\;K:\;L:\;M:\;N:\;O:\;P:\;Q:\;R:\;S:\;T:\;U:\;V:\;W:\;X:\;Y:\;Z:\;\\*\*

set TITLEPROMPT=%[_cmdproc]%@if[%_x64,x64,] %_4ver (%_BUILD) in %%_cwd
title %[_cmdproc]%@if[%_x64,x64,] %_4ver (%_BUILD)
prompt=`^e[37;%@if[%@remote[%_disk] eq 0,42,41];1m[$P]^e[33;40;1m$s`
unset s
 
Yes, but if you execute "*UNALIAS *" within SETLOCAL, it will still remove all aliases from all other running TCC tabs until you perform the corresponding ENDLOCAL.
This is disturbing. How could this not be considered a bug? I thought things like this is exactly what SETLOCAL/ENDLOCAL is to protect against?
 
This is disturbing. How could this not be considered a bug? I thought things like this is exactly what SETLOCAL/ENDLOCAL is to protect against?
If you want to use global aliases, then it is at least a missing feature. If you use local aliases, then setlocal works fine.
 
What does your TCExit.BTM look like?

I find that my alias list changes very rarely. I tend to forget what I've created anyway so I don't have a very long alias list. I use David Marcus's approach - i.e. I save to a file when I want to update my persistent alias list. And I load the file in TCSTART.BTM.
Here is my complete TCSTART file
Code:
if %_pipe != 0 .or. %_transient != 0 .or. %_ide != 0 quit

alias /r c:\jpsoft\aliases
color bri yellow on black

set s=Y
inkey /c /k"YN[Enter]" /w10 /x Restore Previous Environment? (Yn) %%s
echo.
iff "%s" eq "Y" .OR. "%s" eq "@28" then
  for %%s in (@c:\JPSOFT\drives.dat) do cdd %%s
  set /r c:\JPSOFT\env.dat
  dirhistory /r c:\JPSOFT\dirhist.dat
  history /r c:\jpsoft\history.dat
endiff

set TREEEXCLUDE=d:\;e:\;f:\;g:\;h:\;I:\;J:\;K:\;L:\;M:\;N:\;O:\;P:\;Q:\;R:\;S:\;T:\;U:\;V:\;W:\;X:\;Y:\;Z:\;\\*\*

set TITLEPROMPT=%[_cmdproc]%@if[%_x64,x64,] %_4ver (%_BUILD) in %%_cwd
title %[_cmdproc]%@if[%_x64,x64,] %_4ver (%_BUILD)
prompt=`^e[37;%@if[%@remote[%_disk] eq 0,42,41];1m[$P]^e[33;40;1m$s`
unset s
 
If you want to use global aliases, then it is at least a missing feature. If you use local aliases, then setlocal works fine.

This is very easy to deal with. Just put the command "alias /L" before the "unalias *" command to switch from global aliases to local aliases. Then the "unalias" command will only clear the local aliases in the batch file, and no other TCC sessions will be affected. After "endlocal" the aliases will come back.
 
This is very easy to deal with. Just put the command "alias /L" before the "unalias *" command to switch from global aliases to local aliases. Then the "unalias" command will only clear the local aliases in the batch file, and no other TCC sessions will be affected. After "endlocal" the aliases will come back.
Thanks, seems like a reasonable workaround!
 
Back
Top
[FOX] Ultimate Translator
Translate