Skip to content

Instantly share code, notes, and snippets.

@ijortengab
Created December 26, 2024 06:50
Show Gist options
  • Save ijortengab/cd83ddc0f133fa2b24c0a1c2704a083a to your computer and use it in GitHub Desktop.
Save ijortengab/cd83ddc0f133fa2b24c0a1c2704a083a to your computer and use it in GitHub Desktop.
#!/usr/bin/php
<?php
if (!isset($_SERVER['argv'][1])) {
echo 'Example: C:\Users\ijortengab\AppData\Local\Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\LocalState\settings.json'.PHP_EOL;
echo 'The location of settings.json file: ';
if (FALSE !== ($line = fgets(STDIN))) {
$filename = rtrim($line);
}
}
else {
$filename = $_SERVER['argv'][1];
}
if (!is_file($filename)) {
$letter = substr($filename, 0, 1);
$other = substr($filename, 2);
$filename = '/mnt/'.strtolower($letter).str_replace('\\','/', $other);
}
if (!is_file($filename)) {
die('File is not exists.'.PHP_EOL);
}
$contents = file_get_contents($filename);
$json = json_decode($contents, true);
if (null === $json) {
die('JSON is not valid.'.PHP_EOL);
}
$json['copyOnSelect'] = true;
$json['multiLinePasteWarning'] = false;
$json['largePasteWarning'] = false;
$json['confirmCloseAllTabs'] = false;
$json['actions'][] = ['command' => 'newTab', 'keys' => 'ctrl+t'];
$json['actions'][] = ['command' => 'duplicateTab', 'keys' => 'ctrl+shift+t'];
$json['actions'][] = ['command' => 'newWindow', 'keys' => 'ctrl+n'];
$json['actions'][] = ['command' => 'nextTab', 'keys' => 'ctrl+pgdn'];
$json['actions'][] = ['command' => 'prevTab', 'keys' => 'ctrl+pgup'];
$json['actions'][] = ['command' => ['action' => 'switchToTab', 'index' => 0], 'keys' => 'ctrl+1'];
$json['actions'][] = ['command' => ['action' => 'switchToTab', 'index' => 1], 'keys' => 'ctrl+2'];
$json['actions'][] = ['command' => ['action' => 'switchToTab', 'index' => 2], 'keys' => 'ctrl+3'];
$json['actions'][] = ['command' => ['action' => 'switchToTab', 'index' => 3], 'keys' => 'ctrl+4'];
$json['actions'][] = ['command' => ['action' => 'switchToTab', 'index' => 4], 'keys' => 'ctrl+5'];
$json['actions'][] = ['command' => ['action' => 'switchToTab', 'index' => 5], 'keys' => 'ctrl+6'];
$json['actions'][] = ['command' => ['action' => 'switchToTab', 'index' => 6], 'keys' => 'ctrl+7'];
$json['actions'][] = ['command' => ['action' => 'switchToTab', 'index' => 7], 'keys' => 'ctrl+8'];
$json['actions'][] = ['command' => ['action' => 'switchToTab', 'index' => 8], 'keys' => 'ctrl+9'];
$json['actions'][] = ['command' => 'closePane', 'keys' => 'ctrl+w'];
$json['actions'][] = ['command' => 'paste', 'keys' => 'ctrl+v'];
$json['actions'][] = ['command' => 'find', 'keys' => 'ctrl+f'];
$json['actions'][] = ['command' => ['action' => 'splitPane', 'split' => 'auto', 'splitMode' => 'duplicate'], 'keys' => 'ctrl+d'];
$json['actions'][] = ['command' => ['action' => 'splitPane', 'split' => 'horizontal'], 'keys' => 'ctrl+_'];
$json['actions'][] = ['command' => ['action' => 'splitPane', 'split' => 'vertical'], 'keys' => 'ctrl+|'];
if (empty($json['profiles']['defaults']) && is_array($json['profiles']['defaults'])) {
// Ubah ke empty object.
$json['profiles']['defaults'] = (object) [];
}
$contents = json_encode($json, JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES);
// Contoh: JSON_UNESCAPED_SLASHES
// "$help": "https:\/\/aka.ms\/terminal-documentation",
// menjadi
// "$help": "https://aka.ms/terminal-documentation",
// Contoh: JSON_FORCE_OBJECT
// "defaults": [],
// menjadi
// "defaults": {},
file_put_contents($filename, $contents);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment