Commit graph

211 commits

Author SHA1 Message Date
Claudio Bley
dfd572310a Add --format=vertical and -C flags
* add and wire up `VerticalLayout` which is now the default
* adapt flags spec to use single-column layout for testing sort order
  since the output is hard to verify when in vertical format

Fixes #189.
2019-07-01 23:27:53 +02:00
Claudio Bley
d528bf18ef Introduce Layout classes and use them
* add `Layout` base class which contains the base (binary) algorithm
  for finding the maximum amount of columns fitting the given limit
* add `HorizontalLayout` and use it in `Core`
* add `SingleColumnLayout` and use it in `Core`
2019-07-01 23:16:33 +02:00
Claudio Bley
1dad6e0f15 Only add padding when necessary
Only when using more than one column, empty space should be added.

Instead of multiple print calls, we construct the complete line and print it.
2019-07-01 23:16:33 +02:00
Claudio Bley
41c933658b Simplify formatting in ColorLS#fetch_string 2019-07-01 23:16:33 +02:00
Paul McCarthy
ec0ed26458 Fix typo accross => across 2019-07-01 23:12:45 +02:00
Claudio Bley
97c9570437 Refactor git status handling, add some tests 2019-07-01 22:59:27 +02:00
Claudio Bley
56a0ec6903 Show number of hard links in long listing
Fixes #293
2019-06-30 19:05:00 +02:00
Claudio Bley
41669c94a3 Release version 1.2.0 2019-04-09 18:52:11 +02:00
Claudio Bley
7454814894 Handle git status for . and .. properly
The git status is only computed for the given directory and is stored as
a Hash mapping relative paths to their mode string.

For a directory, the git status is comprised of all the statuses of its files
itself and all its sub directories.

The current directory's prefix is just an empty string matching all files inside
the `@git_status` Hash.

Asking for the status of the parent directory is pointless, we do not compute it
(yet).
2019-04-08 21:47:18 +02:00
Claudio Bley
c0d9266378 Fix spec failures due to calling exit 2019-03-14 23:37:55 +01:00
Claudio Bley
6d6d121553 Add --human-readable option for compatibility with GNU ls
* make `-h` an alias for `--human-readable`
* both options are simply ignored when used with an argument or another option
* running `colorls -h` still shows the help text since just as before
2019-03-14 14:48:19 +01:00
Claudio Bley
c92b5c59a4 Fix git status reporting for file arguments 2019-03-11 23:42:38 +01:00
Claudio Bley
6f500722d0 Add String#delete_prefix method for Ruby < 2.5 2019-03-11 23:17:52 +01:00
Claudio Bley
b5caa35de5 Compute git status relative to the actual directory
Using the `--show-prefix` option for `git ref-parse` simplifies determining the
status for the child items.

Previsouly, `File.realdirpath` was used to determine an absolute path, but this
method returns a path without symlinks. This caused status to be reported about
the link target instead of the symlink.
2019-03-11 23:17:52 +01:00
Alex Cano
c60a2ebec8 Add the option to handle depth for the tree flag (#253)
* Add the option to handle depth for the tree flag

* Update README to describe the new option for the tree flag

* Add tests
2019-01-11 07:36:02 +01:00
Claudio Bley
e02b30a111 Drop support for Ruby 2.2
It reached EOL on 20th Jun 2018 and no longer receives patches.

* set required Ruby version to >= 2.3 in spec file
* set rubocop's TargetRubyVersion to 2.3 and fix all the offenses
2019-01-04 12:08:06 +01:00
Claudio Bley
9c266c9fda Make ColorLS::Git a module instead of a class
There is no reason it should inherit from `Core`.
2018-12-29 17:23:07 +01:00
Claudio Bley
306bcd3cbc Fix warning about method redefinement
`lib/colorls/monkeys.rb:26: warning: method redefined; discarding old sum`
2018-12-29 17:13:33 +01:00
Claudio Bley
73e036c939 Fix warning about unintialized instance variable
`warning: instance variable @git_status not initialized`
2018-12-29 16:46:51 +01:00
Claudio Bley
f0e53937de Fix rubocop warnings 2018-12-28 18:55:57 +01:00
Justin Hallquist
54bafa03f0 add forwardable dependency 2018-11-20 08:38:25 -08:00
Claudio Bley
7a9ea25808
Merge pull request #229 from avdv/socket-chardev-blockdev
Add support for special files
2018-11-12 08:23:51 +01:00
Claudio Bley
5d6fe50edd Remove _keys arrays from Core, use key? instead
Instead of searching through an Array, it is much better querying a Hash for a
key.
2018-10-21 23:27:38 +02:00
Claudio Bley
4a0ece2908 Add support for special files
Like sockets, character and block devices.
2018-10-21 23:14:21 +02:00
Claudio Bley
f3e9186ee2 Add --format and -x options
Both are also supported by GNU ls, although currently not all formats are
supported.

This change lays ground for implementing column based formatting and also
supports using a pager with colorls keeping the formatting intact:

`colorls --color -x | less --tabs=4 -RFX`
2018-10-20 10:50:30 +02:00
Claudio Bley
6b972de57d Add --color option
This option works the same as for GNU ls, although if not specified colorization
is on by default (the `auto` mode).

Using `--color` is equivalent to `--color=always`.
2018-10-20 00:01:31 +02:00
Jason Schweier
7bb0f564d5 Fix alignment for file sizes
File size can be up to 1023 B/KiB/etc.
The simplest solution is to allow 4 characters for alignment.
2018-10-13 14:49:48 -04:00
Claudio Bley
127eb510cd Check whether Etc.getpwuid/getgrid returns nil
On Microsoft Windows, the File.Stat information always has the `uid` and `gid`
set to `0`. Also, the Etc functions simply return `nil`.

Fixes #220.
2018-10-05 22:15:02 +02:00
Claudio Bley
126d8ba164 Fix #205: Handle optparse errors gracefully 2018-08-20 08:00:46 +02:00
Claudio Bley
8428efa010 Add --hyperlink option
This generates `file://` links using ANSI escape sequences which opens the
given file using the default application for the file type on your system.

A terminal emulator supporting hyperlinks is required, otherwise the links
will be ignored.
2018-08-17 23:00:55 +02:00
Claudio Bley
e9944d5f39 Fix #197: Take setuid, setgid and sticky bit into account
These special permission bits should cause the executable bit in the current
group to be replaced with an uppercase letter if the executable bit itself is
*not* set, with a lower case character otherwise.
2018-08-17 18:04:15 +02:00
Claudio Bley
159649ab65
Merge pull request #200 from avdv/sort-by-extension
Add `-X` / `--sort=extension` flags
2018-08-12 18:33:04 +02:00
Claudio Bley
1b71184fac Fix rubocop offense Metrics/LineLength: Line is too long 2018-08-12 16:22:27 +02:00
Claudio Bley
012aeb8493 Add -X / --sort=extension flags
This allows the listing to be sorted alphabetically by file extension.

Fixes #199.
2018-08-12 16:22:27 +02:00
mashehu
8d9a3a83f7 added icon for dockerfiles 2018-06-08 15:47:22 +02:00
Claudio Bley
d7e12246e3 Always colorize user info
In a long listing, the user was only shown when owning the file. Originally, the
user was only colorized when owning the file.

Change that to always colorize the user using the defined `:user` color.

Fixes #187.
2018-04-20 11:58:09 +02:00
Athitya
3aab256ab5 Ships v1.1.1 for release 2018-04-09 00:25:04 +05:30
Claudio Bley
8b0ea26c01 Skip next NUL separated git status field for renames
In the `-z` git status format, a NUL follows each file name. When files are
renamed, the status field is followed by a space, the "to" path, a NUL
character, the "from" path and a terminating NUL.

This fixes #185.
2018-03-28 08:23:55 +02:00
Claudio Bley
51fe55cc8f Simplify git mode padding 2018-03-27 19:51:13 +02:00
Claudio Bley
b362fa1eb8 Improve git-status processing
* no longer traverse complete directory trees to determine git status for
  directories

* properly report status for folders with changed files

* skip the parent folder since we do not have git status about it
2018-03-27 19:50:52 +02:00
Andy
bb270b319a Adds some media types (#180)
* add some media types

* alphabetize the media types
2018-02-01 21:43:38 +05:30
Andy
99b94da2f6 add jupyter notebooks to file aliases (#181) 2018-01-30 01:16:55 +05:30
Athitya
0ed7f76b14 Updates to version v1.1.0 2018-01-15 23:46:58 +05:30
Claudio Bley
d12b95da6e Avoid reading link target when not needed
It is only needed in long listing mode.
2018-01-02 11:02:36 +01:00
Claudio Bley
038c15f53c Interprete path with trailing slash as a directory 2018-01-02 11:02:36 +01:00
Claudio Bley
fa803c6cb6 Simplify git info handling 2018-01-02 11:02:36 +01:00
Claudio Bley
68215c56b0 Use porcelain mode with git status, no chdir 2018-01-02 11:02:36 +01:00
Claudio Bley
694fdee03c Use git rev-parse to find git root path 2018-01-02 11:02:36 +01:00
Claudio Bley
f9db84a2b1 Avoid re-computing max_widths 2018-01-02 11:02:36 +01:00
Claudio Bley
a6879dc23d Avoid Time.now call 2018-01-02 11:02:36 +01:00
Claudio Bley
ff7dd59a8c Use information from stat call to colorize user 2018-01-02 11:02:36 +01:00
Claudio Bley
e0ebbdb3d0 Add FileInfo class, reduce syscalls 2018-01-02 11:02:36 +01:00
Claudio Bley
60cc97bbd2 Simplify path handling in Core class 2017-12-10 22:50:13 +01:00
Claudio Bley
1d3bd49f5d Handle errors gracefully
Do not print a backtrace when a `SystemCallError` occurs and keep going to
process arguments afterwards.
2017-12-10 22:50:13 +01:00
Claudio Bley
0c6a174081 Avoid using count if size or length works
According to [1] one should prefer the latter over the former whenever possible.

[1]: http://batsov.com/articles/2014/02/17/the-elements-of-style-in-ruby-number-13-length-vs-size-vs-count/
2017-12-10 10:06:14 +01:00
Claudio Bley
fe78028949 Use IO#winsize instead of calling out to tput
If the window size cannot be determined, use a default of 80 columns, just like
tput.
2017-12-10 10:05:30 +01:00
Claudio Bley
bebe09f5f7 Use clocale gem for proper sorting 2017-12-01 09:05:04 +01:00
Athitya Kumar
60012c93d9
Merge pull request #161 from rohitner/master
Removed bug of ignored files
2017-11-23 03:46:26 +05:30
Claudio Bley
96ec0d5276 Generate Zsh completion file
Add the `_colorls` completion file to the `zsh/` folder of the gem and make the
`tab_complete.sh` script work for Zsh too.
2017-11-22 22:32:20 +01:00
rohitner
1fefca92a9 fixed rubocop issue 2017-11-23 00:10:53 +05:30
rohitner
6deb982c2e fix for partially gitignored dirs 2017-11-23 00:10:36 +05:30
rohitner
e6f0de0679 fix partially ignored files 2017-11-22 19:38:21 +05:30
rohitner
90a296bf35 removed bug of ignored files 2017-11-20 20:57:09 +05:30
Claudio Bley
1b587d8257 Generate man page using ronn 2017-11-17 21:33:44 +01:00
Alex
8dade9d52a Update yaml to proper class. Fix invocations so tests pass 2017-11-07 19:22:37 -05:00
Alex
1cd2029126 Create yaml class and add class methods. Move specs to appropriate folder. Fix method calls. Move flags spec to appropriate folder for rubocop 2017-11-07 19:22:37 -05:00
Claudio Bley
0bc518dda4 Move handling of output mode into core
This prevents giving mutual exclusive options to Core.initialize which could
lead to unexpected results.
2017-11-07 22:38:52 +01:00
Matthew Vincent
ba257b970b Add support for sorting by size
* add `--sort=size` flag
* add `-S` flag
* adjust `.travis.yml` to check the new flags
2017-11-07 22:38:42 +01:00
Claudio Bley
25b21c442a Add support for reverse sorting
Re-assign the `-r` short option from `--report` to `--reverse` and mention this
change in the post install message.
2017-11-07 22:38:42 +01:00
Claudio Bley
2df30f7f33 Add support for sorting by mtime
* add `--sort=WORD` option, which sorts by modification "time" or not at all

* add short option `-U` to mean `--sort=none` (`ls` compatibility)

* `-t` now has the same effect as `--sort=time` which is also mentioned in the
  post install mesage

* add checks for `--sort=time` and `--sort=none` to .travis.yml
2017-11-06 08:42:02 +01:00
Claudio Bley
52badf7ed5 Separate sorting and grouping 2017-11-01 09:14:20 +01:00
Claudio Bley
869dc86d3f Print directory argument before listing contents
If there are a lot of arguments, e.g. due to shell globbing, one might easily
lose track of which output corresponds to which argument.

Again, this is similar to what `ls` does.
2017-11-01 09:07:34 +01:00
Claudio Bley
d48f545344 Sort output by default and re-enable test
When not using any sort options, sort the output by name.

This is in line with what `ls` does, too.

Revert "Disable failing test"

This reverts commit 9e41d60956.
2017-11-01 09:07:34 +01:00
Athitya
e475ba32f2 Updates version to 1.0.9 2017-10-29 05:49:23 +05:30
Athitya
d0a7bba396 Fixes minor chdir issue 2017-10-29 05:43:15 +05:30
Athitya
7543257c7e Removes require call of git gem 2017-10-29 05:39:40 +05:30
Athitya
9dbe6cde49 Adds rubocop fixes 2017-10-29 05:35:57 +05:30
Athitya
919ddb7c4c Adds colors for git-status 2017-10-29 05:34:25 +05:30
Athitya
0984a529ac Adds custom config coloring support for faster git-status 2017-10-29 05:32:38 +05:30
Athitya
a88598e10e Updates version to 1.0.8 2017-10-28 23:05:20 +05:30
Athitya
086cc05adc Fixes minor facets remanant 2017-10-28 23:04:47 +05:30
Athitya
15c5317b1e Updates version to 1.0.7 2017-10-28 22:56:32 +05:30
Athitya
a6a6fffd64 Removes facets dependency 2017-10-28 22:55:05 +05:30
Athitya
b286f71ef0 Adds rake as runtime dependency and updates to 1.0.6 2017-10-28 22:26:39 +05:30
Athitya
aa6920abdc Updates version to 1.0.5 2017-10-28 22:01:56 +05:30
Athitya
5619a5bbf8 Requires monkey patches 2017-10-28 21:58:22 +05:30
Athitya
c9beb097a8 Fixes rubocop issue 2017-10-28 21:36:49 +05:30
Athitya
0501c0b4a2 Adds monkeys.rb, and clean-ups before merging 2017-10-28 21:03:05 +05:30
Athitya
2ea96f1212 Adds support for new inbuilt colors 2017-10-28 20:54:44 +05:30
Athitya
7c6d09c0f7 Fixes --long with --git-status flag combination 2017-10-28 20:10:21 +05:30
Athitya
8e1d16e884 Adds custom config coloring support for git-status 2017-10-28 19:37:51 +05:30
Athitya
1dd794ff23 Adds monkey patch for colorize method 2017-10-28 19:10:10 +05:30
Athitya
aeb3a3950c Switches from colorize to rainbow dependency 2017-10-28 18:21:01 +05:30
Athitya
67d632ffca Updates version to 1.0.4 2017-10-28 16:11:20 +05:30
Claudio Bley
8424e4de27 Use optparse for tab completion (#138) 2017-10-28 16:09:09 +05:30
Athitya
85fa654870 Fixes minor bug with tab completion and updates version to 1.0.3 2017-10-22 23:52:30 +05:30
Athitya
ae20613f94 Updates version to 1.0.2 2017-10-22 23:46:15 +05:30
Athitya
b2fa5f18d7 Fixes minor rubocop offense 2017-10-21 02:58:18 +05:30
Athitya
24406eaa67 Updates version to 1.0.0 2017-10-21 02:48:13 +05:30
Claudio Bley
bf73fd3462 Fixes flag handling issue introduced in PR #129 (#131)
* Fix handling of `--tree` and `--all` / `--allmost_all` flags

When using `:tree` mode, the `:allmost_all` was always enabled unconditionally.

* Add example for combining short options
2017-10-21 02:26:51 +05:30