Welcome!

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

SignUp Now!

Useful short aliases

nchernoff

Administrator
May
42
2
Staff member
Migrated From JP Software

This article is for sharing simple aliases. The syntax is as listed if you issue alias with no parameters, or for importing with alias /R.

You can indicate the source/authorship of a contribution in a HTML comment next to the listing. Within a subsection, put them in alphabetical order.

Please share aliases and alias ideas with the world!

Code:
Contents

    * 1 Examples
          o 1.1 PATH Pollution, Avoiding
          o 1.2 Perl one-liners
    * 2 4NT/TCMD meta-operation
          o 2.1 Reload settings
    * 3 Shortcuts
    * 4 Misc. / Uncategorized

Examples

The examples here are illustrative of a general category. The specific alias listed might be of little interest, but rather it is simply one example of a general thing you can do with aliases, or an illustration of a technique.

PATH Pollution, Avoiding

If you have a directory that contains one (or a small number) of executables that you will run from the command line, instead of putting that directory in the PATH environment variable, you can make an alias for the command of interest to flesh out the complete path to the file.

Code:
zip="%ProgramFiles\zip\zip.exe"
unzip="%ProgramFiles\zip\unzip.exe"

Perl one-liners

Code:
rot13=perl -pe"tr/A-Za-z/N-ZA-Mn-za-m/"

Simple one-liner -e based Perl scripts can be turned into aliases, as illustrated here.

4NT/TCMD meta-operation

This section is for aliases that are for use when manipulating the command shell itself.

Reload settings


After tweaking the files containing your aliases or environment variables, easily reload them. That is better than having your change be temporary to that session — change it in the file in the first place.

Code:
reload=alias /R "C:\program files\4nt\aliases.lst" %+ set /R "C:\program files\4nt\environment.lst"

Shortcuts

Save typing by abbreviating common commands to a single letter:

Code:
a=alias
c=copy
d=dir
e=notepad
l=list
Commands you use very often can be assigned a key of their own. If you precede a key alias with ^E, any text already on the command line when you press the key will be erased. If the command begins with an at-sign, it will not be recorded in your command history. (Some keys will require a NormalKey= or NormalEditKey= .INI directive to disable their default mappings.)

Code:
@@f2=^E@echo Errorlevel: %?
@@f5=^Edir /p /a
@@f11=^Ecdd -</code>
@@f12=^E@cls</code>


Use aliases to abbreviate the names of external commands:

Code:
ff="c:\program files\mozilla firefox\firefox.exe"
iv="c:\program files\irfanview\i_view32.exe"
o*pera="c:\program files\opera\opera.exe"
word=winword.exe


Any often-used option or combination of options for a command is a good candidate for an alias. So is a series of commands which are frequently used together.

Code:
kill=taskend /f
logoff=reboot /l
nd=md /s %1 && %1\
shutdown=reboot /p
tf=dir /[d] /od
unuse=net use %$ /d
use=net use
whoami=echo %userdomain\%username


In version 8 and later, you can also use directory aliases to abbreviate commonly-used locations. Note that variable expansion is not performed if you read them from a file with ALIAS /R. If you want to use variables or functions in directory aliases, create them using individual ALIAS commands in a batch file.

Code:
alias dl:=d:\download
alias pub:=\\jeeves\public
alias user:=%userprofile
alias desk:=%userprofile\desktop
alias docs:=%userprofile\my documents
alias shell:=%@path[%_cmdspec]
alias win:=%systemroot
alias sys:=%systemroot\system32

Misc. / Uncategorized

  • Clonelink - Create a duplicate link (junction) to the current directory in the current directory (a loop). The new link must be moved elsewhere, e.g., with Windows Explorer. See Hard links for potential uses. The name of the link is the current directory preceded by a minus.

    Code:
    alias clonelink=`mklnk "%_cwd" %@quote[-%@name[%_cwp]]`
  • Math - Performs the math in the command line and displays the result.

    Code:
    alias math=`Echo %@eval[%&]`
  • Rensel (Rename + Select) - Adds a prefix to the selected file names.

    Code:
    alias rensel=`rename %@quote[%1] %@quote[%2%1]`
  • Syntax: select rensel (*.wmv) "Summer 2007 Vacation - " Note the optional space between the end hyphen and end double-quote mark. (Adding a suffix would be a lot more complicated because you have to remove the extension, add the suffix and then add back the extension.)
  • TDRV - Create temporary drive
 
