4

I am trying to alias an executable in a directory with a space in it. For example:

alias myfile="/home/ben/test case/myfile"

Now, this is not expanded the way I want (it thinks /home/ben/test is the executable). In bash you can add extra quotes:

alias myfile="'/home/ben/test case/myfile'"

Sadly, in fish this does not work. What should I do instead?

1
  • fish's alias is only a naive function for familiarity that creates functions with this name (and through eval!), and it's not surprising to find it buggy. github.com/fish-shell/fish-shell/blob/master/share/functions/… I think you'd better learn how to write fish functions, although that is neither friendly nor quite suitable for interactive fun. Commented Sep 21, 2015 at 13:40

3 Answers 3

5

alias in fish is just a wrapper for function builtin, it existed for backward compatible with POSIX shell. alias in fish didn't work as POSIX alias.

If you want the equivalent of POSIX alias, you must use abbr, which was added in fish 2.2.0:

abbr -a myfile "'/home/ben/test case/myfile'"

or:

abbr -a myfile "/home/ben/test\ case/myfile"
1
  • 1
    It used to work better! Unfortunately there is a regression in 2.2.0.
    – Zanchey
    Commented Sep 21, 2015 at 14:38
1

This answer is migrated from the comment area.

fish's alias is only a naive function for familiarity that creates functions with this name (and through eval), and it's not surprising to find it buggy. I think you'd better learn how to write fish functions.

For your example given, it is converted this line of eval:

function myfile --wraps /home/ben/test; /home/ben/test case/myfile $argv; end

Therefore using alias myfile="'/home/ben/test case/myfile'" won't help too, as it gives some stupid output like --wraps 'home/ben/test; '/home/ben/test case/myfile' (look at that lonely single quote!)

So write a function yourself, and you will find fish is such nonsense that is ruins the interactive fun and the friendliness:

function myfile --wraps '/home/ben/test case/myfile'; '/home/ben/test case/myfile' $argv; end

Note that I haven't really tested this, and it only works if I got the idea of the syntax right.

And actually I have got enough of the f??????-id??tic-shell in 40 minutes when I read through it's built-in functions the first time.

1

You're unfortunately being bitten by a bug in fish, where aliases containing whitespace are broken.

In any case, it is reasonably easy to write up a replacement:

function myfile
    /home/ben/test\ case/myfile $argv;
end
funcsave myfile

That will define a new function (myfile), set the contents to run your target with all of the command line arguments ($argv) and then save the function so that it is automatically loaded (funcsave).

As noted in another answer, the abbreviation command abbr is another option for defining aliases, although in your case I think a function (alias) is actually more useable.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .