如何配置Gio在vscode中打开Dockerfile?

如何配置Gio在vscode中打开Dockerfile?

当我运行 时gio open Dockerfile,它会在 gedit (/usr/bin/gedit) 中打开 Dockerfile,但我希望它在 Visual Studio Code (/usr/bin/code) 中打开。如何配置 Gio?

答案1

希望这不是解决问题的最佳方法,但这是我知道的唯一方法:第一次运行

sudo apt-get install php-cli;

然后做/usr/local/bin/giowrapper.php一个

#!/usr/bin/env php
<?php

declare(strict_types=1);
// passthru() don't let children inherit stdin/pipes/pty, so use proc_open() instead
// (but even proc_open do not passthru signals, so it's not a perfect solution)
function cmd(string $cmd)
{
    $descriptorspec = array();
    $pipes = array();
    $process = proc_open($cmd, $descriptorspec, $pipes);
    $exitCode = proc_close($process);
    exit($exitCode);
}
$cmd = array(
    0 => '/usr/bin/gio',
);
$argstart = 1;
if ($argc === 3 && $argv[1] === 'open') {
    $path = $argv[2];
    $ext = strtolower(pathinfo($path, PATHINFO_EXTENSION) ?: basename($path) ?: $path);
    if (in_array($ext, array(
        'dockerfile',
        // 'py',
        // 'js',
        // 'php',
    ))) {
        $cmd[0] = 'code';
        $argstart = 2;
    }
}
for ($i = $argstart; $i < $argc; ++$i) {
    $cmd[] = escapeshellarg($argv[$i]);
}
//var_dump($cmd);
cmd(implode(' ', $cmd));

然后运行

sudo bash -c '
ln -s /usr/local/bin/giowrapper.php /usr/local/bin/gio;
chown root:root /usr/local/bin/giowrapper.php /usr/local/bin/gio;
chmod 0555 /usr/local/bin/giowrapper.php /usr/local/bin/gio;
'

瞧,gio open dockerfile现在可以在 vscode 中打开了!

但是这种方法确实有一个明显的缺点:硬编码调用的程序/脚本/usr/bin/gio不会gio受到/usr/bin/env gio影响。

相关内容