Created
October 20, 2010 00:51
-
-
Save scottmessinger/635552 to your computer and use it in GitHub Desktop.
Shows the filename in the finder window
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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