Search code examples
fish

Alias with spaces and arguments in Fish 3


I am using fish 2 on the Windows Subsystem for Linux with the following aliases:

alias n++="/mnt/c/Program\ Files\ \(x86\)/Notepad++/notepad++.exe"
alias d "'/mnt/c/Program Files\ (x86)/Microsoft\ Visual\ Studio/2019/Enterprise/Common7/IDE/devenv.exe' /Edit"

Now I updated to fish 3, but the aliases stopped working. When I enter "d FileName.cs" I get the following message:

fish: Unknown command: x86
in command substitution
    called on line 1 of file -
in function 'd' with arguments 'FileName.cs'
-: Unknown error while evaluating command substitution
in function 'd' with arguments 'FileName.cs'

It seems that the quotes are ignored. How the aliases has to be changed to work?


Solution

  • Short answer: It's a bug in the alias function, tho your escaping is inconsistent.

    "'/mnt/c/Program Files\ (x86)/Microsoft\ Visual\ Studio/2019/Enterprise/Common7/IDE/devenv.exe' /Edit"

    Easy workaround is to fully escape it:

    alias d "'/mnt/c/Program\ Files\ \(x86\)/Microsoft\ Visual\ Studio/2019/Enterprise/Common7/IDE/devenv.exe' /Edit"
    

    Or, as alias is just a (hacky) function that writes functions, skip the middle man and just write a function:

    function d
        "/mnt/c/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/Common7/IDE/devenv.exe" /Edit $argv
    end
    

    Define that interactively and use funcsave d, or write it manually to config.fish or a file called ~/.config/fish/functions/d.fish.