fork/eza
git clone https://git.julia.blue/fork/eza
537c9520
main
1using namespace System.Management.Automation 2using namespace System.Management.Automation.Language 3 4Register-ArgumentCompleter -Native -CommandName'eza' -ScriptBlock { 5param ($wordToComplete ,$commandAst ,$cursorPosition ) 6 7$ArrayWhen = @('always' ,'auto' ,'never' ) 8$ArraySort = @('name' ,'extension' ,'size' ,'type' ,'created' ,'modified' ,'accessed' ,'changed' ,'inode' ,'none' ) 9$ArrayColorScaleMode = @('fixed' ,'gradient' ) 10$ArrayColorScale = @('all' ,'age' ,'size' ) 11$ArrayAbsolute = @('on' ,'follow' ,'off' ) 12$ArrayTime = @('modified' ,'accessed' ,'created' ) 13$ArrayTimeStyle = @('default' ,'iso' ,'long-iso' ,'full-iso' ,'relative' ,'+%Y-%m-%d %H:%M' ,'+%Y.%m.%d %H:$M:$s' ) 14 15$commandElements =$commandAst .CommandElements 16$command = @( 17'eza' 18for ($i =1 ;$i -lt $commandElements .Count ;$i ++) { 19$element =$commandElements [$i ] 20if ($element -isnot [StringConstantExpressionAst ]-or 21$element .StringConstantType -ne [StringConstantType ]::BareWord -or 22$element .Value -eq $wordToComplete ) { 23break 24 } 25$element .Value 26 })-join ';' 27 28$completions = @(switch -Wildcard ($command ) { 29'*;--help' { 30break 31 } 32'*;--version' { 33break 34 } 35'*;--absolute' { 36$ArrayAbsolute | 37 ForEach-Object {[System.Management.Automation.CompletionResult ]::new ($_ ,$_ ,"ParameterValue" ,$_ )} 38break 39 } 40'*;--sort' { 41$ArraySort | 42 ForEach-Object {[System.Management.Automation.CompletionResult ]::new ($_ ,$_ ,"ParameterValue" ,$_ )} 43break 44 } 45'*;--color-scale' { 46$ArrayColorScale | 47 ForEach-Object {[System.Management.Automation.CompletionResult ]::new ($_ ,$_ ,"ParameterValue" ,$_ )} 48break 49 } 50'*;--color-scale-mode' { 51$ArrayColorScaleMode | 52 ForEach-Object {[System.Management.Automation.CompletionResult ]::new ($_ ,$_ ,"ParameterValue" ,$_ )} 53break 54 } 55'*--long;*--time-style' { 56$ArrayTimeStyle | 57 ForEach-Object {[System.Management.Automation.CompletionResult ]::new ($_ ,$_ ,"ParameterValue" ,$_ )} 58break 59 } 60'*--long;*--time' { 61$ArrayTime | 62 ForEach-Object {[System.Management.Automation.CompletionResult ]::new ($_ ,$_ ,"ParameterValue" ,$_ )} 63break 64 } 65'*;--classify' { 66$ArrayWhen | 67 ForEach-Object {[System.Management.Automation.CompletionResult ]::new ($_ ,$_ ,"ParameterValue" ,$_ )} 68break 69 } 70'*;--color' { 71$ArrayWhen | 72 ForEach-Object {[System.Management.Automation.CompletionResult ]::new ($_ ,$_ ,"ParameterValue" ,$_ )} 73break 74 } 75'*;--icons' { 76$ArrayWhen | 77 ForEach-Object {[System.Management.Automation.CompletionResult ]::new ($_ ,$_ ,"ParameterValue" ,$_ )} 78break 79 } 80'*;--all' { 81 [CompletionResult ]::new ('--show-symlinks' ,'listfilessyl' , [CompletionResultType ]::ParameterName ,'explicitly show symbolic links (for use with --only-dirs | --only-files)' ) 82 [CompletionResult ]::new ('--no-symlinks' ,'listfilessyl' , [CompletionResultType ]::ParameterName ,'do not show symbolic links' ) 83break 84 } 85'*long*' { 86# [CompletionResult]::new('-b' ,'binary' , [CompletionResultType]::ParameterName, 'list file sizes with binary prefixes') 87 [CompletionResult ]::new ('--binary' ,'binary' , [CompletionResultType ]::ParameterName ,'list file sizes with binary prefixes' ) 88# [CompletionResult]::new('-B' ,'bytes' , [CompletionResultType]::ParameterName, 'list file sizes in bytes, without any prefixes') 89 [CompletionResult ]::new ('--bytes' ,'bytes' , [CompletionResultType ]::ParameterName ,'list file sizes in bytes, without any prefixes' ) 90# [CompletionResult]::new('-g' ,'group' , [CompletionResultType]::ParameterName, 'list each file''s group') 91 [CompletionResult ]::new ('--smart-group' ,'smart-group' , [CompletionResultType ]::ParameterName ,'only show group if it has a different name from owner' ) 92 [CompletionResult ]::new ('--group' ,'group' , [CompletionResultType ]::ParameterName ,'list each file''s group' ) 93# [CompletionResult]::new('-h' ,'header' , [CompletionResultType]::ParameterName, 'add a header row to each column') 94 [CompletionResult ]::new ('--header' ,'header' , [CompletionResultType ]::ParameterName ,'add a header row to each column' ) 95# [CompletionResult]::new('-H' ,'links' , [CompletionResultType]::ParameterName, 'list each file''s number of hard links') 96 [CompletionResult ]::new ('--links' ,'links' , [CompletionResultType ]::ParameterName ,'list each file''s number of hard links' ) 97# [CompletionResult]::new('-i' ,'inode' , [CompletionResultType]::ParameterName, 'list each file''s inode number') 98 [CompletionResult ]::new ('--inode' ,'inode' , [CompletionResultType ]::ParameterName ,'list each file''s inode number' ) 99# [CompletionResult]::new('-M' ,'mounts' , [CompletionResultType]::ParameterName, 'show mount details (Linux and Mac only)') 100# [CompletionResult]::new('--mounts' ,'mounts' , [CompletionResultType]::ParameterName, 'show mount details (Linux and Mac only)') 101# [CompletionResult]::new('-n' ,'numeric' , [CompletionResultType]::ParameterName, 'list numeric user and group IDs') 102 [CompletionResult ]::new ('--numeric' ,'numeric' , [CompletionResultType ]::ParameterName ,'list numeric user and group IDs' ) 103# [CompletionResult]::new('-O' ,'flags' , [CompletionResultType]::ParameterName, 'list file flags (Mac, BSD, and Windows only)') 104 [CompletionResult ]::new ('--flags' ,'flags' , [CompletionResultType ]::ParameterName ,'list file flags (Mac, BSD, and Windows only)' ) 105# [CompletionResult]::new('-S' ,'blocksize' , [CompletionResultType]::ParameterName, 'show size of allocated file system blocks') 106 [CompletionResult ]::new ('--blocksize' ,'blocksize' , [CompletionResultType ]::ParameterName ,'show size of allocated file system blocks' ) 107# [CompletionResult]::new('-t' ,'time' , [CompletionResultType]::ParameterName, 'which timestamp field to list (modified, accessed, created)') 108 [CompletionResult ]::new ('--time' ,'time' , [CompletionResultType ]::ParameterName ,'which timestamp field to list (modified, accessed, created)' ) 109# [CompletionResult]::new('-m' ,'modified' , [CompletionResultType]::ParameterName, 'use the modified timestamp field') 110 [CompletionResult ]::new ('--modified' ,'modified' , [CompletionResultType ]::ParameterName ,'use the modified timestamp field' ) 111# [CompletionResult]::new('-u' ,'accessed' , [CompletionResultType]::ParameterName, 'use the accessed timestamp field') 112 [CompletionResult ]::new ('--accessed' ,'accessed' , [CompletionResultType ]::ParameterName ,'use the accessed timestamp field' ) 113# [CompletionResult]::new('-U' ,'created' , [CompletionResultType]::ParameterName, 'use the created timestamp field') 114 [CompletionResult ]::new ('--changed' ,'changed' , [CompletionResultType ]::ParameterName ,'use the changed timestamp field' ) 115 [CompletionResult ]::new ('--created' ,'created' , [CompletionResultType ]::ParameterName ,'use the created timestamp field' ) 116 [CompletionResult ]::new ('--time-style' ,'time-style' , [CompletionResultType ]::ParameterName ,'how to format timestamps (default, iso, long-iso,full-iso, relative, or a custom style ''+<FORMAT>'' like ''+%Y-%m-%d %H:%M'')' ) 117# [CompletionResult]::new('--total-size' ,'total-size' , [CompletionResultType]::ParameterName, 'show the size of a directory as the size of all files and directories inside (unix only)') 118# [CompletionResult]::new('-o' ,'octal-permissions' , [CompletionResultType]::ParameterName, 'list each file''s permission in octal format') 119 [CompletionResult ]::new ('--no-permissions' ,'no-permissions' , [CompletionResultType ]::ParameterName ,'suppress the permissions field' ) 120 [CompletionResult ]::new ('--octal-permissions' ,'octal-permissions' , [CompletionResultType ]::ParameterName ,'list each file''s permission in octal format' ) 121 [CompletionResult ]::new ('--no-filesize' ,'no-filesize' , [CompletionResultType ]::ParameterName ,'suppress the filesize field' ) 122 [CompletionResult ]::new ('--no-user' ,'no-user' , [CompletionResultType ]::ParameterName ,'suppress the user field' ) 123 [CompletionResult ]::new ('--no-time' ,'no-time' , [CompletionResultType ]::ParameterName ,'suppress the time field' ) 124 [CompletionResult ]::new ('--stdin' ,'stdin' , [CompletionResultType ]::ParameterName ,'read file names from stdin, one per line or other separator specified in environment' ) 125 [CompletionResult ]::new ('--git' ,'git' , [CompletionResultType ]::ParameterName ,'list each file''s Git status, if tracked or ignored' ) 126 [CompletionResult ]::new ('--no-git' ,'no-git' , [CompletionResultType ]::ParameterName ,'suppress Git status (always overrides -git, --git-repos, --git-repos-no-status)' ) 127 [CompletionResult ]::new ('--git-repos' ,'git-repos' , [CompletionResultType ]::ParameterName ,'list root of git-tree status' ) 128 [CompletionResult ]::new ('--git-repos-no-status' ,'git-repos-no-status' , [CompletionResultType ]::ParameterName ,'list each git-repos branch name (much faster)' ) 129 130break 131 } 132 default { 133# [CompletionResult]::new('-?' ,'help' , [CompletionResultType]::ParameterName, 'show list of command-line options') 134 [CompletionResult ]::new ('--help' ,'help' , [CompletionResultType ]::ParameterName ,'show list of command-line options' ) 135# [CompletionResult]::new('-v' ,'version' , [CompletionResultType]::ParameterName, 'show version of eza') 136 [CompletionResult ]::new ('--version' ,'version' , [CompletionResultType ]::ParameterName ,'show version of eza' ) 137# [CompletionResult]::new('-1' ,'oneline' , [CompletionResultType]::ParameterName, 'display one entry per line') 138 [CompletionResult ]::new ('--oneline' ,'oneline' , [CompletionResultType ]::ParameterName ,'display one entry per line' ) 139# [CompletionResult]::new('-l' ,'long' , [CompletionResultType]::ParameterName, 'display extended file metadata as a table') 140 [CompletionResult ]::new ('--long' ,'long' , [CompletionResultType ]::ParameterName ,'display extended file metadata as a table' ) 141# [CompletionResult]::new('-G' ,'grid' , [CompletionResultType]::ParameterName, 'display entries as a grid (default)') 142 [CompletionResult ]::new ('--grid' ,'grid' , [CompletionResultType ]::ParameterName ,'display entries as a grid (default)' ) 143# [CompletionResult]::new('-x' ,'across' , [CompletionResultType]::ParameterName, 'sort the grid across, rather than downwards') 144 [CompletionResult ]::new ('--across' ,'across' , [CompletionResultType ]::ParameterName ,'sort the grid across, rather than downwards' ) 145# [CompletionResult]::new('-R' ,'recurse' , [CompletionResultType]::ParameterName, 'recurse into directories') 146 [CompletionResult ]::new ('--recurse' ,'recurse' , [CompletionResultType ]::ParameterName ,'recurse into directories' ) 147# [CompletionResult]::new('-T' ,'tree' , [CompletionResultType]::ParameterName, 'recurse into directories as a tree') 148 [CompletionResult ]::new ('--tree' ,'tree' , [CompletionResultType ]::ParameterName ,'recurse into directories as a tree' ) 149# [CompletionResult]::new('-X' ,'dereference' , [CompletionResultType]::ParameterName, 'dereference symbolic links when displaying information') 150 [CompletionResult ]::new ('--dereference' ,'dereference' , [CompletionResultType ]::ParameterName ,'dereference symbolic links when displaying information' ) 151# [CompletionResult]::new('-F' ,'classify' , [CompletionResultType]::ParameterName, 'display type indicator by file names (always, auto, never)') 152 [CompletionResult ]::new ('--classify' ,'classify' , [CompletionResultType ]::ParameterName ,'display type indicator by file names (always, auto, never)' ) 153 [CompletionResult ]::new ('--color' ,'color' , [CompletionResultType ]::ParameterName ,'when to use terminal colours (always, auto, never)' ) 154# [CompletionResult]::new('--colour' ,'color' , [CompletionResultType]::ParameterName, 'when to use terminal colours (always, auto, never)') 155 [CompletionResult ]::new ('--color-scale' ,'colorscale' , [CompletionResultType ]::ParameterName ,'highlight levels of ''field'' distinctly(all, age, size)' ) 156# [CompletionResult]::new('--colour-scale' ,'colorscale' , [CompletionResultType]::ParameterName, 'highlight levels of ''field'' distinctly(all, age, size)') 157 [CompletionResult ]::new ('--color-scale-mode' ,'colorscalemode' , [CompletionResultType ]::ParameterName ,'use gradient or fixed colors in --color-scale (fixed, gradient)' ) 158# [CompletionResult]::new('--colour-scale-mode' ,'colorscalemode' , [CompletionResultType]::ParameterName, 'use gradient or fixed colors in --color-scale (fixed, gradient)') 159 [CompletionResult ]::new ('--icons' ,'icons' , [CompletionResultType ]::ParameterName ,'when to display icons (always, auto, never)' ) 160 [CompletionResult ]::new ('--no-quotes' ,'noquotes' , [CompletionResultType ]::ParameterName ,'don''t quote file names with spaces' ) 161 [CompletionResult ]::new ('--hyperlink' ,'hyperlink' , [CompletionResultType ]::ParameterName ,'display entries as hyperlinks' ) 162 [CompletionResult ]::new ('--absolute' ,'absolute' , [CompletionResultType ]::ParameterName ,'display entries with their absolute path (on, follow, off)' ) 163 [CompletionResult ]::new ('--follow-symlinks' ,'followsymlinks' , [CompletionResultType ]::ParameterName ,'drill down into symbolic links that point to directories' ) 164# [CompletionResult]::new('-w' ,'widths' , [CompletionResultType]::ParameterName, 'set screen width in columns') 165 [CompletionResult ]::new ('--width' ,'widths' , [CompletionResultType ]::ParameterName ,'set screen width in columns' ) 166# [CompletionResult]::new('-a' ,'filter' , [CompletionResultType]::ParameterName, 'show hidden and ''dot'' files. Use this twice to also show the ''.'' and ''..'' directories') 167 [CompletionResult ]::new ('--all' ,'filter' , [CompletionResultType ]::ParameterName ,'show hidden and ''dot'' files. Use this twice to also show the ''.'' and ''..'' directories' ) 168# [CompletionResult]::new('-A' ,'filter' , [CompletionResultType]::ParameterName, 'equivalent to --all; included for compatibility with `ls -A`') 169# [CompletionResult]::new('--almost-all' ,'filter' , [CompletionResultType]::ParameterName, 'equivalent to --all; included for compatibility with `ls -A`') 170# [CompletionResult]::new('-d' ,'filter' , [CompletionResultType]::ParameterName, 'list directories as files; don''t list their contents') 171 [CompletionResult ]::new ('--list-dirs' ,'filter' , [CompletionResultType ]::ParameterName ,'list directories as files; don''t list their contents' ) 172# [CompletionResult]::new('-D' ,'filter' , [CompletionResultType]::ParameterName, 'list only directories') 173 [CompletionResult ]::new ('--only-dirs' ,'filter' , [CompletionResultType ]::ParameterName ,'list only directories' ) 174# [CompletionResult]::new('-f' ,'filter' , [CompletionResultType]::ParameterName, 'list only files') 175 [CompletionResult ]::new ('--only-files' ,'filter' , [CompletionResultType ]::ParameterName ,'list only files' ) 176# [CompletionResult]::new('-L' ,'level' , [CompletionResultType]::ParameterName, 'limit the depth of recursion') 177 [CompletionResult ]::new ('--level' ,'level' , [CompletionResultType ]::ParameterName ,'limit the depth of recursion' ) 178# [CompletionResult]::new('-r' ,'reverse' , [CompletionResultType]::ParameterName, 'reverse the sort order') 179 [CompletionResult ]::new ('--reverse' ,'reverse' , [CompletionResultType ]::ParameterName ,'reverse the sort order' ) 180# [CompletionResult]::new('-s' ,'sort' , [CompletionResultType]::ParameterName, 'which field to sort by SORT_FIELD') 181 [CompletionResult ]::new ('--sort' ,'sort' , [CompletionResultType ]::ParameterName ,'which field to sort by SORT_FIELD' ) 182 [CompletionResult ]::new ('--group-directories-first' ,'gdf' , [CompletionResultType ]::ParameterName ,'list directories before other files' ) 183 [CompletionResult ]::new ('--group-directories-last' ,'gdl' , [CompletionResultType ]::ParameterName ,'list directories after other files' ) 184# [CompletionResult]::new('-I' ,'ignore-glob' , [CompletionResultType]::ParameterName, 'glob patterns (pipe-separated) of files to ignore GLOBS') 185 [CompletionResult ]::new ('--ignore-glob' ,'ignore-glob' , [CompletionResultType ]::ParameterName ,'glob patterns (pipe-separated) of files to ignore GLOBS' ) 186 [CompletionResult ]::new ('--git-ignore' ,'git-ignore' , [CompletionResultType ]::ParameterName ,'ignore files mentioned in ''.gitignore''' ) 187break 188 } 189 190 }) 191$completions .Where{ $_ .CompletionText -like " $wordToComplete *" } | 192Sort-Object -Property completionText 193}