Friday, March 13, 2015

Geany custom command - Parenthesize selected text

Here is quick little bash script that accepts piped input from STDIN and parenthesizes it.

I use it for a Geany Custom Command, to set it up from the Geany IDE:
Choose: -> Edit -> Format -> Send Selection To -> Set Custom Commands -> Add

Then put the full path of this script for the Command and provide a Label: Parenthesize.

If it is the first command it will automatically have the keybinding of Control+1, so now
whenever you select any block of text you can simply hit Control+1 and the selected text will be automatically parenthesized for you.

#!/usr/bin/env bash 
declare INPUT_TXT=""
declare ADD_LF="\n" 
declare -i DONE=0

while read PIPED_INPUT || { DONE=1; ADD_LF=""; }; do 
 INPUT_TXT="${INPUT_TXT}${PIPED_INPUT}${ADD_LF}"
 ((${DONE})) && break; 
done

echo -en "(${INPUT_TXT})"

1 comment:

  1. Thank you! I am using geany for writing documents in latex. I found your script was easily adapted to, e.g., enclose the selected text in the latex section command:
    \section{Selected Text}
    Geany does this automatically for format commands but has no provision for sectioning.

    ReplyDelete