From 8a6df7703e5a38b14b4321eeeec819a84ee40f19 Mon Sep 17 00:00:00 2001 From: Jonathan Martz Date: Wed, 18 Dec 2019 09:29:54 +0100 Subject: [PATCH] add function for endsWith and startWith, add todo for fix prozess finder --- worktime-log.php | 37 +++++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/worktime-log.php b/worktime-log.php index 32197a8..4ae181d 100644 --- a/worktime-log.php +++ b/worktime-log.php @@ -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; @@ -21,7 +40,7 @@ $locked = true; } -$commands = explode(PHP_EOL, $phpstorm); +$commands = explode(PHP_EOL, $find['phpstorm']); $data = [ 'locked' => $locked @@ -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 + ]; + } } }