<commit_before># Fin custom commands

It is possible to extend fin with custom commands per project or per host.

## Project-level custom commands

Create a file at this location `.docksal/commands/updb` with the following contents:

```bash
#!/bin/bash

## Runs drush updb
##
## Usage: fin updb [params to passthrough]

fin drush updb $1
```
Note the file name should match the command name with **no extension**.

Make the file executable

```bash
chmod +x .docksal/commands/updb
```

Now you can use it as if it was a regular fin command: `fin updb`.
Passing parameters also works: `fin updb -y`.
The command description will be visible in `fin help` and the full command help will be available via `fin help updb`.

Note: `drush updb` this is a Drupal-specific example.

## Available variables

These variables, provided by fin, are available for use inside you custom command scripts:

* `PROJECT_ROOT` - absolute path to the project folder.  
* `DOCROOT` - name of the docroot folder.
* `VIRTUAL_HOST` - the virtual host name for the project. For example, `projectname.docksal`.
* `DOCKER_RUNNING` - (string) "true" or "false".


Here is an example `init` command for a Drupal website using drush to automate the install:  

```bash
#!/usr/bin/env bash

# Start containers
fin up
# Install site
fin drush site-install -y --site-name="My Drupal site"
# Get login link
cd docroot 2>dev/null
fin drush uli
```

## Documenting custom command

Fin looks for lines starting with `##` for command documentation.

```bash
## Custom command description
## Usage: fin mycommand [--force]
## Parameters:
## --force Try really hard<commit_msg>Fixed typos<commit_after># Fin custom commands

It is possible to extend fin with custom commands per project or per host.

## Project-level custom commands

Create a file at this location `.docksal/commands/updb` with the following contents:

```bash
#!/bin/bash

## Runs drush updb
##
## Usage: fin updb [params to passthrough]

fin drush updb $1
```
Note: the file name should match the command name with **no extension**.

Make the file executable:

```bash
chmod +x .docksal/commands/updb
```

Now you can use it as if it was a regular fin command: `fin updb`.
Passing parameters also works: `fin updb -y`.
The command description will be visible in `fin help` and the full command help will be available via `fin help updb`.

Note: `drush updb` this is a Drupal-specific example.

## Available variables

These variables, provided by fin, are available for use inside you custom command scripts:

* `PROJECT_ROOT` - absolute path to the project folder
* `DOCROOT` - name of the docroot folder
* `VIRTUAL_HOST` - the virtual host name for the project (e.g., `projectname.docksal`)
* `DOCKER_RUNNING` - (string) "true" or "false"


Here is an example `init` command for a Drupal website using drush to automate the install:  

```bash
#!/usr/bin/env bash

# Start containers
fin up
# Install site
fin drush site-install -y --site-name="My Drupal site"
# Get login link
cd docroot 2>dev/null
fin drush uli
```

## Documenting custom command

Fin looks for lines starting with `##` for command documentation.

```bash
## Custom command description
## Usage: fin mycommand [--force]
## Parameters:
## --force Try really hard
{'fraction_non_alphanumeric': 0.09656652360515021, 'fraction_numerical': 0.001226241569589209, 'mean_word_length': 4.162974683544304, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1332047', 'n_tokens_mistral': 1001, 'n_tokens_neox': 966, 'n_words': 457}