Commit graph

211 commits

Author SHA1 Message Date
Claudio Bley
17b2142c48 Use File.extname to determine file extension
Fixes #441.
2021-01-29 10:21:24 +01:00
Claudio Bley
0048e3883a Group and process arguments in groups of files and directories
Fixes #233
2021-01-15 11:03:21 +01:00
Claudio Bley
4612549bc2 Fix misalignment of git status indicators
The misalignment is caused when a `!` is part of the status
which is later replaced with a space.
2021-01-15 11:03:21 +01:00
Claudio Bley
2eeb30fc44 Refactor git_subdir_status
Instead of simply returning the opened pipe, consume the output
and yield the `mode, file` tuple to the given block.
2021-01-15 11:03:21 +01:00
Claudio Bley
373fb67003 Fix error when git is not installed 2021-01-15 11:03:21 +01:00
Claudio Bley
93b08f9403 Prefer require_relative for internal dependencies 2021-01-15 11:03:21 +01:00
Claudio Bley
0ad630da4c Properly encode hyperlinks with special characters
This also works on Windows now, since absolute paths include a colon after the
drive letter, the `file:` URI needs to start with a triple slash.
2021-01-15 11:03:21 +01:00
Claudio Bley
76f148cc55 Only show a single report at the end
Showing a report for every argument given on the command line
is not suitable when using wildcards and did not work with `--tree`.

Also, it was only designed to work with directories given as
arguments.
2020-12-23 22:32:36 +01:00
Claudio Bley
ca9e1cd5d9 Refactor file_color method 2020-12-22 14:02:46 +01:00
Claudio Bley
d0df25d35d Re-use CoreLS::Core instance
Only initialize colors and flags once.
2020-12-22 14:01:55 +01:00
Claudio Bley
77b5135d97 Remove unused return value 2020-12-11 08:51:03 +01:00
Claudio Bley
41d9f5a757 Extract screen_width into the module 2020-12-11 08:51:03 +01:00
Claudio Bley
019158c63c Prepare release 1.4.3 2020-12-07 23:22:34 +01:00
Claudio Bley
64a42c105d
Merge pull request #417 from t-mangoe/add-option-o-g
add -o and -g options.
2020-12-07 22:54:17 +01:00
t-mangoe
0d0a1d96ca add -G option 2020-12-05 09:14:12 +09:00
Claudio Bley
1795844679 Fix rubocop offense about redundant argument for String#split
```
lib/colorls/core.rb:213:14: C: Style/RedundantArgument: Argument ' ' is
redundant because it is implied by default.
      size = Filesize.from("#{filesize} B").pretty.split(' ')
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
```
2020-11-26 09:07:58 +01:00
Claudio Bley
67ee23069c Take display width of characters into account
Some Unicode characters, e.g. chinese, consume more space when displayed on a terminal
than a single roman character. To avoid alignment issues, try to determine the width
using the unicode-display_width gem.
2020-11-22 21:29:51 +01:00
t-mangoe
39be15c6aa add -o and -g options. 2020-11-21 10:17:32 +09:00
Claudio Bley
6c697cdb9e Remove symbolize_keys monkey method on Hash
Usage in a single place does not really warrant a monkey patch and it
can be replaced with `transform_keys!` easily.
2020-11-02 08:45:07 +01:00
Claudio Bley
a59258b749 Clean up monkey patches
* delete `#remove` method
* remove `#delete_prefix` spec, it was only used for Ruby < 2.5 (see 86cfa2f5cf)
* add specifications for `#colorize` and `#uniq`
2020-11-02 08:45:07 +01:00
dependabot-preview[bot]
dc12307f19
Merge pull request #407 from athityakumar/dependabot/bundler/rubocop-tw-1.1.0 2020-10-31 21:29:31 +00:00
Claudio Bley
12e3b67d56 Fix Lint/EmptyBlock offense 2020-10-31 22:19:37 +01:00
Claudio Bley
8035deaab0 Ensure to use file_encoding for arguments
Fixes #377
2020-10-31 21:54:45 +01:00
t-mangoe
9992218ea4 make executables bold 2020-10-17 15:15:39 +09:00
Claudio Bley
d4110e4ac7 Officially support Windows
On Windows, MRI Ruby uses the `FindFirstFileW` et. al. kind of functions with
wide character paths and constantly converts from multi-byte to wide character
encoding back and forth when calling any methods on `File` or `Dir`.

This means that when using `Encoding::ASCII_8BIT` for reading directory entries,
that this does not round trip properly, if a file name contains unicode
characters. That is because Ruby assumes the path string is encoded in Windows
Codepage 1252[1].

* skip symlink test if files were checked out from git as textual symlinks on
  Windows
* use UTF-8 encoding on Windows, since this properly round-trips between
  multi-byte and wide character encoding
* travis: windows job no longer is allowed to fail

[1]: 946cd6c534/win32/file.c (L131-L134)
2020-10-09 18:26:50 +02:00
t-mangoe
64b1891c2c Set exit status code when specified path doesn't exist
Similar to GNU ls, status code `2` is reported if an argument given on the
command line does not exist.

Close #397
2020-10-07 09:58:01 +02:00
Claudio Bley
52b8c3489d Fix unrecognized files count and colorization
A *file* is assigned a generic icon / glyph in `files.yaml`, so looking up
`:file` in the corresponding hash always succeeds, but `:file` is also used as
the fallback key if a file's extension is not recognized.

