Search code examples
zshzshrc

how to convert an csh to zsh alias that requires arguments


When using csh I use this alias:

alias s autossh -M 0 -t \!:1 \"tmux -2 attach -t $USER\!:2 -d \|\| tmux -2 new -s $USER\!:2 \"

That can help me to ssh to a remote server by using something like:

s 10.11.12.3 X

Where X is the suffix $USERX of the remote tmux session the one I can attach or create in case it doesn't exists.

I am currently using zsh but would like to continue using the same alias, therefore I would like to know how to properly convert this alias to work under zsh.


Solution

  • Use a shell function. csh uses aliases only because it doesn't have functions.

    s () {
        autossh -M 0 -t "$1" "tmux -2 attach -t $USER$2 -d || tmux -2 new -s $USER$2 "
    }
    

    (I think I replaced the parameters correctly, but it's been a few decades since I used csh.)