Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write a multi-command alias in xonsh?

Tags:

shell

xonsh

In bash and zsh I used to write:

alias nb='cd /home/lincoln/Dropbox/nupis/ && jupyter notebook'

But in xonsh this returns an error saying that the command was not found. The tutorial's section on aliases says that I should do something like:

aliases['g'] = 'git status -sb' 

I could make this work in the case of only one command, but when I try the two commands of my bash example, it complains that I am giving too many inputs to cd.

Note: I know I could import the alias from the other shells, but I am interested in learning to do this in xonsh.

like image 912
lincolnfrias Avatar asked Sep 27 '16 12:09

lincolnfrias


People also ask

Can alias run multiple commands?

We can declare a function which allows us to run multiple commands under one alias.

Can you use alias in shell script?

Aliases are disabled for noninteractive shells (that is, shell scripts). Use the unalias builtin to remove an alias.


1 Answers

@lincolnfrias, xonsh does not yet have support for string aliases that have multiple commands. This is a bug / deficiency that will hopefully be addressed soon. Until then, though, you can use a function alias for this behaviour.

def _nb(args, stdin=None):
    cd /home/lincoln/Dropbox/nupis/ && jupyter notebook

aliases['nb'] = _nb

Or if you really wanted to do this in one line:

aliases['nb'] = lambda a, s: ![cd /home/lincoln/Dropbox/nupis/] and ![jupyter notebook]
like image 115
Anthony Scopatz Avatar answered Oct 12 '22 06:10

Anthony Scopatz