Skip to content

Commit

Permalink
add tail command
Browse files Browse the repository at this point in the history
  • Loading branch information
Recca Tsai committed Apr 5, 2016
1 parent 5330ef5 commit d068586
Show file tree
Hide file tree
Showing 9 changed files with 137 additions and 27 deletions.
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,26 +131,56 @@ class Kernel extends ConsoleKernel
## ScreenShot

### Available Commands
```bash
$ help
```
![Available Commands](https://cdn.rawgit.com/recca0120/terminal/master/screenshots/available-commands.png)

### Artisan List
```bash
$ artisan
```
![Artisan List](https://cdn.rawgit.com/recca0120/terminal/master/screenshots/artisan-list.png)

### Migrate
```bash
$ artisan migrate --seed
```
![Migrate](https://cdn.rawgit.com/recca0120/terminal/master/screenshots/artisan-migrate.png)

### Artisan Tinker
```bash
$ artisan tinker
```
![Tinker](https://cdn.rawgit.com/recca0120/terminal/master/screenshots/artisan-tinker.png)

### Find Command
```bash
$ find ./ -name * -maxdepth 1
```
![Find Command](https://cdn.rawgit.com/recca0120/terminal/master/screenshots/find-command.png)

### Find and Delete
```bash
$ find ./storage/logs -name * -maxdepth 1 -delete
```
![Find and Delete](https://cdn.rawgit.com/recca0120/terminal/master/screenshots/find-and-delete.png)

### Vi
```bash
$ vi server.php
```
![Vi Command](https://cdn.rawgit.com/recca0120/terminal/master/screenshots/vi-command.png)

![Vi Editor](https://cdn.rawgit.com/recca0120/terminal/master/screenshots/vi-editor.png)

![Vi Save](https://cdn.rawgit.com/recca0120/terminal/master/screenshots/vi-save.png)

### Tail
```bash
$ tail
$ tail --line=1
$ tail server.php
$ tail server.php --line 5
```
![Tail Command](https://cdn.rawgit.com/recca0120/terminal/master/screenshots/tail-command.png)
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "1.3.x-dev"
"dev-master": "1.4.x-dev"
}
},
"autoload": {
Expand Down
30 changes: 15 additions & 15 deletions public/js/bundle.js

Large diffs are not rendered by default.

12 changes: 2 additions & 10 deletions resources/assets/js/bundle.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
'use strict';

let $;

if (!window.jQuery) {
$ = require('jquery');
} else {
$ = window.jQuery;
}

// $ = window.jQuery = window.$ = require('jquery');
import $ from './jquery';
require('jquery-mousewheel');
require('jquery.terminal');
require('jquery.terminal/js/unix_formatting');
Expand All @@ -29,7 +21,7 @@ import 'codemirror/mode/css/css';
import 'codemirror/mode/javascript/javascript';
import 'codemirror/mode/htmlmixed/htmlmixed';
import 'codemirror/mode/xml/xml';

class Loading {
constructor(term) {
this.$term = term;
Expand Down
10 changes: 10 additions & 0 deletions resources/assets/js/jquery.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
'user strict';

let $;
if (!window.jQuery) {
$ = window.jQuery = window.$ = require('jquery');
} else {
$ = window.jQuery;
}

export default $;
2 changes: 1 addition & 1 deletion resources/assets/js/polyfill.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

import $ from 'jquery';
import $ from './jquery';

if (!Object.assign) {
Object.assign = $.extend;
Expand Down
Binary file added screenshots/tail-command.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
77 changes: 77 additions & 0 deletions src/Console/Commands/Tail.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php

namespace Recca0120\Terminal\Console\Commands;

use Illuminate\Console\Command;
use Illuminate\Filesystem\Filesystem;

class Tail extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'tail
{path?}
{--lines=50 : output the last K lines, instead of the last 50}
';

/**
* The console command description.
*
* @var string
*/
protected $description = 'tail command';

/**
* handle.
*
* @param \Illuminate\Filesystem\Filesystem $filesystem
*
* @return void
*/
public function handle(Filesystem $filesystem)
{
$path = $this->argument('path');
$lines = $this->option('lines');

if (empty($path) === false) {
$path = ((is_null($this->laravel) === false) ? $this->laravel->basePath() : getcwd()).'/'.$path;
} else {
$path = (is_null($this->laravel) === false) ? $this->laravel->storagePath() : getcwd();
$path = collect($filesystem->glob($path.'/logs/*.log'))
->filter(function ($log) {
return is_file($log);
})
->sortByDesc(function ($log) {
return filectime($log);
})
->first();
}

$this->readLine($path, $lines);
}

protected function readLine($file, $lines = 50)
{
if (file_exists($file) === false) {
return 'tail: cannot open ‘'.$file.'’ for reading: No such file or directory';
}

$fp = fopen($file, 'r');
$i = 1;
$result = [];
while (!feof($fp)) {
if ($i > $lines) {
break;
}
$content = fgets($fp);
$result[] = $content;
$i++;
}
fclose($fp);

$this->line(implode('', $result));
}
}
1 change: 1 addition & 0 deletions src/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class Kernel extends ConsoleKernel
Commands\ArtisanTinker::class,
Commands\Find::class,
Commands\Mysql::class,
Commands\Tail::class,
Commands\Vi::class,
];
}

0 comments on commit d068586

Please sign in to comment.