diff options
-rw-r--r-- | .config/xbindkeysrc | 4 | ||||
-rwxr-xr-x | .local/bin/plumber | 34 | ||||
-rwxr-xr-x | .local/bin/plumber-dmenu | 11 |
3 files changed, 49 insertions, 0 deletions
diff --git a/.config/xbindkeysrc b/.config/xbindkeysrc index 4aed743..14a014f 100644 --- a/.config/xbindkeysrc +++ b/.config/xbindkeysrc @@ -26,6 +26,10 @@ "$HOME/.local/bin/scripts/clipboard" Mod4 + z +# Text plumber +"$HOME/.local/bin/plumber-dmenu" + Mod4 + i + # File Search "$HOME/.local/bin/scripts/file-search" Mod4 + p 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 |