aboutsummaryrefslogtreecommitdiff
path: root/.local/bin/plumber
diff options
context:
space:
mode:
Diffstat (limited to '.local/bin/plumber')
-rwxr-xr-x.local/bin/plumber97
1 files changed, 73 insertions, 24 deletions
diff --git a/.local/bin/plumber b/.local/bin/plumber
index e2c9911..88aa80c 100755
--- a/.local/bin/plumber
+++ b/.local/bin/plumber
@@ -2,7 +2,7 @@
defmodule Settings do
def terminal do
- "urxvt"
+ System.get_env("TERMINAL")
end
end
@@ -14,22 +14,30 @@ defmodule ArgParser do
options = [
camelize: "text->camelize",
+ case_lower: "case->lower",
+ case_title: "case->title",
+ case_titleize: "case->titleize",
+ case_upper: "case->upper",
date8601: "text->date8601",
dictionary: "word->dictionary",
- first_letter: "text->first-letter-words",
- kjv_lookup: "verse->kjv",
+ jumbleize: "text->jumbleize",
+ kjv: "verse->kjv",
+ letterize: "text->letterize",
lorem_paragraph: "lorem->paragraph",
lorem_title: "lorem->title",
- lower_case: "case->lower",
- single_line: "text->single-line",
+ reverse_letters: "reverse->letters",
+ reverse_words: "reverse->words",
+ singleline: "text->singleline",
slugize: "text->slugize",
- title_case: "case->title",
- title_case_strict: "case->title-strict"
+ urlize: "text->urlize",
]
cond do
- opts[:option] == options[:first_letter] ->
- TextPlumber.firstLetterOfWordsIn(opts[:text]) |> IO.binwrite()
+ opts[:option] == options[:letterize] ->
+ TextPlumber.firstLetterOfWordsIn(opts[:text]) |> IO.puts()
+
+ opts[:option] == options[:urlize] ->
+ URI.encode(opts[:text]) |> IO.puts()
opts[:option] == options[:slugize] ->
opts[:text]
@@ -40,7 +48,7 @@ defmodule ArgParser do
|> String.replace(~r/[[:space:]]+/, "-")
|> String.replace(~r/[[:punct:]]+/, "-")
|> String.trim("-")
- |> IO.binwrite()
+ |> IO.puts()
opts[:option] == options[:camelize] ->
opts[:text]
@@ -50,23 +58,44 @@ defmodule ArgParser do
|> Macro.camelize()
|> String.replace(~r/[[:space:]]+/, "")
|> String.replace(~r/[[:punct:]]+/, "")
- |> IO.binwrite()
+ |> IO.puts()
+
+ opts[:option] == options[:singleline] ->
+ TextPlumber.singleLineOf(opts[:text]) |> IO.puts()
+
+ opts[:option] == options[:jumbleize] ->
+ String.split(opts[:text] |> String.replace(~r/[[:punct:]]+/, ""))
+ |> Enum.map(&String.codepoints/1)
+ |> Enum.map(&TextPlumber.jumble/1)
+ |> Enum.map(&Enum.join/1)
+ |> Enum.join(" ")
+ |> IO.puts()
- opts[:option] == options[:single_line] ->
- TextPlumber.singleLineOf(opts[:text]) |> IO.binwrite()
+ opts[:option] == options[:reverse_words] ->
+ TextPlumber.reverse(opts[:text]) |> IO.puts()
+
+ opts[:option] == options[:reverse_letters] ->
+ String.split(opts[:text])
+ |> Enum.map(&String.codepoints/1)
+ |> Enum.map(&Enum.reverse/1)
+ |> Enum.join(" ")
+ |> IO.puts()
opts[:option] == options[:dictionary] ->
TextPlumber.dictionOfFirstWordIn(opts[:text])
- TextPlumber.firstWordOf(opts[:text]) |> IO.binwrite()
+ TextPlumber.firstWordOf(opts[:text]) |> IO.puts()
+
+ opts[:option] == options[:case_title] ->
+ opts[:text] |> to_string |> TextPlumber.titleCaseOf() |> IO.puts()
- opts[:option] == options[:title_case] ->
- opts[:text] |> to_string |> TextPlumber.titleCaseOf() |> IO.binwrite()
+ opts[:option] == options[:case_titleize] ->
+ String.downcase(opts[:text]) |> TextPlumber.titleCaseOf() |> IO.puts()
- opts[:option] == options[:title_case_strict] ->
- String.downcase(opts[:text]) |> TextPlumber.titleCaseOf() |> IO.binwrite()
+ opts[:option] == options[:case_lower] ->
+ String.downcase(opts[:text]) |> IO.puts()
- opts[:option] == options[:lower_case] ->
- String.downcase(opts[:text]) |> IO.binwrite()
+ opts[:option] == options[:case_upper] ->
+ String.upcase(opts[:text]) |> IO.puts()
opts[:option] == options[:lorem_title] ->
TextPlumber.loremTitle()
@@ -77,7 +106,7 @@ defmodule ArgParser do
opts[:option] == options[:date8601] ->
TextPlumber.date8601()
- opts[:option] == options[:kjv_lookup] ->
+ opts[:option] == options[:kjv] ->
System.cmd(Settings.terminal(), [
"-e",
"sh",
@@ -85,7 +114,7 @@ defmodule ArgParser do
"kjv #{TextPlumber.singleLineOf(opts[:text])}"
])
- TextPlumber.singleLineOf(opts[:text]) |> IO.binwrite()
+ TextPlumber.singleLineOf(opts[:text]) |> IO.puts()
true ->
Enum.each(options, fn {_, value} -> IO.puts(value) end)
@@ -95,8 +124,8 @@ end
defmodule TextPlumber do
def firstLetterOfWordsIn(text) do
- String.replace(text, ~r/(\w)\w*/, "\\1", global: true)
- |> String.replace(~r/\s\s+/, " ", global: true)
+ String.replace(text, ~r/(\w)\w*/u, "\\1", global: true)
+ |> String.replace(~r/\s\s+/u, " ", global: true)
end
def singleLineOf(text) do
@@ -108,6 +137,10 @@ defmodule TextPlumber do
String.split(text) |> List.first()
end
+ def reverse(text) do
+ String.split(text) |> Enum.reverse |> Enum.join(" ")
+ end
+
def titleCaseOf(text) do
text |> String.split() |> Enum.map(fn word -> :string.titlecase(word) end) |> Enum.join(" ")
end
@@ -141,6 +174,22 @@ defmodule TextPlumber do
])
end
+ def jumble(list) do
+ if length(list) == 1 do
+ list
+ else
+ head = Enum.take(list, 1)
+ tail = Enum.take(list, -1)
+ list = list |> Enum.drop(-1) |> Enum.drop(1)
+
+ if length(list) == 2 do
+ head ++ (list |> Enum.reverse()) ++ tail
+ else
+ head ++ (list |> Enum.shuffle()) ++ tail
+ end
+ end
+ end
+
def date8601() do
{string, _return} =
System.cmd("date", [