Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Special files fix #56

Merged
merged 4 commits into from Jun 17, 2017
Merged

Special files fix #56

merged 4 commits into from Jun 17, 2017

Conversation

glubsy
Copy link
Contributor

@glubsy glubsy commented Jun 13, 2017

Fixes reading size and mtime columns in directories holding special character or block files #50
Fixes misaligned permission column in case the extra "+" mask bit is set on a file.
Adds missing --potsf command line argument to README file

Example screenshot:
fixed columns in /dev/

Shorter arguments work just fine too (wasn't working before this patch):
ls++ --psf

Fix alignment with permission column in case of extra "+" bit
Fix README missing --potsf arguments
ls++ Outdated
$max = 0;
foreach my $line (split(/^/, $out)) {
($perm, $hlink, $user, $group, $size) = split(/\s+/, $line);
(undef, undef, undef, undef, $size) = split(/\s+/, $line);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These variables were never used, so I removed them.

ls++ Outdated
@@ -362,6 +383,9 @@ sub perm_size_file {

sub perm {
my ($perm) = @_;
if (substr($perm,-1,1) ne "+"){
$perm .= " "; # adding an extra space to align with occasional +
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't want to parse the whole permission column to determine if we needed the extra space. For performance reason, I just add a space by default before the column delimiter. It looks good and centered since there is a space at the beginning of the string anyway.

Copy link
Contributor

@anthraxx anthraxx Jun 13, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't take much performance, you don't need to parse the permissions just calculate the length of it without spaces and pad everything shorter then the longest one.
I think it would make sense to only show the space when there is need for it.

But maybe just personal feelings as you are totally right with the space at the beginning... no clue... works for me either way 😄

Copy link
Contributor Author

@glubsy glubsy Jun 14, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't very clear in my comment, but I meant going through each line of the GNU ls output like you did in the get_max_size_len subroutine, which means looping through each line twice just to get the max length. I thought it would be some extra steps for very little benefit since these "+" mask bits are rather uncommon. But I might just be overthinking this (happens often heh).
I'll work on it and add the space only when necessary.

Edit: I've added the extra space only when needed. Thanks. :)

. fg($c[3], fg('bold', $2))
);
}
elsif($size =~ m/^(\d+)/) {
$size = sprintf("%27s",
fg($c[7], sprintf("%4d", $1))
fg($c[7], sprintf("%*d", $stringlen, $1))
Copy link
Contributor Author

@glubsy glubsy Jun 13, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$stringlen is finally used for more than one single thing now. :)
It avoids hardcoding "size" column width and dynamically changes it depending on the maximum size of the "size" string.
So you can still have as little as 4 characters width in directories where files are not special files like shown in the above screenshot.

@@ -362,6 +387,10 @@ sub perm_size_file {

sub perm {
my ($perm) = @_;
if (length($perm) < $permlen){
# adding an extra space to align with occasional +
$perm .= " ";
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra padding when necessary:

When not needed:

@trapd00r
Copy link
Owner

Splendid work @glubsy! Merging right away. Thank you, have a cold one!

@trapd00r trapd00r merged commit 78766ed into trapd00r:master Jun 17, 2017
@glubsy
Copy link
Contributor Author

glubsy commented Jun 18, 2017

Thanks! Glad I could help a bit.

By the way, I forgot to increment the VERSION. You might want to do that to avoid breaking downstream. ;)

@anthraxx
Copy link
Contributor

anthraxx commented Jun 18, 2017 via email

@glubsy glubsy deleted the special_files_fix branch June 18, 2017 10:28
@trapd00r
Copy link
Owner

Both remarks fixed! Thanks guys.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants