Skip to content

Instantly share code, notes, and snippets.

@scottmessinger
Created October 20, 2010 00:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scottmessinger/635552 to your computer and use it in GitHub Desktop.
Save scottmessinger/635552 to your computer and use it in GitHub Desktop.
Shows the filename in the finder window
def match_text_for_idx idx
match = truncated_match @matches[idx]
if idx == @selection
prefix = @@selection_marker
suffix = padding_for_selected_match match
else
prefix = @@unselected_marker
suffix = ''
end
prefix + file_name(match) + match + suffix
end
def file_name(match)
file = match.split('/').last
if file.length >= 50
shorten_file_name(file)
else
spaces = 50 - file.length
file = file + " " * (spaces)
end
end
def shorten_file_name match
len = match.length
max_width = 50
return match if len <= max_width
left = (max_width / 2) - 1
right = (max_width / 2) - 2 + (max_width % 2)
match[0, left] + '...' + match[-right, right]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment