0

How can I make a shell script that will know where the caret is and grab selected text, so I can wrap the text in something? For example, this is a script from a Textmate bundle:

<${1:p}>$TM_SELECTED_TEXT</${1/\s.*//}>

It grabs the text and wraps it in open/close HTML tags. And it is variable so the second tag is mirrored as you type the first. I want to make a script like this but outside of Textmate so I can use it in TextEXpander.
Does this make sense ? :)

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
thatryan
  • 1,551
  • 6
  • 21
  • 39
  • I think you need to clarify what you want - I don't understand, and from the lack of response, neither does anyone else. Is the TM_SELECTED_TEXT an environment variable? Where does the ${1:p} (which I interpret to mean 'argument 1 if given, but 'p' for paragraph if not given') come from. And what does the '${1/\s.*//}' sequence mean? It might be something odd like 'take argument 1 and trim a sequence of zero or more spaces from it', but then why not in the opening tag too? – Jonathan Leffler Nov 04 '09 at 18:50
  • Ah ok, I am sorry about that. How it works is, that snippet takes the selected text, and surrounds it with open/close HTML tag

    The 'p' is highlighted and can be overtyped upon insertion, and the end 'p' tag is mirrored. So, If I highlight THIS and activate, I end up with

    THIS

    and can overtype the firts 'p' to get
    THIS
    or something. That is the ${1:p} it says to highlight the p first, and mirror it to the last one. Make sense? And I think that the variables are environment, I don't know.
    – thatryan Nov 04 '09 at 18:58

1 Answers1

1

$TM_SELECTED_TEXT is not an environment variable provided to scripts running outside of TextMate -- it is a variable that is set by TextMate and provided to scripts that are run as part of its snippet system. It is not even provided to the Shell bundles "Run Script" command.

What you want to do may be doable through other shell facilities (e.g., sed) so the functionality can be replicated by a shell script -- it depends on your usage scenario.

mipadi
  • 398,885
  • 90
  • 523
  • 479