dotfiles

Dash Eclipse's dotfiles
git clone git://ezup.dev/dotfiles.git
Log | Files | Refs | README | LICENSE

commit ecfd0bfa2841d3ddf726418b6dd510e755d59442
parent 8daf8f5fbb9b2429f40330686e2c402598a9dc34
Author: Dash Eclipse <dashezup@disroot.org>
Date:   Mon, 21 Mar 2022 16:08:55 +0000

feat: add slugify()

Diffstat:
M.zshrc.local | 14++++++++++++++
1 file changed, 14 insertions(+), 0 deletions(-)

diff --git a/.zshrc.local b/.zshrc.local @@ -227,3 +227,17 @@ day_of_week() { calculator() { while true; do bc <<<"scale=3; $(read -e)"; done } gtree() { git ls-files $1 | tree --fromfile } + +slugify() { + # https://github.com/Mayeu/slugify/blob/master/slugify#L24 + if [ "$1" = "-h" ]; then + echo "Usage: $0 [-i]" + elif test -t 0; then + read -e | $0 $@ + else + sed -e 's/[^[:alnum:]]/-/g' \ + | tr -s '-' \ + | sed -e 's/-$//' \ + | ([ "$1" = "-i" ] && tr A-Z a-z || cat) + fi +}