From 40d45e295c5b7a9ab3d72ccf905fb883b71adc59 Mon Sep 17 00:00:00 2001 From: tdro Date: Tue, 6 Jun 2023 18:20:46 -0400 Subject: .local/bin/plumber: Update --- .local/bin/plumber | 53 ++++++++++++++++++++++++++++++++++++------------ .local/bin/plumber-dmenu | 20 ++++++++++-------- 2 files changed, 52 insertions(+), 21 deletions(-) diff --git a/.local/bin/plumber b/.local/bin/plumber index e2c9911..0bc53b3 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,21 +14,23 @@ 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", + singleline: "text->singleline", slugize: "text->slugize", - title_case: "case->title", - title_case_strict: "case->title-strict" ] cond do - opts[:option] == options[:first_letter] -> + opts[:option] == options[:letterize] -> TextPlumber.firstLetterOfWordsIn(opts[:text]) |> IO.binwrite() opts[:option] == options[:slugize] -> @@ -52,22 +54,33 @@ defmodule ArgParser do |> String.replace(~r/[[:punct:]]+/, "") |> IO.binwrite() - opts[:option] == options[:single_line] -> + opts[:option] == options[:singleline] -> TextPlumber.singleLineOf(opts[:text]) |> IO.binwrite() + opts[:option] == options[:jumbleize] -> + String.split(opts[:text]) + |> Enum.map(&String.codepoints/1) + |> Enum.map(&TextPlumber.jumble/1) + |> Enum.map(&Enum.join/1) + |> Enum.join(" ") + |> IO.binwrite() + opts[:option] == options[:dictionary] -> TextPlumber.dictionOfFirstWordIn(opts[:text]) TextPlumber.firstWordOf(opts[:text]) |> IO.binwrite() - opts[:option] == options[:title_case] -> + opts[:option] == options[:case_title] -> opts[:text] |> to_string |> TextPlumber.titleCaseOf() |> IO.binwrite() - opts[:option] == options[:title_case_strict] -> + opts[:option] == options[:case_titleize] -> String.downcase(opts[:text]) |> TextPlumber.titleCaseOf() |> IO.binwrite() - opts[:option] == options[:lower_case] -> + opts[:option] == options[:case_lower] -> String.downcase(opts[:text]) |> IO.binwrite() + opts[:option] == options[:case_upper] -> + String.upcase(opts[:text]) |> IO.binwrite() + opts[:option] == options[:lorem_title] -> TextPlumber.loremTitle() @@ -77,7 +90,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", @@ -141,6 +154,20 @@ 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) + head ++ (list + |> Enum.drop(-1) + |> Enum.drop(1) + |> Enum.shuffle) + ++ tail + end + end + def date8601() do {string, _return} = System.cmd("date", [ diff --git a/.local/bin/plumber-dmenu b/.local/bin/plumber-dmenu index 262d099..1ebbbca 100755 --- a/.local/bin/plumber-dmenu +++ b/.local/bin/plumber-dmenu @@ -1,16 +1,20 @@ #!/bin/sh -eu options="\ -text->camelize -text->date8601 -word->dictionary -text->first-letter-words -verse->kjv +case->lower +case->title +case->titleize +case->upper lorem->paragraph lorem->title -case->lower -text->single-line +text->camelize +text->date8601 +text->jumbleize +text->letterize +text->singleline text->slugize -case->title +verse->kjv + +word->dictionary " printf "%s" "$options" \ | dmenu -i -b -p ⠀:::⠀plumber⠀::: \ -- cgit v1.2.3