Skip to content

Commit

Permalink
add function for endsWith and startWith, add todo for fix prozess finder
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan Martz committed Dec 18, 2019
1 parent 57876df commit 8a6df77
Showing 1 changed file with 29 additions and 8 deletions.
37 changes: 29 additions & 8 deletions worktime-log.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,35 @@
* @todo add support for vscode
*/

function startsWith($haystack, $needle)
{
$length = strlen($needle);
return (substr($haystack, 0, $length) === $needle);
}

function endsWith($haystack, $needle)
{
$length = strlen($needle);
if ($length == 0) {
return true;
}

return (substr($haystack, -$length) === $needle);
}

$filename = 'config.json';
$file = file_get_contents($filename);

$config = json_decode($file, JSON_FORCE_OBJECT);

$phpstorm = exec('ps -aux | grep -i '.$config['filter']);
$command['phpstorm'] = 'ps -aux | grep -i '.$config['filter'];
$find['phpstorm'] = exec($command['phpstorm']);

/**
* @todo add as requirement to README.md
* @todo fix prozess finder
*/
$locked = exec('gnome-screensaver-command -q | grep "is active"');
$locked = exec('gnome-screensaver-command -q | grep -i "is active"');

if(empty($locked)){
$locked = false;
Expand All @@ -21,7 +40,7 @@
$locked = true;
}

$commands = explode(PHP_EOL, $phpstorm);
$commands = explode(PHP_EOL, $find['phpstorm']);

$data = [
'locked' => $locked
Expand All @@ -33,12 +52,14 @@
if(!empty($command[29])){
$project = explode($config['folder']. '/', $command[29])[1];

$branch = exec('cd '. $command[29].' && git rev-parse --abbrev-ref HEAD');
if(!endsWith($command[29], 'phpstorm.sh')){
$branch = exec('cd '. $command[29].' && git rev-parse --abbrev-ref HEAD');

$data[] = [
'project' => $project,
'branch' => $branch
];
$data[] = [
'project' => $project,
'branch' => $branch
];
}
}
}

Expand Down

0 comments on commit 8a6df77

Please sign in to comment.