There's nothing builtin for that kind of functionality and is much easier 
said than done. I did write up an AppleScript that works decently well from 
my mild testing. There's a bit that could be cleaned up from it and likely 
simplified. If someone wants to improve upon go ahead.

Essentially, it tries determine any file path in front of the text cursor 
(e.g., ../images/tes), then splits it out into directory and partial file 
name. It also has to find out what directory the currently edited file 
exists. Parsing out all of this it builds a command in the form of,

ls -A1 <relative directory> | grep "partialFileName"

If one result comes back, it replaces the partial file name with it. If 
more than one is found it displays a message that more than one match was 
found. If a file path couldn't be found it doesn't do anything. This works 
for the current directory as well, whether you give ./ or just the start of 
the name.

Just copy and paste the script below into AppleScript Editor and save it 
the BBEdit's script folder. Then you can assign a keyboard shortcut to it 
if you want quick access. Again, the code it a little dirty and not well 
tested, but seems to work OK, just don't try and trick it.

------------------------------------
tell application "BBEdit"
    activate
    set lineNum to startLine of selection
    set aaa to (characterOffset of line (startLine of selection)) of front 
window
    set zzz to (characterOffset of selection)
    set cursorPos to zzz - aaa
    set linestr to characters 1 thru cursorPos of line lineNum of front 
window
    
    set theResult to find "([\\w\\.\\-\\/_]+)" options {search mode:grep, 
backwards:true} searching in linestr
    set startstr to ""
    if found of theResult then
        set startstr to found text of theResult
    end if
    
    set pre to ""
    set partial to startstr
    
    if startstr contains "/" then
        set delim to AppleScript's text item delimiters
        set AppleScript's text item delimiters to "/"
        set partial to last text item of startstr
        set idx to 1
        repeat (count text item of startstr) - 1 times
            if idx > 1 then set pre to pre & "/"
            set pre to pre & text item idx of startstr
            set idx to idx + 1
        end repeat
        set AppleScript's text item delimiters to delim
    end if
    -- no partial filename, give up
    if partial = "" then return
    
    -- find pwd of document
    set fp to (POSIX path of (file of front window as string))
    set fpchars to characters of fp
    set fprev to reverse of fpchars
    set fpdir to characters 1 thru ((length of fp) - (offset of "/" in 
(fprev as string))) of fp
    
    set cmd to "cd " & (quoted form of (fpdir as string)) & "; ls -A1 " & 
pre & " | grep \"" & partial & "\""
    --display dialog cmd
    set cmdR to ""
    try
        set cmdR to do shell script cmd
    on error theErr
        display dialog theErr
        return
    end try
    
    if cmdR contains return then
        -- More than one file/folder matches
        display dialog "Multiple matches"
        return
    end if
    
    set startPartial to cursorPos - (length of partial) + 1
    set characters startPartial thru cursorPos of line lineNum of front 
window to cmdR
    
end tell
------------------------------------

-Kendall

On Wednesday, September 26, 2012 10:26:35 AM UTC-4, Matt Karikomi wrote:
>
> hi all this is my first post in the group.  im just using bbedit for the 
> first time and love it.  i didnt get anything obvious in a search so here 
> goes.  id like to implement tab-completion for relative urls.  like if 
> there was an attribute "url(../images/a..)" and id like to just hit the tab 
> key to get  "url(../images/armored_flamingos.jpg)" 
>
> thanks in advance!
>

-- 
-- 
You received this message because you are subscribed to the 
"BBEdit Talk" discussion group on Google Groups.
To post to this group, send email to bbedit@googlegroups.com
To unsubscribe from this group, send email to
bbedit+unsubscr...@googlegroups.com
For more options, visit this group at
<http://groups.google.com/group/bbedit?hl=en>
If you have a feature request or would like to report a problem, 
please email "supp...@barebones.com" rather than posting to the group.
Follow @bbedit on Twitter: <http://www.twitter.com/bbedit>



Reply via email to