First determining the color and group of a given file before falling back to
the `:file` key fixes this issue.
2020-09-07 20:38:42 +02:00
Claudio Bley
8379ba64db Fix newly reported offenses
* Style/MultilineWhenThen: Do not use then for multiline when statement
* Style/StringConcatenation: Prefer string interpolation to string concatenation
* Style/OptionalBooleanParameter: Use keyword arguments when defining method with boolean argument
* Style/GlobalStdStream: Use $stderr instead of STDERR
* Style/GlobalStdStream: Use $stdout instead of STDOUT
2020-09-03 23:18:18 +02:00
Claudio Bley
747dc37a13 Prepare release 1.4.2 2020-07-09 09:53:16 +02:00
dependabot-preview[bot]
41df9f7e0f
Merge pull request #370 from athityakumar/dependabot/bundler/rubocop-tw-0.87.0 2020-07-07 09:05:27 +00:00
Claudio Bley
7fb4c0619a Fix Style/AccessorGrouping offense in fileinfo.rb 2020-07-07 11:01:06 +02:00
Claudio Bley
f27048b1db Add missing require 'set'
Fixes #371
2020-07-07 09:02:20 +02:00
George Pickering
e345cfca8b Update yaml and monkeys to support hexstring colors 2020-05-28 15:02:37 -04:00
Claudio Bley
1a2d3ad6c1 Prepare release 1.4.1 2020-05-10 21:26:43 +02:00
Claudio Bley
f34453bce3 Workaround Errno::ENOENT error in rubygems
When trying to `require` a gem running in an unlinked directory, an exception is
thrown because `Dir.pwd` is called (see rubygems/rubygems#3087).

Until the fix lands in an official release, we monkey patch `Dir.pwd` to return
'/' if a `Errno::ENOENT` exception is raised while loading the colorls gem.

This should work for all Unixes. On Windows, this error cannot happen since you
cannot unlink a directory which is still in use by a process.

Fixes #351.
2020-05-10 21:23:07 +02:00
Claudio Bley
f8674d46df Prepare release 1.4.0 2020-05-08 22:27:51 +02:00
Claudio Bley
53a6bef959 Directly use Unicode symbols in yaml config 2020-05-08 22:12:35 +02:00
Claudio Bley
825e9f711c Only warn if locale settings are broken
Keep running if calling `setlocale` fails, because of invalid locale settings.

Fixes #335.
2020-04-17 00:21:11 +02:00
Claudio Bley
86cfa2f5cf Drop support for Ruby 2.4
It reached EOL on March 31, 2020, and no longer receives patches.

See https://www.ruby-lang.org/en/news/2020/04/05/support-of-ruby-2-4-has-ended/
2020-04-16 22:49:54 +02:00
Claudio Bley
73e4de9378 Use ASCII_8BIT for paths and directory entries
On Unix systems the encoding of file names is specified by the user via the
locale settings.

In order to avoid encoding problems simply read file names in ASCII 8 bit
encoding and try to convert to the external encoding while replacing undefined
characters.

Also, does not show an icon if the external encoding does not support it and
shows a `=` instead of a check mark for git status.

Fixes #352.
2020-04-16 21:58:39 +02:00
Max Ainatchi
8b6ba5ee2f
case-insensitive directory matching
Check directories case-insensitively, per https://github.com/athityakumar/colorls/issues/325
2020-03-16 17:32:17 -04:00
Claudio Bley
5640a6e104
Prepare release 1.3.3 2020-01-31 09:27:21 +01:00
Claudio Bley
6b2cbdc17d Fix exception when permission denied on symlinks
Fixes #338.
2020-01-31 08:57:55 +01:00
Claudio Bley
f451476238
Prepare release 1.3.2
[skip ci]
2020-01-24 09:53:08 +01:00
Claudio Bley
fb39a9da6d Correct git status for directories without changes
git does not report any status for empty directories, and it also does not
report any status for directories without any modified, untracked or ignored
files.

To correctly show the status, we need to check whether the directory is empty if
git did not report any status codes. When empty, show it as "not interesting",
otherwise the "no changes" green check mark is shown.

Note, I am specifically not using the untracked marker, as that would mean there
is some interesting file inside the directory which could be added.

Fixes #334.
2020-01-24 09:22:43 +01:00
Claudio Bley
d0244c2aa7 Fix git output showing no changes
Fixes #336.
2020-01-23 14:41:29 +01:00
Claudio Bley
6c51cd974d Bump VERSION to 1.3.1 2020-01-08 22:32:04 +01:00
Claudio Bley
d4aa862f79 Fix deprecation warning on Ruby 2.7
```
lib/colorls/flags.rb:50: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call
lib/colorls/core.rb:5: warning: The called method `initialize is defined here
```
2020-01-07 22:08:02 +01:00
Claudio Bley
141a8e5fbe Fix rubocop offense for Style/MultilineWhenThen 2019-07-24 18:21:20 +02:00
Claudio Bley
ac9734d879 Align number of link column in long listing
This fixes the misalignment of files in a long listing when some files have a
different number of characters in the links column.

Instead of iterating three times over the @contents array, in order to compute
the sizes of the variant columns, use a single loop to compute the maximum size
for each column in a one pass.
2019-07-07 23:09:22 +02:00