VSCode Remote Containers CLI.alfredworkflow.zip
- Click 「Configure workflow and variables」
- Edit path
This workflow uses zsh, but you can modify it to fit your shell.
VSCode Remote Containers CLI.alfredworkflow.zip
This workflow uses zsh, but you can modify it to fit your shell.
# frozen_string_literal: true | |
# !/usr/bin/env ruby | |
require 'json' | |
module VSCodeRemoteContainer | |
class Utility | |
attr_accessor :bin_path | |
def initialize | |
@bin_path = ENV['GHQ_PATH'] || '/usr/local/bin' | |
end | |
def generate_url(root_path) | |
folder = find_workspace_folder(root_path) | |
path = "dev-container+#{root_path.unpack('H*')[0]}" | |
print "vscode-remote://#{URI.encode_www_form_component(path)}#{folder}" | |
end | |
def find_workspace_folder(root_path) | |
unless File.exist?("#{root_path}/.devcontainer/devcontainer.json") | |
puts 'Not found devcontainer.json file.' | |
return | |
end | |
config = JSON.parse(File.read("#{root_path}/.devcontainer/devcontainer.json")) | |
config['workspaceFolder'] | |
end | |
def ghq_exists? | |
!`which #{@bin_path}/ghq`.empty? | |
end | |
def search | |
return unless ghq_exists? | |
result = [] | |
`#{@bin_path}/ghq list --full-path`.split(/\R/).each do |d| | |
Dir.foreach(d) do |path| | |
next if ['.', '..'].include?(path) | |
file = File.join(d, path) | |
result << d if file.include?('.devcontainer') | |
end | |
end | |
result | |
end | |
end | |
end |
require './cli.rb' | |
query = ARGV[0] | |
VSCodeRemoteContainer::Utility.new.generate_url(query) |
query=$1 | |
source ~/.zshrc | |
code --folder-uri $query |
require './cli.rb' | |
def item(index, name) | |
<<ITEM | |
<item uid="#{index}" arg="#{name}"> | |
<title>"#{File.basename(name)}"</title> | |
</item> | |
ITEM | |
end | |
targets = VSCodeRemoteContainer::Utility.new.search | |
items = targets.map.with_index { |t, i| item(i, t)}.join('') | |
puts <<EOS | |
<items> | |
#{items}</items> | |
EOS |