From 6050c129bc7a1d87de51dde1e3c44c4e5f01d159 Mon Sep 17 00:00:00 2001 From: tdro Date: Thu, 19 Nov 2020 22:28:03 -0500 Subject: .local/bin/plumber: Add crude text plumber --- .local/bin/plumber | 34 ++++++++++++++++++++++++++++++++++ .local/bin/plumber-dmenu | 11 +++++++++++ 2 files changed, 45 insertions(+) create mode 100755 .local/bin/plumber create mode 100755 .local/bin/plumber-dmenu (limited to '.local') diff --git a/.local/bin/plumber b/.local/bin/plumber new file mode 100755 index 0000000..0c575b9 --- /dev/null +++ b/.local/bin/plumber @@ -0,0 +1,34 @@ +#! /usr/bin/env elixir + +defmodule ArgParser do + def parse do + {opts, _} = + System.argv() + |> OptionParser.parse!(strict: [option: :string, text: :string]) + + cond do + opts[:option] == "First letter of each word in sentence" -> + TextPlumber.firstLetterOfWordsIn(opts[:text]) + + opts[:option] == "Single line of text" -> + TextPlumber.singleLineOf(opts[:text]) + + true -> + "No plumber specified #{opts[:option]}" |> IO.puts() + end + end +end + +defmodule TextPlumber do + def firstLetterOfWordsIn(text) do + String.replace(text, ~r/(\w)\w*/, "\\1", global: true) + |> String.replace(~r/\s\s+/, " ", global: true) + |> IO.puts() + end + + def singleLineOf(text) do + String.replace(text, "\n", "") |> IO.puts() + end +end + +ArgParser.parse() diff --git a/.local/bin/plumber-dmenu b/.local/bin/plumber-dmenu new file mode 100755 index 0000000..431bbb7 --- /dev/null +++ b/.local/bin/plumber-dmenu @@ -0,0 +1,11 @@ +#!/bin/sh -eu +options="First letter of each word in sentence +Single line of text +" +printf "%s" "$options" \ + | dmenu -i -b \ + | while read -r option + do + text=$(plumber --option "$option" --text "$(xsel -o)") + notify-send "$text" && printf "%s" "$text" | xsel -ib + done -- cgit v1.2.3