Skip to content

Commit

Permalink
#11 more text about --follow-symlinks
Browse files Browse the repository at this point in the history
  • Loading branch information
epogrebnyak committed Mar 4, 2024
1 parent 2e9915c commit 38fc86f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 10 deletions.
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,17 @@ C:\tools\Cmder\bin;C:\tools\Cmder\vendor\bin;C:\Windows\system32;C:\Windows;...
{"total": 52, "invalid": 1, "duplicates": 16}
```

### 7. Follow symlinks when looking for duplicates

Often times symbolic links are added to `PATH` to point to a particular version
of a package. You can discover more duplicate directories with `--follow-symlinks` flag.

```console
$ justpath --duplicates --follow-symlinks --includes dotnet
6 /home/codespace/.dotnet (resolves to /usr/local/dotnet/7.0.306, duplicates: 2)
32 /usr/local/dotnet/current (resolves to /usr/local/dotnet/7.0.306, duplicates: 2)
```

## Installation

### Stable version
Expand Down Expand Up @@ -325,8 +336,7 @@ Check out the discussion at [Hacker News](https://news.ycombinator.com/item?id=3
about bash and zsh scripts and `justpath` scenarios.

> [!TIP]
> `--shell-equivalents` flag provides a reference about one line commands for several shells that do similar jobs as `justpath` itself.
> Try `justpath --shell-equivalents`.
> `justpath --shell-equivalents` provides a reference about one line commands for several shells that do similar jobs as `justpath` itself.
### Other utilities

Expand Down
29 changes: 21 additions & 8 deletions justpath/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ def make_row(i, path):
return [make_row(i, path) for i, path in self.items()]


def resolve(path: Path):
def resolve(path: Path) -> str:
return str(path.resolve()).lower()


def as_is(path: Path):
def as_is(path: Path) -> str:
return str(path).lower()


Expand Down Expand Up @@ -123,7 +123,9 @@ def show(
includes: option("Show paths that include a specific string.", str) = "", # type: ignore
excludes: option("Show paths that do not include a specific string.", str) = "", # type: ignore
follow_symlinks: option("Resolve symbolic links.", bool) = False, # type: ignore
bare: option("Hide extra information about paths.") = False, # type: ignore
bare: option("Provide minimal text output.") = False, # type: ignore
comments: option("Add extra information about paths.") = True, # type: ignore
numbers: option("Add line numbers.") = True, # type: ignore
color: option("Use color to highlight errors.") = True, # type: ignore
string: option("Print a single string suitable as PATH content.") = False, # type: ignore
json: option("Format output as JSON.") = False, # type: ignore
Expand Down Expand Up @@ -156,17 +158,17 @@ def show(
follow_symlinks,
)
paths = [str(row.path) for row in rows]
if bare:
comments = False
numbers = False
color = False
if string:
print(os.pathsep.join(paths))
elif json:
print(dumps(paths, indent=2))
else:
for row in rows:
if bare:
modifier = get_color(row) if color else ""
print(modifier + str(row.path))
else:
print_row(row, color, path_var.max_digits)
print_row2(row, color, comments, numbers, path_var.max_digits)
if color:
print(Style.RESET_ALL, end="")

Expand Down Expand Up @@ -226,6 +228,17 @@ def get_comment(row: Row) -> str:
return ""


def print_row2(row: Row, color: bool, comments: bool, numbers: bool, max_digits: int):
color_modifier = get_color(row) if color else ""
comment_text = (" " + get_comment(row)) if comments else ""
line_number_text = (str(row.i).rjust(max_digits) + " ") if numbers else ""
print("".join([color_modifier,
line_number_text,
str(row.path),
comment_text]))



def print_row(row: Row, color: bool, n: int):
modifier = get_color(row) if color else ""
comment = get_comment(row)
Expand Down

0 comments on commit 38fc86f

Please sign in to comment.