Skip to content

Instantly share code, notes, and snippets.

@m-bers
Last active January 19, 2023 16:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save m-bers/9dd91a378c178a0b0664147442e56ffc to your computer and use it in GitHub Desktop.
Save m-bers/9dd91a378c178a0b0664147442e56ffc to your computer and use it in GitHub Desktop.
lima/vscode automation

Lima / Visual Studio Code integration

Prerequisites

  • lima
  • vscode
  • jq
  • curl

Installation

sudo curl -o /usr/local/bin/lcode https://gist.githubusercontent.com/m-bers/9dd91a378c178a0b0664147442e56ffc/raw/c827b5e580bd6acd65c7fd988bd4b534e10b5b9b/lcode
sudo chmod +x /usr/local/bin/lcode
mkdir -p ~/.ssh/lima.d
echo "Include lima.d/*" >> ~/.ssh/config

Usage

lcode [FILE OR DIR] [Lima VM name]

Examples:

lcode                               # vscode remote to the default Lima instance, does not open a file or directory
lcode . ubuntu                      # vscode remote to the current working directory in a lima instance named "ubuntu"
lcode /Users/user/project/file.json # vscode remote to the default Lima instance, opens a file by absolute path
#!/bin/bash
Path="$(readlink -f ${1:-$PWD})"
Host="${2:-default}"
Port=$(limactl list --json | jq -r ". | select( .name==\"$Host\" ) .sshLocalPort")
cat <<EOF > $HOME/.ssh/lima.d/$Host
Host lima-$Host
HostName localhost
Port $Port
ControlPath "~/.lima/$Host/ssh.sock"
EOF
code --remote "ssh-remote+lima-$Host" $Path%
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment