Skip to content

Instantly share code, notes, and snippets.

@rtorr
Last active Aug 20, 2021
Embed
What would you like to do?
Visual Studio Code fish shell shortcut

Put this in your config.fish

run

code path/to/project

function code
set location "$PWD/$argv"
open -n -b "com.microsoft.VSCode" --args $location
end
@eltonjuan

This comment has been minimized.

Copy link

@eltonjuan eltonjuan commented Nov 29, 2015

Thanks for this! Was struggling with figuring out how to pass the correct args. :)

@marcleblanc

This comment has been minimized.

Copy link

@marcleblanc marcleblanc commented Jun 11, 2016

Added this to my ~/.config/fish/config.fish file and works like a charm. Thanks!

@dideler

This comment has been minimized.

Copy link

@dideler dideler commented Nov 4, 2017

What problem is this solving? On Linux, code will automatically be in your PATH when you install VS Code, and on a Mac you can Install 'code' command in PATH via the command palette.

@Anenth

This comment has been minimized.

Copy link

@Anenth Anenth commented Nov 11, 2017

this wont support flags like --disable-extensions! any solution?

@nurikk

This comment has been minimized.

Copy link

@nurikk nurikk commented Aug 24, 2018

better to use official launcher, it resolves relative urls
code /etc/hosts code ../hosts
https://code.visualstudio.com/docs/setup/mac#_launching-from-the-command-line

@madsem

This comment has been minimized.

Copy link

@madsem madsem commented Jul 8, 2019

if you already have an alias named 'code', like I do, I think this is a great alternative. I don't find any option to use the official launcher under a different alias

@duganchen

This comment has been minimized.

Copy link

@duganchen duganchen commented Feb 13, 2020

This would be closer to the way it works in BASH and ZSH:

function code --wraps='/Applications/Visual Studio Code 2.app/Contents/Resources/app/bin/code' --description 'alias code /Applications/Visual Studio Code 2.app/Contents/Resources/app/bin/code'
  /Applications/Visual\ Studio\ Code\ 2.app/Contents/Resources/app/bin/code $argv;
end

I used FISH's "alias" command to generate the function, and then I edited the function to add the escape characters for the spaces in the path.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment