#!/bin/php
<?php

$url = parse_url($argv[1] ?? '');

if (($url['scheme'] ?? 'hovno') != 'vscode') {
    exec('notify-send "Unknown scheme " "'.$url['scheme'].'" -u critical');
    exit;
}

parse_str($url['query'], $query);

$remote = $query['url'];
preg_match('|/(?<repo>[^/]*)\.git$|', $remote, $res);

$repo = $res['repo'];

chdir("{{.chezmoi.homeDir }}/devel/");
exec("git clone '$remote'");
chdir($repo);
pcntl_exec('/bin/zsh');