PATH Pollution, Avoiding

To avoid %PATH% pollution, all you need to do is to create an entry in the registry, under "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths"

Example:
Code:
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\rar.exe" /ve /d "%[ProgramFiles]\WinRAR\rar.exe" /f

Will create
REGEDIT4

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\rar.exe]
@="C:\\Program Files\\WinRAR\\rar.exe"

Now, TC* can find it anywhere any time. Many other programs, too. While alias' application is limited to TC* only.

Well, back to topic.

Now, really useful aliases:

Code:
#!=rem
Even if it looks silly, it coming truly useful when you are interoperating with CygWin/MSYS and want TC* script to be launched from bash script.

Code:
done=iff %_TRANSIENT == 0 .and. %_BATCH == 1 then %+ exit %1 %+ else %+ quit %1 %+ endiff
The issue is, if you call "exit" from a nested batch file, you'll kill a whole stack, which is not a desired behavior in many situations.
Using this alias in place of "exit/quit", you'll not interrupt your execution chain accidentally.

And common consideration to keep in mind, when you are writing aliases - always, and I mean, always use fully qualified definitions.
%+ instead of whatever command separator you're using.
%= for escape character.
%[name] for variable reference. Could also save you from unintended name concatenation.
 
For the most part, i use hacks of 'write.exe', using a different name in registry, with different scripts in the file.

This is apppath.cmd, all of these commands are embedded in a version of write.exe, with different icon, and different call command. Write calls a new gui window to launch the required app, getting the info from the regkey below.

Most of the favs are done by editing this file. For example, when time comes to update tcmd to v12, the only thing that will be done after install, is to point the command as v12.

Note here that the virtual command is not the actual app. This is because if you rename write.exe to wordpad.exe (which it launches), then it will go into a loop. On the other hand, the names selected here are taken because they are not commands in current use, and you can use a pathed 'tcmd.exe' to load tcmd.exe

v8.01 is still current because it is the last version that runs in win2000, the main boot os.

Code:
@echo off
set rkey=SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths
:: change this on each install
set rsave=%systemdrive%\save
set rdir=%rsave%\newin


:: 4nt + tcmd 8
reg add "HKLM\%rkey%\4ntu.exe" /f /ve /d %rdir%\jpsoft\4nt.exe
reg add "HKLM\%rkey%\tcmdu.exe" /f /ve /d %rdir%\jpsoft\tcmd.exe
reg add "HKLM\%rkey%\tciu.exe" /f /ve /d %rdir%\jpsoft\tcii.exe
reg add "HKLM\%rkey%\tcx.exe" /f /ve /d %rdir%\tcmd11\tcc.exe
reg add "HKLM\%rkey%\tcmdxp.exe" /f /ve /d %rdir%\tcmd11\tcmd.exe

:: boxer
reg add "HKLM\%rkey%\boxer32.exe" /f /ve /d %rdir%\boxer\b.exe

:: iview32
reg add "HKLM\%rkey%\i_view32.exe" /f /ve /d %rdir%\irfanview\i_view32.exe

:: total commander
reg add "HKLM\%rkey%\totalcmd.exe" /f /ve /d %rdir%\ghisler\totalcmd.exe

:: ztw
reg add "HKLM\%rkey%\ztwin.exe" /f /ve /d %rdir%\ztree\ztw.exe

:: winassoc
reg add "HKLM\%rkey%\wassociate.exe" /f /ve /d %rdir%\wassoc\wassociate.exe

:: winimage
reg add "HKLM\%rkey%\winimage32.exe" /f /ve /d %rdir%\winimage\winimage.exe

