fork/fish-shell

git clone https://git.julia.blue/fork/fish-shell

Daniel Rainerformat: don't use tabs for indentatione0916e793

master
9.6 KiB179 linesraw
1#
2# Completions for the ls command and its aliases
3#
4
5# Shared ls switches
6set -l uname (uname -s)
7test "$uname" != SunOS
8and complete -c ls -s S -d "Sort by size"
9
10complete -c ls -s 1 -d "List one entry per line"
11complete -c ls -s c -d "Sort by changed time, (-l) show ctime"
12complete -c ls -s C -d "Force multi-column output"
13complete -c ls -s f -d "Unsorted output, enables -a"
14complete -c ls -s l -d "Long listing format"
15complete -c ls -s m -d "Comma-separated format, fills across screen"
16complete -c ls -s t -d "Sort by modified time, most recent first"
17complete -c ls -s u -d "Sort by access time, (-l) show atime"
18complete -c ls -s x -d "Multi-column output, horizontally listed"
19
20# Test if we are using GNU ls
21if ls --version >/dev/null 2>/dev/null
22    complete -c ls -s a -l all -d "Show hidden"
23    complete -c ls -s A -l almost-all -d "Show hidden except . and .."
24    complete -c ls -s b -l escape -d "Octal escapes for non-graphic characters"
25    complete -c ls -s d -l directory -d "List directories, not their content"
26    complete -c ls -s F -l classify -d "Append filetype indicator (*/=>@|)"
27    complete -c ls -s h -l human-readable -d "Human readable sizes"
28    complete -c ls -s H -l dereference-command-line -d "Follow symlinks"
29    complete -c ls -s i -l inode -d "Print inode number of files"
30    complete -c ls -s k -d "Set blocksize to 1kB" # BSD ls -k enables blocksize *output*
31    complete -c ls -s L -l dereference -d "Follow symlinks"
32    complete -c ls -s n -l numeric-uid-gid -d "Long format, numeric UIDs and GIDs"
33    complete -c ls -s p -l file-type -d "Append filetype indicator"
34    complete -c ls -s q -l hide-control-chars -d "Replace non-graphic characters with '?'"
35    complete -c ls -s r -l reverse -d "Reverse sort order"
36    complete -c ls -s R -l recursive -d "List subdirectory recursively"
37    complete -c ls -s s -l size -d "Print size of files"
38
39    # GNU specific ls switches
40    complete -c ls -l author -d "Print author"
41    complete -c ls -s B -l ignore-backups -d "Ignore files ending with ~"
42    complete -c ls -l block-size -x -d "Set block size"
43    complete -c ls -l color -f -a "never always auto" -d "Use colors"
44    complete -c ls -s D -l dired -d "Generate dired output"
45    complete -c ls -l dereference-command-line-symlink-to-dir #-d "Follow directory symlinks from command line"
46    complete -c ls -l format -x -a "across commas horizontal long single-column verbose vertical" -d "List format"
47    complete -c ls -l full-time -d "Long format, full-iso time"
48    complete -c ls -s G -l no-group -d "Don't print group information"
49    complete -c ls -l group-directories-first -r -d "Group directories before files"
50    complete -c ls -l hide -r -d "Do not list implied entries matching specified shell pattern"
51    complete -c ls -s I -l ignore -r -d "Skip entries matching pattern"
52    complete -c ls -l indicator-style -x -a "none classify file-type" -d "Append filetype indicator"
53    complete -c ls -l lcontext -d "Display security context"
54    complete -c ls -s N -l literal -d "Print raw entry names"
55    complete -c ls -s o -d "Long format without groups"
56    complete -c ls -s Q -l quote-name -d "Enclose entry in quotes"
57    complete -c ls -l quoting-style -x -a "literal locale shell shell-always c escape" -d "Select quoting style"
58    complete -c ls -l scontext -d "Display only security context and file name"
59    complete -c ls -l si -d "Human readable sizes, powers of 1000"
60    complete -c ls -l show-control-chars -d "Non-graphic characters printed as-is"
61    complete -c ls -l sort -x -d "Sort criteria" -a "
62            extension\t'Sort by file extension'
63            none\tDon\'t\ sort
64            size\t'Sort by size'
65            time\t'Sort by modification time'
66            version\t'Sort by version'
67            status\t'Sort by file status modification time'
68            atime\t'Sort by access time'
69            access\t'Sort by access time'
70            use\t'Sort by access time'
71        "
72    complete -c ls -s T -l tabsize -x -a "1 2 3 4 5 6 7 8 9 10 11 12" -d "Assume tab stops at each COLS"
73    complete -c ls -l time -x -d "Show time type" -a "
74            time\t'Sort by modification time'
75            access\t'Sort by access time'
76            use\t'Sort by use time'
77            ctime\t'Sort by file status modification time'
78            status\t'Sort by status time'
79        "
80    complete -c ls -l time-style -x -a "full-iso long-iso iso locale" -d "Select time style"
81    complete -c ls -s U -d "Do not sort"
82    complete -c ls -s v -d "Sort by version"
83    complete -c ls -s w -l width -x -d "Assume screen width"
84    complete -c ls -s X -d "Sort by extension"
85    complete -c ls -s Z -l context -d "Display security context so it fits on most displays"
86    complete -c ls -l help -d "Display help and exit"
87    complete -c ls -l version -d "Display version and exit"
88
89else
90    ####              ls on eunichs                  ####
91    # From latest checked-in man pages as of Nov 2018.
92    # Reformatted with Open Group's ordering and spacing,
93    # then sorted by prevalence, consolidating option
94    # matches.
95
96    #              [         IEEE 1003.1-2017 options         ]  [   extension options  ]
97    # freebsd: ls -[ikqrs][glno][Aa][Cmx1][Fp][LH][Rd][Sft][cu]  [hbTBWwPUG ZyI,        ] [-D format] [--color=when] [file ...]
98    # netbsd:  ls -[ikqrs][glno][Aa][Cmx1][Fp][L ][Rd][Sft][cu]  [hbTBWwP       XMO     ] [file ...]
99    # macOS:   ls -[ikqrs][glno][Aa][Cmx1][Fp][LH][Rd][Sft][cu]  [hbTBWwPUG       Oe@   ] [file ...]
100    # openbsd: ls -[ikqrs][glno][Aa][Cmx1][Fp][LH][Rd][Sft][cu]  [  TB                  ] [file ...]
101    # solaris: ls -[i qrs][glno][Aa][Cmx1][Fp][LH][Rd][ ft][cu]  [hb               e@EvV] [file ...]
102
103    # netbsd ls -O: only leaf files, no dirs | macos ls -O: include file flags in -l output
104    # so: don't complete -H for netbsd, and return early after the ls -P completion.
105    #     But not before adding their -X, -M, -O options. Same kind of thing for the other OSes.
106
107    ## IEEE 1003.1-2017 standard options:
108
109    complete -c ls -s i -d "Show inode numbers for files"
110    test "$uname" != SunOS
111    and complete -c ls -s k -d "for -s: Display sizes in kB, not blocks" # GNU sets block size with -k
112    complete -c ls -s q -d "Replace non-graphic characters with '?'"
113    complete -c ls -s r -d "Reverse sort order"
114    complete -c ls -s s -d "Show file sizes"
115
116    complete -c ls -s g -d "Show group instead of owner in long format"
117    complete -c ls -s n -d "Long format, numerical UIDs and GIDs"
118    contains "$uname" FreeBSD NetBSD OpenBSD DragonFly
119    and complete -c ls -s o -d "Long format, show file flags" # annoying BSD
120    or complete -c ls -s o -d "Long format, omit group names" # annoying POSIX
121
122    complete -c ls -s A -d "Show hidden except . and .."
123    complete -c ls -s a -d "Show hidden entries"
124
125    # -C in common, -m in common, -x in common, -1 in common
126
127    complete -c ls -s F -d "Append indicators. dir/ exec* link@ socket= fifo| whiteout%"
128    complete -c ls -s p -d "Append directory indicators"
129
130    complete -c ls -s L -d "Follow all symlinks Cancels -P option"
131    test "$uname" != NetBSD
132    and complete -c ls -s H -d "Follow symlink given on commandline" # not present on netbsd
133
134    complete -c ls -s R -d "Recursively list subdirectories"
135    complete -c ls -s d -d "List directories, not their content"
136
137    # -S in common, -f in common, -t in common
138    # -c in common, -u in common
139    ## These options are not standardized:
140    if test "$uname" != OpenBSD
141        complete -c ls -s h -d "Human-readable sizes"
142        complete -c ls -s b -d "C escapes for non-graphic characters"
143        if test "$uname" = SunOS
144            complete -c ls -s e -d "Like -l, but fixed time format with seconds"
145            complete -c ls -s @ -d "Like -l, but xattrs shown instead of ACLs"
146            complete -c ls -s E -d "Like -l, but fixed time format with nanoseconds"
147            complete -c ls -s v -d "Like -l, but verbose ACL information shown as well as -l output"
148            complete -c ls -s V -d "Like -l, but compact ACL information printed after -l output"
149            exit 0
150        end
151    else
152        exit 0 # OpenBSD
153    end
154    complete -c ls -s T -d "for -l: Show complete date and time"
155    complete -c ls -s B -d "Octal escapes for non-graphic characters"
156    complete -c ls -s W -d "Display whiteouts when scanning directories"
157    complete -c ls -s w -d "Force raw printing of non-printable characters"
158    complete -c ls -s P -d "Don't follow symlinks"
159    switch "$uname"
160        case NetBSD
161            complete -c ls -s X -d "Don't cross mount points when recursing"
162            complete -c ls -s M -d "for -l, -s: Format size/count with commas"
163            complete -c ls -s O -d "Show only leaf files (not dirs), eliding other output"
164            exit 0
165        case Darwin
166            complete -c ls -s O -d "for -l: Show file flags"
167            complete -c ls -s e -d "for -l: Print ACL associated with file, if present"
168            complete -c ls -s @ -d "for -l: Display extended attributes"
169        case FreeBSD
170            complete -c ls -s Z -d "Display each file's MAC label"
171            complete -c ls -s y -d "for -t: Sort A-Z output in same order as time output"
172            complete -c ls -s I -d "Prevent -A from being automatically set for root"
173            complete -c ls -s , -d "for -l: Format size/count number groups with ,/locale"
174            complete -r -c ls -s D -d "for -l: Format date with strptime string"
175            complete -c ls -l color -f -a "auto always never" -d "Enable color output"
176    end
177    complete -c ls -s U -d "Sort (-t) by creation time and show time (-l)"
178    complete -c ls -s G -d "Enable colorized output" # macos, freebsd.
179end