mirror of
https://github.com/athityakumar/colorls.git
synced 2024-09-19 05:31:23 +02:00
Merge pull request #417 from t-mangoe/add-option-o-g
add -o and -g options.
This commit is contained in:
commit
64a42c105d
5 changed files with 232 additions and 32 deletions
|
@ -11,7 +11,7 @@ module ColorLS
|
||||||
class Core
|
class Core
|
||||||
def initialize(input, all: false, report: false, sort: false, show: false,
|
def initialize(input, all: false, report: false, sort: false, show: false,
|
||||||
mode: nil, git_status: false, almost_all: false, colors: [], group: nil,
|
mode: nil, git_status: false, almost_all: false, colors: [], group: nil,
|
||||||
reverse: false, hyperlink: false, tree_depth: nil)
|
reverse: false, hyperlink: false, tree_depth: nil, show_group: true, show_user: true)
|
||||||
@input = (+input).force_encoding(ColorLS.file_encoding)
|
@input = (+input).force_encoding(ColorLS.file_encoding)
|
||||||
@count = {folders: 0, recognized_files: 0, unrecognized_files: 0}
|
@count = {folders: 0, recognized_files: 0, unrecognized_files: 0}
|
||||||
@all = all
|
@all = all
|
||||||
|
@ -23,7 +23,7 @@ module ColorLS
|
||||||
@group = group
|
@group = group
|
||||||
@show = show
|
@show = show
|
||||||
@one_per_line = mode == :one_per_line
|
@one_per_line = mode == :one_per_line
|
||||||
@long = mode == :long
|
init_long_format(mode,show_group,show_user)
|
||||||
@tree = {mode: mode == :tree, depth: tree_depth}
|
@tree = {mode: mode == :tree, depth: tree_depth}
|
||||||
@horizontal = mode == :horizontal
|
@horizontal = mode == :horizontal
|
||||||
process_git_status_details(git_status)
|
process_git_status_details(git_status)
|
||||||
|
@ -75,6 +75,12 @@ module ColorLS
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def init_long_format(mode,show_group,show_user)
|
||||||
|
@long = mode == :long
|
||||||
|
@show_group = show_group
|
||||||
|
@show_user = show_user
|
||||||
|
end
|
||||||
|
|
||||||
# how much characters an item occupies besides its name
|
# how much characters an item occupies besides its name
|
||||||
CHARS_PER_ITEM = 12
|
CHARS_PER_ITEM = 12
|
||||||
|
|
||||||
|
@ -274,8 +280,11 @@ module ColorLS
|
||||||
|
|
||||||
links = content.nlink.to_s.rjust(@linklength)
|
links = content.nlink.to_s.rjust(@linklength)
|
||||||
|
|
||||||
[mode_info(content.stats), links, user_info(content), group_info(content.group),
|
line_array = [mode_info(content.stats), links]
|
||||||
size_info(content.size), mtime_info(content.mtime)].join(' ')
|
line_array.push user_info(content) if @show_user
|
||||||
|
line_array.push group_info(content.group) if @show_group
|
||||||
|
line_array.concat [size_info(content.size), mtime_info(content.mtime)]
|
||||||
|
line_array.join(' ')
|
||||||
end
|
end
|
||||||
|
|
||||||
def symlink_info(content)
|
def symlink_info(content)
|
||||||
|
|
|
@ -10,19 +10,7 @@ module ColorLS
|
||||||
@args = args
|
@args = args
|
||||||
@light_colors = false
|
@light_colors = false
|
||||||
|
|
||||||
@opts = {
|
@opts = default_opts
|
||||||
show: false,
|
|
||||||
sort: true,
|
|
||||||
reverse: false,
|
|
||||||
group: nil,
|
|
||||||
mode: STDOUT.tty? ? :vertical : :one_per_line, # rubocop:disable Style/GlobalStdStream
|
|
||||||
all: false,
|
|
||||||
almost_all: false,
|
|
||||||
report: false,
|
|
||||||
git_status: false,
|
|
||||||
colors: [],
|
|
||||||
tree_depth: 3
|
|
||||||
}
|
|
||||||
|
|
||||||
parse_options
|
parse_options
|
||||||
|
|
||||||
|
@ -81,6 +69,24 @@ module ColorLS
|
||||||
warn "WARN: #{e}, check your locale settings"
|
warn "WARN: #{e}, check your locale settings"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def default_opts
|
||||||
|
{
|
||||||
|
show: false,
|
||||||
|
sort: true,
|
||||||
|
reverse: false,
|
||||||
|
group: nil,
|
||||||
|
mode: STDOUT.tty? ? :vertical : :one_per_line, # rubocop:disable Style/GlobalStdStream
|
||||||
|
all: false,
|
||||||
|
almost_all: false,
|
||||||
|
report: false,
|
||||||
|
git_status: false,
|
||||||
|
colors: [],
|
||||||
|
tree_depth: 3,
|
||||||
|
show_group: true,
|
||||||
|
show_user: true
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
def add_sort_options(options)
|
def add_sort_options(options)
|
||||||
options.separator ''
|
options.separator ''
|
||||||
options.separator 'sorting options:'
|
options.separator 'sorting options:'
|
||||||
|
@ -126,8 +132,7 @@ module ColorLS
|
||||||
when 'single-column' then @opts[:mode] = :one_per_line
|
when 'single-column' then @opts[:mode] = :one_per_line
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
options.on('-1', 'list one file per line') { @opts[:mode] = :one_per_line }
|
options.on('-1', 'list one file per line') { @opts[:mode] = :one_per_line }
|
||||||
options.on('-l', '--long', 'use a long listing format') { @opts[:mode] = :long }
|
|
||||||
options.on('--tree=[DEPTH]', Integer, 'shows tree view of the directory') do |depth|
|
options.on('--tree=[DEPTH]', Integer, 'shows tree view of the directory') do |depth|
|
||||||
@opts[:tree_depth] = depth
|
@opts[:tree_depth] = depth
|
||||||
@opts[:mode] = :tree
|
@opts[:mode] = :tree
|
||||||
|
@ -136,6 +141,19 @@ module ColorLS
|
||||||
options.on('-C', 'list entries by columns instead of by lines') { @opts[:mode] = :vertical }
|
options.on('-C', 'list entries by columns instead of by lines') { @opts[:mode] = :vertical }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def add_long_style_options(options)
|
||||||
|
options.on('-l', '--long', 'use a long listing format') { @opts[:mode] = :long }
|
||||||
|
options.on('-o', 'use a long listing format without group information') do
|
||||||
|
@opts[:mode] = :long
|
||||||
|
@opts[:show_group] = false
|
||||||
|
end
|
||||||
|
options.on('-g', 'use a long listing format without owner information') do
|
||||||
|
@opts[:mode] = :long
|
||||||
|
@opts[:show_user] = false
|
||||||
|
end
|
||||||
|
options.on('-G', '--no-group', 'show no group information in a long listing') { @opts[:show_group] = false }
|
||||||
|
end
|
||||||
|
|
||||||
def add_general_options(options)
|
def add_general_options(options)
|
||||||
options.separator ''
|
options.separator ''
|
||||||
options.separator 'general options:'
|
options.separator 'general options:'
|
||||||
|
@ -196,17 +214,22 @@ module ColorLS
|
||||||
EXAMPLES
|
EXAMPLES
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def assign_each_options(opts)
|
||||||
|
add_common_options(opts)
|
||||||
|
add_format_options(opts)
|
||||||
|
add_long_style_options(opts)
|
||||||
|
add_sort_options(opts)
|
||||||
|
add_compatiblity_options(opts)
|
||||||
|
add_general_options(opts)
|
||||||
|
add_help_option(opts)
|
||||||
|
end
|
||||||
|
|
||||||
def parse_options
|
def parse_options
|
||||||
@parser = OptionParser.new do |opts|
|
@parser = OptionParser.new do |opts|
|
||||||
opts.banner = 'Usage: colorls [OPTION]... [FILE]...'
|
opts.banner = 'Usage: colorls [OPTION]... [FILE]...'
|
||||||
opts.separator ''
|
opts.separator ''
|
||||||
|
|
||||||
add_common_options(opts)
|
assign_each_options(opts)
|
||||||
add_format_options(opts)
|
|
||||||
add_sort_options(opts)
|
|
||||||
add_compatiblity_options(opts)
|
|
||||||
add_general_options(opts)
|
|
||||||
add_help_option(opts)
|
|
||||||
|
|
||||||
opts.on_tail('--version', 'show version') do
|
opts.on_tail('--version', 'show version') do
|
||||||
puts ColorLS::VERSION
|
puts ColorLS::VERSION
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
.\" generated with Ronn/v0.7.3
|
.\" generated with Ronn/v0.7.3
|
||||||
.\" http://github.com/rtomayko/ronn/tree/0.7.3
|
.\" http://github.com/rtomayko/ronn/tree/0.7.3
|
||||||
.
|
.
|
||||||
.TH "COLORLS" "1" "October 2020" "colorls 1.4.2" "colorls Manual"
|
.TH "COLORLS" "1" "November 2020" "colorls 1.4.2" "colorls Manual"
|
||||||
.
|
.
|
||||||
.SH "NAME"
|
.SH "NAME"
|
||||||
\fBcolorls\fR \- list directory contents with colors and icons
|
\fBcolorls\fR \- list directory contents with colors and icons
|
||||||
|
@ -55,10 +55,6 @@ use format: across (\-x), horizontal (\-x), long (\-l), single\-column (\-1), ve
|
||||||
list one file per line
|
list one file per line
|
||||||
.
|
.
|
||||||
.TP
|
.TP
|
||||||
\fB\-l\fR, \fB\-\-long\fR
|
|
||||||
use a long listing format
|
|
||||||
.
|
|
||||||
.TP
|
|
||||||
\fB\-\-tree\fR
|
\fB\-\-tree\fR
|
||||||
shows tree view of the directory
|
shows tree view of the directory
|
||||||
.
|
.
|
||||||
|
@ -71,6 +67,22 @@ list entries by lines instead of by columns
|
||||||
list entries by columns instead of by lines
|
list entries by columns instead of by lines
|
||||||
.
|
.
|
||||||
.TP
|
.TP
|
||||||
|
\fB\-l\fR, \fB\-\-long\fR
|
||||||
|
use a long listing format
|
||||||
|
.
|
||||||
|
.TP
|
||||||
|
\fB\-o\fR
|
||||||
|
use a long listing format without group information
|
||||||
|
.
|
||||||
|
.TP
|
||||||
|
\fB\-g\fR
|
||||||
|
use a long listing format without owner information
|
||||||
|
.
|
||||||
|
.TP
|
||||||
|
\fB\-G\fR, \fB\-\-no\-group\fR
|
||||||
|
show no group information in a long listing
|
||||||
|
.
|
||||||
|
.TP
|
||||||
\fB\-\-sd\fR, \fB\-\-sort\-dirs\fR, \fB\-\-group\-directories\-first\fR
|
\fB\-\-sd\fR, \fB\-\-sort\-dirs\fR, \fB\-\-group\-directories\-first\fR
|
||||||
sort directories first
|
sort directories first
|
||||||
.
|
.
|
||||||
|
|
|
@ -325,4 +325,156 @@ RSpec.describe ColorLS::Flags do
|
||||||
expect(subject).to eq 2
|
expect(subject).to eq 2
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'with -o flag' do
|
||||||
|
let(:args) { ['-o', "#{FIXTURES}/a.txt"] }
|
||||||
|
|
||||||
|
before do
|
||||||
|
fileInfo = instance_double(
|
||||||
|
'FileInfo',
|
||||||
|
:group => "sys",
|
||||||
|
:mtime => Time.now,
|
||||||
|
:directory? => false,
|
||||||
|
:owner => "user",
|
||||||
|
:name => "a.txt",
|
||||||
|
:show => "a.txt",
|
||||||
|
:nlink => 1,
|
||||||
|
:size => 128,
|
||||||
|
:blockdev? => false,
|
||||||
|
:chardev? => false,
|
||||||
|
:socket? => false,
|
||||||
|
:symlink? => false,
|
||||||
|
:stats => OpenStruct.new(
|
||||||
|
mode: 0o444, # read for user, owner, other
|
||||||
|
setuid?: true,
|
||||||
|
setgid?: true,
|
||||||
|
sticky?: true
|
||||||
|
),
|
||||||
|
:executable? => false
|
||||||
|
)
|
||||||
|
|
||||||
|
allow(ColorLS::FileInfo).to receive(:new).with("#{FIXTURES}/a.txt", link_info: true) { fileInfo }
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'lists without group info' do
|
||||||
|
expect { subject }.not_to output(/sys/).to_stdout
|
||||||
|
end
|
||||||
|
it 'lists with user info' do
|
||||||
|
expect { subject }.to output(/user/).to_stdout
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with -g flag' do
|
||||||
|
let(:args) { ['-g', "#{FIXTURES}/a.txt"] }
|
||||||
|
|
||||||
|
before do
|
||||||
|
fileInfo = instance_double(
|
||||||
|
'FileInfo',
|
||||||
|
:group => "sys",
|
||||||
|
:mtime => Time.now,
|
||||||
|
:directory? => false,
|
||||||
|
:owner => "user",
|
||||||
|
:name => "a.txt",
|
||||||
|
:show => "a.txt",
|
||||||
|
:nlink => 1,
|
||||||
|
:size => 128,
|
||||||
|
:blockdev? => false,
|
||||||
|
:chardev? => false,
|
||||||
|
:socket? => false,
|
||||||
|
:symlink? => false,
|
||||||
|
:stats => OpenStruct.new(
|
||||||
|
mode: 0o444, # read for user, owner, other
|
||||||
|
setuid?: true,
|
||||||
|
setgid?: true,
|
||||||
|
sticky?: true
|
||||||
|
),
|
||||||
|
:executable? => false
|
||||||
|
)
|
||||||
|
|
||||||
|
allow(ColorLS::FileInfo).to receive(:new).with("#{FIXTURES}/a.txt", link_info: true) { fileInfo }
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'lists with group info' do
|
||||||
|
expect { subject }.to output(/sys/).to_stdout
|
||||||
|
end
|
||||||
|
it 'lists without user info' do
|
||||||
|
expect { subject }.not_to output(/user/).to_stdout
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with -o and -g flag' do
|
||||||
|
let(:args) { ['-og', "#{FIXTURES}/a.txt"] }
|
||||||
|
|
||||||
|
before do
|
||||||
|
fileInfo = instance_double(
|
||||||
|
'FileInfo',
|
||||||
|
:group => "sys",
|
||||||
|
:mtime => Time.now,
|
||||||
|
:directory? => false,
|
||||||
|
:owner => "user",
|
||||||
|
:name => "a.txt",
|
||||||
|
:show => "a.txt",
|
||||||
|
:nlink => 1,
|
||||||
|
:size => 128,
|
||||||
|
:blockdev? => false,
|
||||||
|
:chardev? => false,
|
||||||
|
:socket? => false,
|
||||||
|
:symlink? => false,
|
||||||
|
:stats => OpenStruct.new(
|
||||||
|
mode: 0o444, # read for user, owner, other
|
||||||
|
setuid?: true,
|
||||||
|
setgid?: true,
|
||||||
|
sticky?: true
|
||||||
|
),
|
||||||
|
:executable? => false
|
||||||
|
)
|
||||||
|
|
||||||
|
allow(ColorLS::FileInfo).to receive(:new).with("#{FIXTURES}/a.txt", link_info: true) { fileInfo }
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'lists without group info' do
|
||||||
|
expect { subject }.not_to output(/sys/).to_stdout
|
||||||
|
end
|
||||||
|
it 'lists without user info' do
|
||||||
|
expect { subject }.not_to output(/user/).to_stdout
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with -G flag in a listing format' do
|
||||||
|
let(:args) { ['-l', '-G', "#{FIXTURES}/a.txt"] }
|
||||||
|
|
||||||
|
before do
|
||||||
|
fileInfo = instance_double(
|
||||||
|
'FileInfo',
|
||||||
|
:group => "sys",
|
||||||
|
:mtime => Time.now,
|
||||||
|
:directory? => false,
|
||||||
|
:owner => "user",
|
||||||
|
:name => "a.txt",
|
||||||
|
:show => "a.txt",
|
||||||
|
:nlink => 1,
|
||||||
|
:size => 128,
|
||||||
|
:blockdev? => false,
|
||||||
|
:chardev? => false,
|
||||||
|
:socket? => false,
|
||||||
|
:symlink? => false,
|
||||||
|
:stats => OpenStruct.new(
|
||||||
|
mode: 0o444, # read for user, owner, other
|
||||||
|
setuid?: true,
|
||||||
|
setgid?: true,
|
||||||
|
sticky?: true
|
||||||
|
),
|
||||||
|
:executable? => false
|
||||||
|
)
|
||||||
|
|
||||||
|
allow(ColorLS::FileInfo).to receive(:new).with("#{FIXTURES}/a.txt", link_info: true) { fileInfo }
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'lists without group info' do
|
||||||
|
expect { subject }.not_to output(/sys/).to_stdout
|
||||||
|
end
|
||||||
|
it 'lists with user info' do
|
||||||
|
expect { subject }.to output(/user/).to_stdout
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -17,11 +17,15 @@ _arguments -s -S \
|
||||||
"--report[show brief report]" \
|
"--report[show brief report]" \
|
||||||
"--format[use format: across (-x), horizontal (-x), long (-l), single-column (-1), vertical (-C)]" \
|
"--format[use format: across (-x), horizontal (-x), long (-l), single-column (-1), vertical (-C)]" \
|
||||||
"-1[list one file per line]" \
|
"-1[list one file per line]" \
|
||||||
"-l[use a long listing format]" \
|
|
||||||
"--long[use a long listing format]" \
|
|
||||||
"--tree[shows tree view of the directory]" \
|
"--tree[shows tree view of the directory]" \
|
||||||
"-x[list entries by lines instead of by columns]" \
|
"-x[list entries by lines instead of by columns]" \
|
||||||
"-C[list entries by columns instead of by lines]" \
|
"-C[list entries by columns instead of by lines]" \
|
||||||
|
"-l[use a long listing format]" \
|
||||||
|
"--long[use a long listing format]" \
|
||||||
|
"-o[use a long listing format without group information]" \
|
||||||
|
"-g[use a long listing format without owner information]" \
|
||||||
|
"-G[show no group information in a long listing]" \
|
||||||
|
"--no-group[show no group information in a long listing]" \
|
||||||
"--sd[sort directories first]" \
|
"--sd[sort directories first]" \
|
||||||
"--sort-dirs[sort directories first]" \
|
"--sort-dirs[sort directories first]" \
|
||||||
"--group-directories-first[sort directories first]" \
|
"--group-directories-first[sort directories first]" \
|
||||||
|
|
Loading…
Reference in a new issue