E Text Editor | The Power of Textmate on Windows

 
Author Message

Index  >  TextMate Bundles  ~  edit included file

nigauw
Posted: Mon Aug 13, 2007 4:31 pm Reply with quote
Registered User Joined: 09 Aug 2007 Posts: 28 Location: Brussels - Belgium
It would be extremely useful to be able to edit an included resources with a right-click option (or a keyboard shortcut).

You would click anywhere in a bit of code like this:
<script src="../../extras/panes.js" type="text/javascript"></script>,
or like this:
<link rel="stylesheet" href="../../extras/mycss.css" type="text/css" media="screen" />
or even like this:
<cfinclude template="../include_top.cfm">
and directly open the included file, based on the relative path.

This feature is active in DWV (under Ctrl-D) and it's a great way to save time.
Do you know if there's already a bundle command that does that already? Or can you think of a way to implement it?
View user's profile Send private message Visit poster's website
nigauw
Posted: Sun Sep 09, 2007 3:24 pm Reply with quote
Registered User Joined: 09 Aug 2007 Posts: 28 Location: Brussels - Belgium
Thanks to the precious bash swordsmanship of sensei TanguyR, I now have almost exactly what was described in my August post.

Code:

#strip trailing filename from TM_FILEPATH
MY_TM_FILEPATH=$(echo $TM_FILEPATH | sed -e 's/\/[^\/]*$/\//g')
 
#and now put it all together
ABSPATH=${MY_TM_FILEPATH}${TM_SELECTED_TEXT}
ABSPATH_BACKSLASH=$(echo $ABSPATH | sed -e 's/\//\\/g')
ABSPATH_CDRIVE=$(echo $ABSPATH_BACKSLASH | sed -e 's/^\\cygdrive\\\([a-z|A-Z]\)\\/\1:\\/g')

e $ABSPATH_CDRIVE


You will need to have e added to your windows system_path for the last line to work.

The Command uses the selected text (the path to the file you want to open), but it shouldn't be too hard to look at the active line and carret position, and find the closest thing that looks like a file path... to be continued.
View user's profile Send private message Visit poster's website
nigauw
Posted: Mon Sep 10, 2007 9:32 am Reply with quote
Registered User Joined: 09 Aug 2007 Posts: 28 Location: Brussels - Belgium
Double quotes are needed on the last line on some systems, so here's the command script:
Code:

#strip trailing filename from TM_FILEPATH
MY_TM_FILEPATH=$(echo $TM_FILEPATH | sed -e 's/\/[^\/]*$/\//g')
 
#and now put it all together
ABSPATH=${MY_TM_FILEPATH}${TM_SELECTED_TEXT}
ABSPATH_BACKSLASH=$(echo $ABSPATH | sed -e 's/\//\\/g')
ABSPATH_CDRIVE=$(echo $ABSPATH_BACKSLASH | sed -e 's/^\\cygdrive\\\([a-z|A-Z]\)\\/\1:\\/g')

e "$ABSPATH_CDRIVE"
View user's profile Send private message Visit poster's website
tanguyr
Posted: Tue Sep 25, 2007 1:14 pm Reply with quote
Registered User Joined: 21 Sep 2007 Posts: 1
here's the new version, you can just place the cursor anywhere in the path instead of having to select the whole path

Code:

#split the current line in two: before and after cursor
LN_BEFORE=${TM_CURRENT_LINE:0:$TM_LINE_INDEX}
LN_AFTER=${TM_CURRENT_LINE:$TM_LINE_INDEX}

#the part of the line before from the last double quotes
#to the end plus the part of the line after from the start
#up to the first double quotes = the target href
TARGETREF=${LN_BEFORE##*\"}${LN_AFTER%%\"*}

#for every "../" at the start of the target href, go "up"
#one story in TM_DIRECTORY (i.e. remove rightmost dir)
while [[ "$TARGETREF" =~ "^\.\./.*$" ]]
do
 TM_DIRECTORY=${TM_DIRECTORY%/*}
 TARGETREF=${TARGETREF#../}
done

#the absolute path to the target file, in cygwin notation
ABSPATH=${TM_DIRECTORY}/${TARGETREF}

#test if the file exists
if [[ ! -f "$ABSPATH" ]]; then
 echo file $ABSPATH does not exist >&2
 exit 1
fi

#change cygwin style path to windows style path,
#and call e to open file
if [[ "$ABSPATH" =~ /cygdrive/([a-z|A-Z])/(.*)$ ]]; then
  WINPATH=${BASH_REMATCH[1]}":\\"${BASH_REMATCH[2]//\//\\}
  e "$WINPATH"
else
  echo $ABSPATH is not a cygwin path? >&2
  exit 1
fi

edited: added script comments
View user's profile Send private message

Display posts from previous:  

All times are GMT
Page 1 of 1
Post new topic

Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum