[prev] [next] [up] [top]

Conversion guide for csh aliases


  1. If the csh alias references "parameters" (\!:1 \!* etc.), then in zsh you need a function (referencing $1 $* etc.). Otherwise, you can use a zsh alias.

  2. If you use a zsh function, you need to refer at least to $* in the body (inside the { }). Parameters don't magically appear inside the { } the way they get appended to an alias.

  3. If the csh alias references its own name (alias rm "rm -i"), then in a zsh function you need the command keyword (function rm() { command rm -i $* }), but in a zsh alias you don't (alias rm="rm -i").

  4. If you have aliases that refer to each other (alias ls "ls -C"; alias lf "ls -F" ==> lf == ls -C -F) then you must either:

Those first four are all you really need, but here are four more for heavy csh alias junkies:
  1. Mapping from csh alias "parameter referencing" into zsh function (assuming shwordsplit and ksharrays are NOT set in zsh):
    csh zsh
    \!* $* (or $argv)
    \!^ $1 (or $argv[1])
    \!:1 $1
    \!:2 $2 (or $argv[2]), etc.)
    \!$ $*[$#] (or $argv[$#], or $*[-1])
    \!:1-4 $*[1,4]
    \!:1- $*[1,$#-1] (or $*[1,-2])
    \!^- $*[1,$#-1]
    \!*:q "$@" ($*:q doesn't work (yet))
    \!*:x $=* ($*:x doesn't work (yet))

  2. Remember that it is NOT a syntax error in a zsh function to refer to a position ($1, $2, etc.) greater than the number of parameters. (E.g., in a csh alias, a reference to \!:5 will cause an error if 4 or fewer arguments are given; in a zsh function, $5 is the empty string if there are 4 or fewer parameters.)

  3. To begin a zsh alias with a - (dash, hyphen) character, use alias --:
    csh zsh
    alias - "fg %-" alias -- -="fg %-"

  4. Stay away from alias -g in zsh until you REALLY know what you're doing.

[prev] [next] [up] [top]
Mark D. Borges