Skip to content

Instantly share code, notes, and snippets.

@rtorr
Last active April 16, 2025 11:06
Show Gist options
  • Select an option

  • Save rtorr/233bf6ffd81b6ecdf534 to your computer and use it in GitHub Desktop.

Select an option

Save rtorr/233bf6ffd81b6ecdf534 to your computer and use it in GitHub Desktop.
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
@dideler
Copy link
Copy Markdown

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
Copy link
Copy Markdown

Anenth commented Nov 11, 2017

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

@nurikk
Copy link
Copy Markdown

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
Copy link
Copy Markdown

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
Copy link
Copy Markdown

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.

@odravison
Copy link
Copy Markdown

Visual code has a new way to add code into your PATH env, if you're not already using code as a command for other thing ....

  1. Open visual studio code;
  2. Hit + SHIFT + P (mac) or ALT+SHIFT+P (windows/linux);
  3. Then search for: "Install 'code' command in PATH" and hit ENTER;
  4. Authenticate yourself;

This should add code command into your PATH

source: https://stackoverflow.com/questions/29955500/code-is-not-working-in-on-the-command-line-for-visual-studio-code-on-os-x-ma

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