diff --git a/app/Console/Controller/JumpController.php b/app/Console/Controller/JumpController.php index 275cc96..00c70ba 100644 --- a/app/Console/Controller/JumpController.php +++ b/app/Console/Controller/JumpController.php @@ -11,11 +11,11 @@ use Inhere\Console\Controller; use Inhere\Console\Exception\PromptException; -use Inhere\Console\IO\Input; use Inhere\Console\IO\Output; use Inhere\Kite\Kite; use Inhere\Kite\Lib\Jump\JumpShell; use Inhere\Kite\Lib\Jump\JumpStorage; +use InvalidArgumentException; use PhpPkg\EasyTpl\SimpleTemplate; use Toolkit\PFlag\FlagsParser; use Toolkit\Stdlib\Str; @@ -74,15 +74,20 @@ public function listCommand(FlagsParser $fs, Output $output): void $output->colored('Datafile: ' . $qj->getDatafile(), 'cyan'); $output->println(Str::repeat('=', 60)); - $key = $fs->getFirstArg(); - $data = $qj->getEngine()->toArray(true); + $opts = [ 'ucTitleWords' => false, ]; - if ($key && isset($data[$key])) { - $output->aList($data[$key], $key, $opts); + if ($key = $fs->getFirstArg()) { + $val = $qj->getEngine()->get($key); + if ($val === null) { + throw new InvalidArgumentException("invalid data key: $key"); + } + + $output->aList($val, $key, $opts); } else { + $data = $qj->getEngine()->toArray(true); $output->mList($data, $opts); } } @@ -210,6 +215,7 @@ public function getCommand(FlagsParser $fs, Output $output): void // vdump($input, $_SERVER['argv']); $name = $fs->getArg('name'); $dir = $qj->match($name); + // $qj->saveLastMatch($dir); Kite::logger()->info("jump get directory is: $dir, name: $name"); diff --git a/app/Lib/Jump/JumpStorage.php b/app/Lib/Jump/JumpStorage.php index 2e48f80..94f1dff 100644 --- a/app/Lib/Jump/JumpStorage.php +++ b/app/Lib/Jump/JumpStorage.php @@ -35,6 +35,8 @@ class JumpStorage implements JsonSerializable public const MATCH_BOTH = 3; /** + * The json data file + * * @var string */ private string $datafile; @@ -380,13 +382,28 @@ public function __toString(): string /** * @return string - * @throws \JsonException */ public function toString(): string { return Json::encode($this->toArray(), JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT); } + /** + * @param string $key + * + * @return string|array|null + */ + public function get(string $key): string|array|null + { + return match ($key) { + 'prev', 'prevPath' => $this->prevPath, + 'last', 'lastPath' => $this->lastPath, + 'name', 'named', 'namedPaths' => $this->namedPaths, + 'his', 'history', 'histories' => array_values($this->histories), + default => null, + }; + } + /** * @param bool $clearId * diff --git a/resource/mkdown-demo.md b/resource/mkdown-demo.md index 4b8b8bc..6e6ea1a 100644 --- a/resource/mkdown-demo.md +++ b/resource/mkdown-demo.md @@ -12,7 +12,7 @@ Render colored markdown contents on console terminal **composer** ```bash -composer require phpcom-lab/cli-markdown +composer require phppkg/cli-markdown ``` ## Usage diff --git a/resource/packages.md b/resource/packages.md index 9ecd35a..040df95 100644 --- a/resource/packages.md +++ b/resource/packages.md @@ -44,7 +44,7 @@ like Yaml, json but simple. **crontab** - `dragonmantank/cron-expression` https://github.com/dragonmantank/cron-expression -- `phpcom-lab/hucron` https://github.com/phpcom-lab/hucron +- `phppkg/hucron` https://github.com/phppkg/hucron **parser&lexer** diff --git a/resource/templates/completion/kite-alias.sh b/resource/templates/completion/kite-alias.sh new file mode 100644 index 0000000..8de393b --- /dev/null +++ b/resource/templates/completion/kite-alias.sh @@ -0,0 +1,12 @@ +# +## aliases for kite +# NOTICE: zsh plugin support add aliases +#alias kj="kite jump" +alias kg="kite git" +alias kgit="kite git" +alias kjson="kite json" +alias kplug="kite plugin" +alias kstr="kite string" +alias kgl="kite gitlab" +alias kgh="kite github" +alias cht="kite cheat" diff --git a/resource/templates/go-code-tpl/struct.tpl b/resource/templates/go-code-tpl/struct.tpl new file mode 100644 index 0000000..66058c2 --- /dev/null +++ b/resource/templates/go-code-tpl/struct.tpl @@ -0,0 +1,11 @@ + +// {{ $className }} struct +// +// Gen by: +// {{ $genMark | nl }} +type {{ $className }} struct { +{{ foreach ($fields as $field): }} + // {{= $field->name | camel:true }} {{= $field->comment | nl }} + {{= $field->name | camel:true }} {{= $field->getType($lang) }} `json:"{{= $field->name | snake }}"` +{{ endforeach }} +} \ No newline at end of file diff --git a/resource/templates/php-code-tpl/parts/class-comments.tpl b/resource/templates/php-code-tpl/parts/class-comments.tpl new file mode 100644 index 0000000..5ed71a4 --- /dev/null +++ b/resource/templates/php-code-tpl/parts/class-comments.tpl @@ -0,0 +1,4 @@ +/** + * @author {{= $user ?? 'inhere' | nl}} + * @date {{= date('Y-m-d H:i:s') | nl }} + */ \ No newline at end of file diff --git a/resource/templates/php-code-tpl/req-resp-dto.tpl b/resource/templates/php-code-tpl/req-resp-dto.tpl new file mode 100644 index 0000000..b41d4f8 --- /dev/null +++ b/resource/templates/php-code-tpl/req-resp-dto.tpl @@ -0,0 +1,17 @@ + +{{ include('parts/class-comments', [ + 'user' => $user, + 'date' => $date +]) }} +class {{ $className | nl }} +{ +{{ foreach ($fields as $field): }} + + /** + * {{= $field->comment | nl }} + * + * @param {{= $field->getType($lang) | nl }} + */ + public ${{= $field->name | camel }}; +{{ endforeach }} +} diff --git a/resource/templates/quick-jump/jump.zsh b/resource/templates/quick-jump/jump.zsh index 9352566..755b97c 100644 --- a/resource/templates/quick-jump/jump.zsh +++ b/resource/templates/quick-jump/jump.zsh @@ -4,19 +4,25 @@ # # set the bind func name is: j # eval "$(kite jump shell zsh --bind j)" # +# for DEBUG: +# set -x # start +# set +x # stop +# typeset -ft __jump_chpwd # start for given function +# typeset +ft __jump_chpwd # stop +# # The following lines are autogenerated: # change pwd hook __jump_chpwd() { - # x: is number - # cmd: the command name - # eg: "123 j" or "124 j /path/to/dir" - local lastCmd=$(history -1 | { + # eg: + # ': 1649259804:0;j /path/to' + # => x=':' cmd='1649259804:0;j' args='/path/to' + local midStr=$(tail -n 1 $HOME/.zsh_history | { read x cmd args echo "$cmd" }) -# kite util log "lastCmd $lastCmd $@" --type zsh-jump-chdir + local lastCmd=${midStr#*;} # Do not process other commands executed if [[ $lastCmd != "{{bindFunc}}" ]]; then return 0