@@ -96,20 +96,32 @@ The recommended way to replace an existing command is to shadow the command.
96
96
Here is an example shadowing the ` ls ` command.
97
97
98
98
``` 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
114
126
}
115
127
```
0 commit comments