:: winzip (aka 7zfm) H:\PROGRAM\K7-Zip\7zFM.exe
reg add "HKLM\%rkey%\winzip.exe" /f /ve /d "%ProgramFiles%\7-Zip\7zfm.exe"
reg add "HKLM\%rkey%\winzip32.exe" /f /ve /d "%ProgramFiles%\7-Zip\7zfm.exe"
 
alias cdtc=`cdd "%_tcfolder"`
When executed in a tab of a TCMD window sets the current folder of the tab's tcc process to what is seen in the folder file list pane.
 
Here go some of mine:

A colorful version of cd, for all drives (inspired by Unix's pwd, actually):

Code:
[COLOR=Blue]pwd=for %A in (%_ready) do ( echo ^e[%COLORES_DE_DISCOS[%@eval[%@ascii[%@instr[0,1,%A]]-65]]m%@format[-12,%@label[%A]] %@cwds[%A]^e[0m )[/COLOR]


COLORES_DE_DISCOS is an array defined in tcstart.btm:

Code:
[SIZE=1]unsetarray /Q COLORES_DE_DISCOS
setarray COLORES_DE_DISCOS[26]
set COLORES_DE_DISCOS[0]=37;2
set COLORES_DE_DISCOS[1]=32;1
set COLORES_DE_DISCOS[2]=32;2
set COLORES_DE_DISCOS[3]=33;2
set COLORES_DE_DISCOS[4]=32;1
set COLORES_DE_DISCOS[5]=36;2
set COLORES_DE_DISCOS[6]=36;1
set COLORES_DE_DISCOS[7]=36;1
set COLORES_DE_DISCOS[8]=36;1
set COLORES_DE_DISCOS[9]=36;1
set COLORES_DE_DISCOS[10]=37;2
set COLORES_DE_DISCOS[11]=37;2
set COLORES_DE_DISCOS[12]=33;1
set COLORES_DE_DISCOS[13]=31;1
set COLORES_DE_DISCOS[14]=37;2
set COLORES_DE_DISCOS[15]=35;1
set COLORES_DE_DISCOS[16]=37;2
set COLORES_DE_DISCOS[17]=31;1
set COLORES_DE_DISCOS[18]=31;1
set COLORES_DE_DISCOS[19]=37;2
set COLORES_DE_DISCOS[20]=37;2
set COLORES_DE_DISCOS[21]=37;2
set COLORES_DE_DISCOS[22]=37;2
set COLORES_DE_DISCOS[23]=37;2
set COLORES_DE_DISCOS[24]=37;2
set COLORES_DE_DISCOS[25]=37;2
rem Significado de cada color.
rem
rem Intensidad normal: discos no removibles. Intensidad alta (brillante): discos removibles.
rem
rem Verde: partición principal de cada disco duro interno.
rem Amarillo (no brillante): discos sustituidos.
rem Cian: particiones secundarias de cada disco duro interno.
rem Blanco: discos sin significado especial.
rem
rem Rojo brillante: CD-ROMs.
rem Verde brillante: pendrives.
rem Amarillo brillante: discos externos (el de 1TB, etc.).
rem Violeta brillante: discos externos cuestionados (mi passport).
rem Cian brillante: tarjetas SD, CF, etcétera.
rem
rem DISPONIBLE: negro brillante, azul brillante (ÚLTIMA opción), magenta (penúltima opción) y blanco brillante.
rem NO USAR: negro, rojo y azul.
[/SIZE]

(I should translate that comment block into english.)

An extended version of free, for all ready drives:

Code:
[COLOR=Blue]freee=for %A in (%_ready) do if "%A" eq "%@left[2,%@truename[%A]]" (free %A)[/COLOR]


(some of you will remember it from this thread: http://jpsoft.com/forums/showthread.php?t=2556 )

A convenient shorthand:

Code:
[COLOR=Blue]..*....................=`cd %0`[/COLOR]

(this one has been in my alias.txt for so many years, I can't remember where it came from - I *think* it wasn't my invention)

Permanent settings for some commands:

Code:
[COLOR=Blue]move=*move /R
select=*select /H/Ou
say=*say /A[/COLOR]



I have more aliases, but they're all instances of stuff nchernoff has already mentioned (path pollution avoidance, shortcuts, etc.).
 
----- Original Message -----
From: mfarah
To: [email protected]
Sent: Thursday, 2011. March 10. 18:00
Subject: RE: [T&T - Aliases-t-172] Re: Useful short aliases
Quote:
Originally Posted by David Marcus
What is "say"?

say /? returns "Speaks the specified text." :-)

The /A option makes TCC execute it asynchronically.
--- end quote ---

SAY.DLL is a plugin from Charles Dye. Beware! Do not issue the command "help
say" - it keeps on saying the HELP until it is finished...
--
Steve
 
A convenient shorthand:

Code:
[/COLOR][/SIZE][COLOR=black] [/COLOR] [SIZE=2][COLOR=black]..*....................=`cd %0`[/COLOR][/SIZE][SIZE=2][COLOR=black]


I used something similar for years, dating back to 4DOS, but took it out of my aliases list two or three major versions back. It's no longer needed. Recent versions of TCC will treat a directory name as an implied CDD even if it doesn't end with a trailing backslash.

 
SAY.DLL is a plugin from Charles Dye. Beware! Do not issue the command "help say" - it keeps on saying the HELP until it is finished...

Undocumented feature:

Code:
help say & delay 2 & say /k

Only useful for asynchronous speech, which that online help text is.
 
----- Original Message -----
From: Charles Dye

Undocumented feature:

Code:
help say & delay 2 & say /k
Only useful for asynchronous speech, which that online help text is.
----- End Original Message -----

Well, nobody expects "help say" to start speaking! It is contrary to the
documentation of the HELP command. In fact I did not recall whence SAY came,
so I just issued HELP SAY, and had to press my mute button to be able to
think. Only after that did I use the TCC internal WHICH command to determine
where the command is implemented.

The "quick help" of the command is really full help (except the /K option is
not included); that's what I expected to see. I think a better idea would be
to use piping to do the same:
help say | say
(which is a little verbose but makes the intent clear).
--
Steve
 
Well, nobody expects "help say" to start speaking! It is contrary to the documentation of the HELP command. In fact I did not recall whence SAY came, so I just issued HELP SAY, and had to press my mute button to be able to think. Only after that did I use the TCC internal WHICH command to determine where the command is implemented.

Originally it was just a message box, but then I had the idea that in this particular case it might make sense to consider the needs of the visually impaired.

Anybody else have an opinion? Especially anyone who has difficulty reading screen text? It'd be trivial to change it back to a popup.
 


I used something similar for years, dating back to 4DOS, but took it out of my aliases list two or three major versions back. It's no longer needed. Recent versions of TCC will treat a directory name as an implied CDD even if it doesn't end with a trailing backslash.


You're right! I just commented it out from my aliases file.

Thanks.
 
This article is for sharing simple aliases
A handful of favourites that might have a general application:
Code:
tohex=echo %@convert[10,16,%1]
fromhex=echo %@convert[16,10,%1]
calc=echo %@eval[%$]
indir=pushd %1 %+ %2$ %+ popd
trace=setdos /y1 %+ %&
howlong=timer on %+ %$ %+ timer
ele*vate=*start /elevated
The latter has considerably reduced my frustration with running as a normal user under Windows 7 with UAC set to the second 'highest' level, and even has the neat side effect that issuing an elevate on its own starts a new TCC prompt elevated.
 
On 2011-04-22 07:33, Steve Pitts wrote:

trace=setdos /y1 %+ %&



This SETDOS setting is no longer supported. I used to use an
identical alias under 4DOS but had to change it to call BDEBUGGER
when TCC became the norm.
 
Code:
ele*vate=*start /elevated
The latter has considerably reduced my frustration with running as a normal user under Windows 7 with UAC set to the second 'highest' level, and even has the neat side effect that issuing an elevate on its own starts a new TCC prompt elevated.

Just out of curiosity, what is the purpose of the * in ele*vate? I added the alias as typed, and it appears that the alias can be invoked by either elevate or ele*vate.

Thanks,
Danny
 
Just out of curiosity, what is the purpose of the * in ele*vate? I added the alias as typed, and it appears that the alias can be invoked by either elevate or ele*vate.

It can also be invoked as ELE, or ELEV, or....
 
Danny wrote:
| Quote:
| Originally Posted by Steve Pitts
| Code:
| ele*vate=*start /elevatedThe latter has considerably reduced my
| frustration with running as a normal user under Windows 7 with UAC
| set to the second 'highest' level, and even has the neat side effect
| that issuing an elevate on its own starts a new TCC prompt elevated.
|
| Just out of curiosity, what is the purpose of the * in ele*vate? I
| added the alias as typed, and it appears that the alias can be
| invoked by either elevate or ele*vate.

As described in HELP topic Alias, to invoke the alias you need to enter only
the part of the alias name BEFORE the asterisk. Additional characters are
optional, but must be correct. The alias can be invoked as :

ELE
ELEV
ELEVA
ELEVAT
ELEVATE
--
Steve
 
Hi, All!

Code:
.*....................=`%0.\`
A dot before the asterisk

Code:
alias=al*ias
al @Shift-F7=`for /H /A:D %i in (*.*) %i`
al @Shift-F8=`for %i in (*.*) %i`
al calc=`ScrPut %_row 5 Bri Gre On Bla Result is: %+ ScrPut %_row 20 Bri Whi On Bla %@eval[%$]`
al s1=`se /o-d /a:-d %1 (*.*) %2 %3`
al sc=`*describe %$`
al se=`Select /ha:`
al tm=`timer /1 %+ %$ %+ scrput %_row 20 Bri Gre On Bla %_TIME done in under  %@timer[1] %+ echo. %+ timer /q1`
 
Here are 2 aliases that I often use:

1. "disk free"
Code:
(system)  C:\...\TCCLE >alias df
for %d in ( %_drives ) if %@ready[%d] eq 1 echo %d %@format[8,%@comma[%@disktotal[%d,M]]] %@format[8,%@comma[%@diskused[%d,M]]] %@format[8,%@comma[%@diskfree[%d,M]]]  %@eval[ 100-(%@diskfre
e[%d] / %@disktotal[%d]*100=0)]%%
 
(system)  C:\...\TCCLE >df
C:   60.954   49.102   11.852   81%
D:  476.936  418.052   58.884   88%
E:  307.199  185.608  121.591   60%
F:  169.736   33.023  136.713   19%

2. show me my actual path line by line ("echo path")
Code:
(system)  C:\...\TCCLE >alias ep
for /t";" %p in (%path) echo %p
 
(system)  C:\...\TCCLE >ep
C:\Program Files (x86)\JPSoft\TCCLE\
C:\oracle\oraclexe\app\oracle\product\10.2.0\server\bin
C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common
C:\Windows\system32
C:\Windows
C:\Windows\System32\Wbem
C:\Windows\System32\WindowsPowerShell\v1.0\
C:\Program Files\Intel\DMIX
C:\Program Files (x86)\Sysinternals
C:\Program Files (x86)\Tools\WinMerge

hth
 
Code:
for %d in ( %_drives ) if %@ready[%d] eq 1 echo...

This can be simplified a tiny bit by using the _ready internal variable rather than _drives internal variable.
Code:
for %d in (%_ready) do echo...
That variable should be available in all the later major versions of TCC.
 
This can be simplified a tiny bit by using the _ready internal variable rather than _drives internal variable.
Code:
for %d in (%_ready) do echo...
That variable should be available in all the later major versions of TCC.

Thank you!
But be ware, the _ready is not available in LE, but _drives + @ready are...
 
Just out of curiosity, what is the purpose of the * in ele*vate? I added the alias as typed, and it appears that the alias can be invoked by either elevate or ele*vate.

Thanks,
Danny

What of the * prefix to the start command? What is the difference, if any, between start and *start?
 
What of the * prefix to the start command? What is the difference, if any, between start and *start?

Prefixing an asterisk disables alias expansion. START might be an alias to be expanded by the parser; *START will not be interpreted as an alias. This type of construction is sometimes used to prevent infinite recursion when using aliases to modify commands:

Code:
alias start=*start /pgm
 
Back
Top
[FOX] Ultimate Translator
Translate