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.
We can declare a function which allows us to run multiple commands under one alias.
Aliases are disabled for noninteractive shells (that is, shell scripts). Use the unalias builtin to remove an alias.
@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]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With