Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lashoun/slugify
ZSH plugin that converts filenames and directories to a web friendly format.
https://github.com/lashoun/slugify
Last synced: about 2 months ago
JSON representation
ZSH plugin that converts filenames and directories to a web friendly format.
- Host: GitHub
- URL: https://github.com/lashoun/slugify
- Owner: lashoun
- License: mit
- Fork: true (benlinton/slugify)
- Created: 2019-04-08T12:24:47.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2021-03-30T12:19:39.000Z (about 3 years ago)
- Last Synced: 2024-01-25T13:04:54.652Z (4 months ago)
- Language: Shell
- Homepage:
- Size: 43 KB
- Stars: 5
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Lists
- awesome-zsh-plugins - slugify - Converts filenames and directories to a web friendly format. (Plugins / ZSH on Windows)
- fucking-awesome-zsh-plugins - slugify - Converts filenames and directories to a web friendly format. (Plugins / ZSH on Windows)
- fucking-awesome-zsh-plugins - slugify - Converts filenames and directories to a web friendly format. (Plugins / ZSH on Windows)
- awesome-zsh-plugins - slugify - ZSH plugin that converts filenames and directories to a web friendly format. (Plugins / Zinit (née zplugin))
- awesome-zsh-plugins - slugify - Converts filenames and directories to a web friendly format. (Plugins / ZSH on Windows)
README
# Slugify
Slugify is a ZSH plugin that converts filenames and directories to a web friendly format. Converted from the bash command [slugify](https://github.com/benlinton/slugify).
## Installation
I recommend [zplug](https://github.com/zplug/zplug). Add the following line in your `.zshrc`.
```zsh
zplug "lashoun/slugify"
```## Usage Help
Simply enter the slugify command without any arguments or with the -h option to view the usage help.
```
$ slugify -h
usage: slugify [-abcdefhinptuv] source_file ...
-a: remove spaces immediately adjacent to dashes
-b: remove spaces immediately adjacent to dots
-c: consolidate consecutive spaces into single space
-d: replace spaces with dashes (instead of default underscores)
-e: do not replace special characters with regular characters
-f: treat existing non alpha-numeric characters (except dashes) as spaces
-h: help
-i: ignore case
-n: dry run
-p: treat existing non alpha-numeric characters as spaces
-t: treat existing dashes as spaces
-u: treat existing underscores as spaces (useful with -a, -c, or -d)
-v: verbose
```## Usage Examples
Note, most examples below are run in verbose mode (-v) to help illustrate the results.
Verbose mode is unnecessary in real world scenarios.
#### Provide escaped filenames:
$ slugify -v My\ \ file.txt
rename: My file.txt -> my__file.txt#### Alternatively provide unescaped filenames inside quotes:
$ slugify -v "My file.txt"
rename: My file.txt -> my__file.txt#### Globs (like * and ?) work as well:
$ slugify -v *.txt
rename: My file.txt -> my_file.txt
ignore: my_web_friendly_filename.txt#### Provide an unlimited number of arguments:
$ slugify -v "My first file.txt" "My second file.txt"
rename: My first file.txt -> my_first_file.txt
rename: My second file.txt -> my_second_file.txt#### Directories are also supported:
$ slugify -v "My Directory"
rename: My Directory -> my_directory#### Consolidate consecutive spaces into single spaces:
$ slugify -vc "My consolidated file.txt"
rename: My consolidated file.txt -> my_consolidated_file.txt#### Replace spaces with dashes:
$ slugify -vd "My dashed file.txt"
rename: My dashed file.txt -> my-dashed-file.txtThe -d option replaces each space with a dash.
$ slugify -vd "My dashed file.txt"
rename: My dashed file.txt -> my--dashed--file.txtCombine -d with -c (consolidate spaces) for a single dash between each word.
$ slugify -vdc "My dashed file.txt"
rename: My dashed file.txt -> my-dashed-file.txt#### Ignore case:
$ slugify -vi "UPPER CASE FILE.txt"
rename: UPPER CASE FILE.txt -> UPPER_CASE_FILE.txt#### Play it safe with a dry run:
Dry run mode does not alter the filesystem in any way.
$ slugify -n *
--- Begin dry run mode.
rename: My file.txt -> my_file.txt
ignore: web_friendly_filename.txt
--- End dry run mode.Dry run mode also allows you to test filenames that don't exist. Great for testing!
$ slugify -n "Ghost File.txt"
--- Begin dry run mode.
not found: Ghost File.txt
rename: Ghost File.txt -> ghost_file.txt
--- End dry run mode.Dry run mode automatically enables verbose mode so there is no need to include the -v option with -n.
#### Handle spaces adjacent to dashes:
In this example, without -a the dashes end up surrounded by underscores.
$ slugify -v "The Beatles - Yellow Submarine.mp3"
rename: The Beatles - Yellow Submarine.mp3 -> the_beatles_-_yellow_submarine.mp3But with -a the adjacent spaces are removed.
$ slugify -va "The Beatles - Yellow Submarine.mp3"
rename: The Beatles - Yellow Submarine.mp3 -> the_beatles-yellow_submarine.mp3The -a only removes spaces immediately adjacent to a dash, which may not be the desired effect (below three spaces on either side of the dash get converted into two underscores because of -a).
$ slugify -va "The Beatles - Yellow Submarine.mp3"
rename: The Beatles - Yellow Submarine.mp3 -> the_beatles__-__yellow_submarine.mp3But -c consolidates spaces into a single space and then -a will remove the left over adjacent single spaces.
$ slugify -vac "The Beatles - Yellow Submarine.mp3"
rename: The Beatles - Yellow Submarine.mp3 -> the_beatles-yellow_submarine.mp3#### Convert existing underscores into dashes
The -u treats underscores as spaces and -d converts spaces into dashes.
$ slugify -vud "Spaces Dashes-And_Underscores.txt"
rename: Spaces Dashes-And_Underscores.txt -> spaces-dashes-and-underscores.txt#### Convert existing dashes into underscores
$ slugify -vt "Spaces Dashes-And_Underscores.txt"
rename: Spaces Dashes-And_Underscores.txt -> spaces_dashes_and_underscores.txt