Skip to content

Instantly share code, notes, and snippets.

@lyrixx
Last active April 11, 2024 21:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lyrixx/5107964fb9b231d69c548e0f128fe8ea to your computer and use it in GitHub Desktop.
Save lyrixx/5107964fb9b231d69c548e0f128fe8ea to your computer and use it in GitHub Desktop.
slugger CLI

Slugger

This "project" is a simple CLI slugger

image

#!/usr/bin/env php
<?php
// # Installation instruction
// # Clone the symfony/string repository
// $ git clone git@github.com:symfony/string $HOME/dev/github.com/symfony/string
// $ cd $HOME/dev/github.com/symfony/string
// # Install the dependencies
// $ composer up
// # Then create a file slug.php with the content of this file.
// # Make it executable
// $ chmod +x slug.php
// # Create a symlink in your $PATH with
// $ ln -s $HOME/dev/github.com/symfony/string/slug.php $HOME/.local/bin/slug
// # Usage
// $ echo "Hello my little 🐰" | slug
// hello-my-little-rabbit
// $ echo "Bonjour mon petit 🐰" | LOCALE=fr slug
// bonjour-mon-petit-lapin
require "{$_SERVER['HOME']}/dev/github.com/symfony/string/vendor/autoload.php";
use Symfony\Component\String\Slugger\AsciiSlugger;
echo (new AsciiSlugger($_SERVER['LOCALE'] ?? 'en'))
->withEmoji($_SERVER['LOCALE'] ?? 'text')
->slug(stream_get_contents(STDIN))
;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment