Skip to content

Commit e94eabc

Browse files
docs(aliases): refactor the ls shadow alias (nushell#1766)
Co-authored-by: Artur Manuel <[email protected]>
1 parent 04ad7a5 commit e94eabc

File tree

1 file changed

+27
-15
lines changed

1 file changed

+27
-15
lines changed

book/aliases.md

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -96,20 +96,32 @@ The recommended way to replace an existing command is to shadow the command.
9696
Here is an example shadowing the `ls` command.
9797

9898
```nu
99-
# An escape hatch to have access to the original ls command
100-
alias core-ls = ls
101-
102-
# Call the built-in ls command with a path parameter
103-
def old-ls [path] {
104-
core-ls $path | sort-by type name -i
105-
}
106-
107-
# Shadow the ls command so that you always have the sort type you want
108-
def ls [path?] {
109-
if $path == null {
110-
old-ls .
111-
} else {
112-
old-ls $path
113-
}
99+
# alias the built-in ls command to ls-builtins
100+
alias ls-builtin = ls
101+
102+
# List the filenames, sizes, and modification times of items in a directory.
103+
def ls [
104+
--all (-a), # Show hidden files
105+
--long (-l), # Get all available columns for each entry (slower; columns are platform-dependent)
106+
--short-names (-s), # Only print the file names, and not the path
107+
--full-paths (-f), # display paths as absolute paths
108+
--du (-d), # Display the apparent directory size ("disk usage") in place of the directory metadata size
109+
--directory (-D), # List the specified directory itself instead of its contents
110+
--mime-type (-m), # Show mime-type in type column instead of 'file' (based on filenames only; files' contents are not examined)
111+
--threads (-t), # Use multiple threads to list contents. Output will be non-deterministic.
112+
...pattern: glob, # The glob pattern to use.
113+
]: [ nothing -> table ] {
114+
let pattern = if ($pattern | is-empty) { [ '.' ] } else { $pattern }
115+
(ls-builtin
116+
--all=$all
117+
--long=$long
118+
--short-names=$short_names
119+
--full-paths=$full_paths
120+
--du=$du
121+
--directory=$directory
122+
--mime-type=$mime_type
123+
--threads=$threads
124+
...$pattern
125+
) | sort-by type name -i
114126
}
115127
```

0 commit comments

Comments
 (0)