https://github.com/jessarcher/zsh-artisan
Laravel artisan plugin for zsh to help you to run artisan from anywhere in the project tree, with auto-completion, and it can automatically open files created by artisan!
https://github.com/jessarcher/zsh-artisan
Last synced: 8 months ago
JSON representation
Laravel artisan plugin for zsh to help you to run artisan from anywhere in the project tree, with auto-completion, and it can automatically open files created by artisan!
- Host: GitHub
- URL: https://github.com/jessarcher/zsh-artisan
- Owner: jessarcher
- License: mit
- Created: 2018-10-26T05:31:28.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2024-07-22T10:00:22.000Z (over 1 year ago)
- Last Synced: 2024-10-14T20:31:45.363Z (about 1 year ago)
- Language: Shell
- Homepage:
- Size: 57.6 KB
- Stars: 618
- Watchers: 9
- Forks: 39
- Open Issues: 14
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-zsh-plugins - artisan - Laravel `artisan` plugin for ZSH to help you to run `artisan` from anywhere in the project tree, with tab completion! (Plugins / ZSH on Windows)
- fucking-awesome-zsh-plugins - artisan - Laravel `artisan` plugin for ZSH to help you to run `artisan` from anywhere in the project tree, with tab completion! (Plugins / ZSH on Windows)
- awesome-zsh-plugins - artisan - Laravel `artisan` plugin for ZSH to help you to run `artisan` from anywhere in the project tree, with tab completion! (Plugins / Zinit (née zplugin))
README
This plugin adds an `artisan` shell command with the following features:
* It will find and execute `artisan` from anywhere within the project file tree
(and you don't need to prefix it with `php` or `./`)
* It provides auto-completion for `artisan` commands (that also work anywhere
within the project).
* You can specify an editor to automatically open new files created by `artisan
make:*` commands
* It automatically runs artisan commands using `sail` when appropriate.
* It will run commands using `docker compose` (or `docker-compose`) if a known container name is found.
## Requirements
* [Zsh](https://www.zsh.org/)
* A Zsh package manager (e.g. [oh-my-zsh](https://github.com/robbyrussell/oh-my-zsh), [Antigen](https://github.com/zsh-users/antigen), or [zplug](https://github.com/zplug/zplug))
* A [Laravel](https://laravel.com/) project
## Installation
### [Antigen](https://github.com/zsh-users/antigen)
Add the following bundle to your `.zshrc`:
```zsh
antigen bundle jessarcher/zsh-artisan
```
### [Fig](https://fig.io)
Fig adds apps, shortcuts, and autocomplete to your existing terminal.
Install `artisan` in just one click.
### Oh-my-zsh
First download the plugin to your oh-my-zsh custom plugin location:
```zsh
git clone https://github.com/jessarcher/zsh-artisan.git ~/.oh-my-zsh/custom/plugins/artisan
```
> Note that the repository name is prefixed with `zsh-`, however the plugin
> directory name should just be "artisan".
Then enable the plugin in your `.zshrc` file. For example:
```zsh
plugins=(
artisan
composer
git
)
```
### [zplug](https://github.com/zplug/zplug)
Add the following to your `.zshrc`:
```zsh
zplug "jessarcher/zsh-artisan"
```
## Configuration
If you wish to automatically open new files created by `artisan make:*` commands
then you will need to configure the `ARTISAN_OPEN_ON_MAKE_EDITOR` environment
variable. The best place for this is probably your `.zshrc` file. For example:
```zsh
ARTISAN_OPEN_ON_MAKE_EDITOR=vim
#ARTISAN_OPEN_ON_MAKE_EDITOR=subl # Sublime Text
#ARTISAN_OPEN_ON_MAKE_EDITOR=pstorm # PHPStorm
#ARTISAN_OPEN_ON_MAKE_EDITOR=atom # Atom (May require shell commands to be enabled)
#ARTISAN_OPEN_ON_MAKE_EDITOR=code # VSCode (May require shell commands to be enabled)
```
> The author uses [mhinz/neovim-remote](https://github.com/mhinz/neovim-remote),
combined with a wrapper script, to automatically open files in an existing neovim
session within the same tmux session, and automatically switch to the correct
tmux window (tab).
Note that you will need to re-source your `.zshrc` or restart `zsh` to pick up
the changes.
## Usage
Simply use the command `artisan` from anywhere within the directory structure of
a Laravel project and it will search up the tree for the `artisan` command and
execute it. E.g:
```zshrc
$ pwd
~/MyProject/tests/Feature
$ artisan make:model MyAwesomeModel
Model created successfully.
```
Tab-completion will work anywhere that `artisan` can be found, and the available
commands are retrieved on-demand. This means that you will see any Artisan
commands that are available to you, including any custom commands that have
been defined.
If you configured the `ARTISAN_OPEN_ON_MAKE_EDITOR` environment variable, any
files created by `artisan make:*` commands should automatically be opened,
including when multiple files are created (E.g. by `artisan make:model -m -c -r`)
The plugin does not create any aliases for you, but the author would like to
offer some suggestions:
```zsh
alias a="artisan"
alias tinker="artisan tinker"
alias serve="artisan serve"
```
Many more can be found at https://laravel-news.com/bash-aliases
## Homestead Setup
The Zsh Artisan plugin can be installed automatically with any new or provisioned Laravel Homestead instance.
In the root of your Homestead project, add the following to your `after.sh` file.
```bash
ARTISAN=/home/vagrant/.oh-my-zsh/custom/plugins/artisan
if [ -d "$ARTISAN" ]; then
echo "$ARTISAN exist"
else
git clone https://github.com/jessarcher/zsh-artisan.git $ARTISAN
sed -i 's/plugins=(git)/plugins=(git composer artisan)/g' /home/vagrant/.zshrc
source /home/vagrant/.zshrc
fi
```
*Note:* If you are re-provisioning your Homestead box, and already have other Zsh plugins defined in your Zsh config files, you wil need to adjust the `sed` command to includes those in the list.
## License
This project is open-sourced software licensed under the MIT License - see the
[LICENSE](LICENSE) file for details
## Acknowledgements
* [antonioribeiro/artisan-anywhere](https://github.com/antonioribeiro/artisan-anywhere)
for some of the initial artisan location logic
* The `laravel5` plugin that comes with oh-my-zsh for the initial completion
logic
* [ahuggins/open-on-make](https://github.com/ahuggins/open-on-make) for the
"open on make" functionality idea. Unfortunately, adding a dev dependency like
this isn't an option on some of the projects I work on.