1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Useful short aliases

Discussion in 'T&T - Aliases' started by nchernoff, Jun 9, 2008.

  1. nchernoff

    nchernoff Administrator
    Staff Member

    Joined:
    May 16, 2008
    Messages:
    42
    Likes Received:
    1
    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
     
    #1
    noahcoad likes this.
  2. AnrDaemon

    Joined:
    Aug 23, 2010
    Messages:
    18
    Likes Received:
    1
    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
    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.
     
    #2
    noahcoad likes this.
  3. w_krieger

    Joined:
    Nov 2, 2008
    Messages:
    78
    Likes Received:
    0
    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"
    
     
    #3
  4. Dmitry L. Kobyakov

    Joined:
    Mar 9, 2011
    Messages:
    10
    Likes Received:
    0
    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.
     
    #4
  5. mfarah

    Joined:
    Nov 2, 2009
    Messages:
    173
    Likes Received:
    3
    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.).
     
    #5
  6. David Marcus

    Joined:
    Jun 4, 2008
    Messages:
    577
    Likes Received:
    0
    What does this do?

    What is "say"?
     
    #6
  7. mfarah

    Joined:
    Nov 2, 2009
    Messages:
    173
    Likes Received:
    3
    .. == cd ..
    ... == cd ..\..
    .... == cd ..\..\..
    ..... == cd ..\..\..\..

    (and so on)



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

    The /A option makes TCC execute it asynchronically.
     
    #7
  8. Steve Fabian

    Joined:
    May 20, 2008
    Messages:
    3,531
    Likes Received:
    4
    ----- Original Message -----
    From: mfarah
    To: ESFabian@zenge.org
    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
     
    #8
  9. Charles Dye

    Charles Dye Super Moderator
    Staff Member

    Joined:
    May 20, 2008
    Messages:
    2,738
    Likes Received:
    16


    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.

     
    #9
  10. Charles Dye

    Charles Dye Super Moderator
    Staff Member

    Joined:
    May 20, 2008
    Messages:
    2,738
    Likes Received:
    16
    Undocumented feature:

    Code:
    help say & delay 2 & say /k
    
    Only useful for asynchronous speech, which that online help text is.
     
    #10
  11. Steve Fabian

    Joined:
    May 20, 2008
    Messages:
    3,531
    Likes Received:
    4
    ----- 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
     
    #11
  12. Charles Dye

    Charles Dye Super Moderator
    Staff Member

    Joined:
    May 20, 2008
    Messages:
    2,738
    Likes Received:
    16
    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.
     
    #12
  13. mfarah

    Joined:
    Nov 2, 2009
    Messages:
    173
    Likes Received:
    3
    I should have mentioned it's a plugin. I forgot that, since tend to consider the plugins I use as part of TCC.
     
    #13
  14. mfarah

    Joined:
    Nov 2, 2009
    Messages:
    173
    Likes Received:
    3
    You're right! I just commented it out from my aliases file.

    Thanks.
     
    #14
  15. mfarah

    Joined:
    Nov 2, 2009
    Messages:
    173
    Likes Received:
    3
    Hey, that's nice! Should *be* documented...
     
    #15
  16. Steve Pitts

    Joined:
    Jul 7, 2008
    Messages:
    133
    Likes Received:
    0
    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.
     
    #16
  17. WavSlave

    Joined:
    May 29, 2008
    Messages:
    37
    Likes Received:
    0
    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.
     
    #17
  18. Steve Pitts

    Joined:
    Jul 7, 2008
    Messages:
    133
    Likes Received:
    0
    Well spotted that man. I can't even claim that it is in the version that I'm used to using (v7) because it seems to have disappeared from there too.
     
    #18
  19. Danny

    Joined:
    May 30, 2008
    Messages:
    10
    Likes Received:
    0
    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
     
    #19
  20. Charles Dye

    Charles Dye Super Moderator
    Staff Member

    Joined:
    May 20, 2008
    Messages:
    2,738
    Likes Received:
    16
    It can also be invoked as ELE, or ELEV, or....
     
    #20
  21. Steve Fabian

    Joined:
    May 20, 2008
    Messages:
    3,531
    Likes Received:
    4
    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
     
    #21
  22. David Marcus

    Joined:
    Jun 4, 2008
    Messages:
    577
    Likes Received:
    0
    On the Help page for ALIAS, see "Partial (Abbreviated) Alias Names".
     
    #22
  23. Alexander

    Joined:
    Jan 29, 2012
    Messages:
    5
    Likes Received:
    0
    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`
    
     
    #23
  24. Frank

    Joined:
    Aug 2, 2011
    Messages:
    258
    Likes Received:
    4
    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
     
    #24
    Avi Shmidman and Alexander like this.
  25. Charles Dye

    Charles Dye Super Moderator
    Staff Member

    Joined:
    May 20, 2008
    Messages:
    2,738
    Likes Received:
    16
    I used to do this, but it's no longer necessary. Current versions of TCC recognize a directory name as an implicit CDD even if it doesn't end with a backslash.
     
    #25
  26. WavSlave

    Joined:
    May 29, 2008
    Messages:
    37
    Likes Received:
    0
    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.
     
    #26
  27. Frank

    Joined:
    Aug 2, 2011
    Messages:
    258
    Likes Received:
    4
    Thank you!
    But be ware, the _ready is not available in LE, but _drives + @ready are...
     
    #27
  28. Alexander

    Joined:
    Jan 29, 2012
    Messages:
    5
    Likes Received:
    0
    Frank, WavSlave, Charles Dye, thanks !
     
    #28
  29. Giles Evans

    Joined:
    May 6, 2013
    Messages:
    3
    Likes Received:
    0
    What of the * prefix to the start command? What is the difference, if any, between start and *start?
     
    #29
  30. Charles Dye

    Charles Dye Super Moderator
    Staff Member

    Joined:
    May 20, 2008
    Messages:
    2,738
    Likes Received:
    16
    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
    
     
    #30
    Giles Evans likes this.

Share This Page