Skip to content

Commit

Permalink
Fix passing path to ll on cli (#46)
Browse files Browse the repository at this point in the history
- fix issue where passing positional arg to ll would only display usage
- update readme and instructions
- reintroduce -h flag
  • Loading branch information
OldhamMade authored Jun 30, 2019
1 parent aeafa6f commit 9347117
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 77 deletions.
29 changes: 13 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# `ll` - a more informative `ls`, based on [`k`][1]

[![Waffle.io - Summary][7]][8] [![Travis Build][9]][10]
[![Travis Build][9]][10]


## Description
Expand Down Expand Up @@ -29,7 +29,7 @@ Calling `ll` provides a full file listing for a directory, similar to calling

Files sizes are graded from green for small (< 1k), to red for huge (> 1mb).

Human readable files sizes can be shown by using the `-h` flag.
Human readable files sizes can be shown by using the `-h` or `--human` flag.

### "Rotting" dates

Expand Down Expand Up @@ -74,35 +74,33 @@ and install using the following instructions.

### Requirements

- [Nim][3], minimum v0.19.0
- [Nim][3], minimum v0.20.0
- `make`

### Steps

Firstly install [Nim][3]. You'll need to install version 0.19 as a
Firstly install [Nim][3]. You'll need to install version 0.20 as a
minimum. I personally use [`asdf`][6] to manage Nim versions on my
machine. With `asdf` installed, this is as simple as calling `asdf
install nim v0.19.0`.
install nim v0.20.0`.

Once Nim is installed, clone this repository. From within the cloned
directory, call `make release` which will build `ll` into the working
directory. Copy the resulting `ll` binary to a location in your
`$PATH` (eg. `/usr/local/bin`).
directory, call `make install` which will build `ll` into the working
directory and will then opy the resulting `ll` binary to `/usr/local/bin`.

## Usage

$ ll

That's it. For more options, pass `--help`. Alternatively, read the
[usage](src/usage.txt) file.
That's it. For more options, pass `-?` or `--help`.

## Development

`ll` is developed using Github issues and [Kanban][4] (via
[Waffle][5]). If you would like to request a feature or report a bug,
please add a new issue [here](https://github.com/OldhamMade/ll/issues)
and we'll do our best to address them. Please note that this is not a
funded project and fixes will be addressed on a best-effort basis.
`ll` is developed using Github issues and [Kanban][4]. If you would
like to request a feature or report a bug, please add a new issue
[here](https://github.com/OldhamMade/ll/issues) and we'll do our best
to address them. Please note that this is not a funded project and
fixes will be addressed on a best-effort basis.

Contributions and pull-requests are always welcome, as is constructive
feedback around code structure, hints, tips, etc.
Expand Down Expand Up @@ -147,7 +145,6 @@ the listing; I'm currently reviewing what would be most useful.
[2]: https://en.wikipedia.org/wiki/Z_shell
[3]: https://nim-lang.org
[4]: https://en.wikipedia.org/wiki/Kanban
[5]: https://waffle.io
[6]: https://github.com/asdf-vm/asdf
[7]: https://badge.waffle.io/03e04bd3c5dd71dd392210b4479adccc.svg?columns=all
[8]: https://waffle.io/OldhamMade/ll
Expand Down
2 changes: 1 addition & 1 deletion ll.nimble
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Package

version = "0.1.0"
version = "0.2.0"
author = "Phillip Oldham"
description = "ll - a more informative ls, based on k"
license = "MIT"
Expand Down
67 changes: 41 additions & 26 deletions src/ll.nim
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,15 @@ proc getFileList(path: string, displayopts: DisplayOpts): seq[Entry] =

proc llCompose(
path: string,
displayopts: DisplayOpts): string =
let
entries = getFileList(path, displayopts)
formatted = formatattributes(entries, displayopts)

result = formatSummary(entries) & "\n" & tabulate(formatted)


proc buildDisplayOpts(
all = false,
aall = true,
dirsOnly = false,
Expand All @@ -600,8 +609,7 @@ proc llCompose(
sortByMtime = false,
sortReverse = false,
human = false,
vcs = true): string =

vcs = true): DisplayOpts =
var
optAll =
if all: DisplayAll.all
Expand All @@ -619,24 +627,22 @@ proc llCompose(
elif sortByMtime: DisplaySort.mtime
else: DisplaySort.default

let
displayOpts = DisplayOpts(
all: optAll,
dirs: optDirs,
size: optSize,
sortBy: optSort,
reversed: sortReverse,
vcs: vcs,
hasGit: gitAvailable(),
)
entries = getFileList(path, displayopts)
formatted = formatattributes(entries, displayopts)

result = formatSummary(entries) & "\n" & tabulate(formatted)
return DisplayOpts(
all: optAll,
dirs: optDirs,
size: optSize,
sortBy: optSort,
reversed: sortReverse,
vcs: vcs,
hasGit: gitAvailable(),
)


proc getTargetPath(path: string): string =
var path = path
proc getTargetPath(path: seq[string]): string =
var
path =
if path.len < 1: ""
else: path[0]

case path
of "":
Expand All @@ -656,7 +662,7 @@ when isMainModule:
import cligen

proc ll(
path = @[""],
path: seq[string],
all = false,
almost_all = false,
directory = false,
Expand All @@ -666,16 +672,25 @@ when isMainModule:
reverse = false,
human = false,
no_vcs = false) =
echo llCompose(getTargetPath path[0], all, almost_all, directory,
no_directory, size, mtime, reverse, human, not no_vcs)

var
displayOpts =
buildDisplayOpts(all, almost_all, directory, no_directory,
size, mtime, reverse, human, no_vcs)

echo llCompose(getTargetPath path, displayOpts)

clCfg.version = AppVersionFull
dispatch ll,
short = {"size": 'S',
"mtime": 't',
"no_vcs": 'V',
"almost_all": 'A',
"version": 'v'},
short = {
"size": 'S',
"mtime": 't',
"no_vcs": 'V',
"almost_all": 'A',
"version": 'v',
"human": 'h',
"help": '?'
},
help = {
"all": "list entries starting with .",
"almost_all": "list all except . and ..",
Expand Down
Loading

0 comments on commit 9347117

Please sign in to comment.