From 3fae4c9b1631fed9ce8ac8c73c78d47477dfc6ed Mon Sep 17 00:00:00 2001 From: tdro Date: Tue, 6 Jun 2023 21:02:51 -0400 Subject: .local/bin/plumber: Add reverse Handle 2 item list in jumble Let vim know how to auto format --- .local/bin/plumber | 36 +++++++++++++++++++++++++++--------- .local/bin/plumber-dmenu | 2 ++ .vim/vimrc | 1 + 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/.local/bin/plumber b/.local/bin/plumber index 0bc53b3..e2c186d 100755 --- a/.local/bin/plumber +++ b/.local/bin/plumber @@ -25,6 +25,8 @@ defmodule ArgParser do letterize: "text->letterize", lorem_paragraph: "lorem->paragraph", lorem_title: "lorem->title", + reverse_letters: "reverse->letters", + reverse_words: "reverse->words", singleline: "text->singleline", slugize: "text->slugize", ] @@ -58,13 +60,23 @@ defmodule ArgParser do TextPlumber.singleLineOf(opts[:text]) |> IO.binwrite() opts[:option] == options[:jumbleize] -> - String.split(opts[:text]) + 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.binwrite() + opts[:option] == options[:reverse_words] -> + TextPlumber.reverse(opts[:text]) |> IO.binwrite() + + opts[:option] == options[:reverse_letters] -> + String.split(opts[:text]) + |> Enum.map(&String.codepoints/1) + |> Enum.map(&Enum.reverse/1) + |> Enum.join(" ") + |> IO.binwrite() + opts[:option] == options[:dictionary] -> TextPlumber.dictionOfFirstWordIn(opts[:text]) TextPlumber.firstWordOf(opts[:text]) |> IO.binwrite() @@ -121,6 +133,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 @@ -156,15 +172,17 @@ defmodule TextPlumber do def jumble(list) do if length(list) == 1 do - list + list else - head = Enum.take(list, 1) - tail = Enum.take(list, -1) - head ++ (list - |> Enum.drop(-1) - |> Enum.drop(1) - |> Enum.shuffle) - ++ tail + 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 diff --git a/.local/bin/plumber-dmenu b/.local/bin/plumber-dmenu index fba449d..bb50a03 100755 --- a/.local/bin/plumber-dmenu +++ b/.local/bin/plumber-dmenu @@ -6,6 +6,8 @@ case->titleize case->upper lorem->paragraph lorem->title +reverse->letters +reverse->words text->camelize text->date8601 text->jumbleize diff --git a/.vim/vimrc b/.vim/vimrc index db24101..ee1f868 100644 --- a/.vim/vimrc +++ b/.vim/vimrc @@ -349,6 +349,7 @@ augroup AutoCommands autocmd FileType sh set formatprg=shfmt\ - autocmd FileType typescriptreact set formatprg=deno\ fmt\ - autocmd FileType typescript set formatprg=deno\ fmt\ - + autocmd FileType elixir set formatprg=mix\ format\ - autocmd FileType python set formatprg=black\ --quiet\ - autocmd FileType scheme set formatprg=emacs-batch-indent\ scheme autocmd FileType css set formatprg=prettier\ --parser\ css\ --stdin-filepath\ % -- cgit v1.2.3