Merge 0805de548f into e38696a0ac
commit
105b6f2715
|
|
@ -134,6 +134,7 @@ plugins/available/rbenv.plugin.bash
|
||||||
plugins/available/ruby.plugin.bash
|
plugins/available/ruby.plugin.bash
|
||||||
plugins/available/textmate.plugin.bash
|
plugins/available/textmate.plugin.bash
|
||||||
plugins/available/todo.plugin.bash
|
plugins/available/todo.plugin.bash
|
||||||
|
plugins/available/url.plugin.bash
|
||||||
plugins/available/xterm.plugin.bash
|
plugins/available/xterm.plugin.bash
|
||||||
plugins/available/zoxide.plugin.bash
|
plugins/available/zoxide.plugin.bash
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,45 @@
|
||||||
|
# shellcheck shell=bash
|
||||||
|
cite about-plugin
|
||||||
|
about-plugin 'Basic url handling and manipulation functions'
|
||||||
|
|
||||||
|
function slugify() {
|
||||||
|
about 'takes the text and transform to slug url, also supports formats like (html,link,rst,md)'
|
||||||
|
group 'url'
|
||||||
|
param "1: Text to transform (optional)"
|
||||||
|
param "2: Output format (html,rst,link,md). Omit or pass any text to return only output"
|
||||||
|
|
||||||
|
local TXT=$1
|
||||||
|
local OUTPUT=$2
|
||||||
|
local SLUG
|
||||||
|
|
||||||
|
if [[ -z $TXT ]]; then
|
||||||
|
read -rp "Enter the valid string: " TXT
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Pass 1 - Clean the url
|
||||||
|
# Credits: https://stackoverflow.com/a/20007549/10362396
|
||||||
|
SLUG=$(echo -n "$TXT" | tr -cd ' [:alnum:]._-' | tr -s ' ')
|
||||||
|
|
||||||
|
# Pass 2 - Transformation
|
||||||
|
SLUG=$(echo -n "$SLUG" | tr '[:upper:]' '[:lower:]' | tr ' ' '-')
|
||||||
|
|
||||||
|
case "$OUTPUT" in
|
||||||
|
html | htm)
|
||||||
|
echo "<a href=\"#$SLUG\">$TXT</a>"
|
||||||
|
;;
|
||||||
|
href | link)
|
||||||
|
echo "#$SLUG"
|
||||||
|
;;
|
||||||
|
md)
|
||||||
|
echo "[$TXT](#$SLUG)"
|
||||||
|
;;
|
||||||
|
rst)
|
||||||
|
echo "\`$TXT <#$SLUG>\`_"
|
||||||
|
;;
|
||||||
|
|
||||||
|
*)
|
||||||
|
echo "$SLUG"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue