testMathFishCompletionScript().fish 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. function __math_should_offer_completions_for_flags_or_options -a expected_commands
  2. set -l non_repeating_flags_or_options $argv[2..]
  3. set -l non_repeating_flags_or_options_absent 0
  4. set -l positional_index 0
  5. set -l commands
  6. __math_parse_tokens
  7. test "$commands" = "$expected_commands"; and return $non_repeating_flags_or_options_absent
  8. end
  9. function __math_should_offer_completions_for_positional -a expected_commands expected_positional_index positional_index_comparison
  10. if test -z $positional_index_comparison
  11. set positional_index_comparison -eq
  12. end
  13. set -l non_repeating_flags_or_options
  14. set -l non_repeating_flags_or_options_absent 0
  15. set -l positional_index 0
  16. set -l commands
  17. __math_parse_tokens
  18. test "$commands" = "$expected_commands" -a \( "$positional_index" "$positional_index_comparison" "$expected_positional_index" \)
  19. end
  20. function __math_parse_tokens -S
  21. set -l unparsed_tokens (__math_tokens -pc)
  22. set -l present_flags_and_options
  23. switch $unparsed_tokens[1]
  24. case 'math'
  25. __math_parse_subcommand 0 'version' 'h/help'
  26. switch $unparsed_tokens[1]
  27. case 'add'
  28. __math_parse_subcommand -r 1 'x/hex-output' 'version' 'h/help'
  29. case 'multiply'
  30. __math_parse_subcommand -r 1 'x/hex-output' 'version' 'h/help'
  31. case 'stats'
  32. __math_parse_subcommand 0 'version' 'h/help'
  33. switch $unparsed_tokens[1]
  34. case 'average'
  35. __math_parse_subcommand -r 1 'kind=' 'version' 'h/help'
  36. case 'stdev'
  37. __math_parse_subcommand -r 1 'version' 'h/help'
  38. case 'quantiles'
  39. __math_parse_subcommand -r 4 'file=' 'directory=' 'shell=' 'custom=' 'custom-deprecated=' 'version' 'h/help'
  40. end
  41. case 'help'
  42. __math_parse_subcommand -r 1 'version'
  43. end
  44. end
  45. end
  46. function __math_tokens
  47. if test (string split -m 1 -f 1 -- . "$FISH_VERSION") -gt 3
  48. commandline --tokens-raw $argv
  49. else
  50. commandline -o $argv
  51. end
  52. end
  53. function __math_parse_subcommand -S -a positional_count
  54. argparse -s r -- $argv
  55. set -l option_specs $argv[2..]
  56. set -a commands $unparsed_tokens[1]
  57. set -e unparsed_tokens[1]
  58. set positional_index 0
  59. while true
  60. argparse -sn "$commands" $option_specs -- $unparsed_tokens 2> /dev/null
  61. set unparsed_tokens $argv
  62. set positional_index (math $positional_index + 1)
  63. for non_repeating_flag_or_option in $non_repeating_flags_or_options
  64. if set -ql _flag_$non_repeating_flag_or_option
  65. set non_repeating_flags_or_options_absent 1
  66. break
  67. end
  68. end
  69. if test (count $unparsed_tokens) -eq 0 -o \( -z "$_flag_r" -a "$positional_index" -gt "$positional_count" \)
  70. break
  71. end
  72. set -e unparsed_tokens[1]
  73. end
  74. end
  75. function __math_complete_directories
  76. set -l token (commandline -t)
  77. string match -- '*/' $token
  78. set -l subdirs $token*/
  79. printf '%s\n' $subdirs
  80. end
  81. function __math_custom_completion
  82. set -x SAP_SHELL fish
  83. set -x SAP_SHELL_VERSION $FISH_VERSION
  84. set -l tokens (__math_tokens -p)
  85. if test -z (__math_tokens -t)
  86. set -l index (count (__math_tokens -pc))
  87. set tokens $tokens[..$index] \'\' $tokens[(math $index + 1)..]
  88. end
  89. command $tokens[1] $argv $tokens
  90. end
  91. complete -c 'math' -f
  92. complete -c 'math' -n '__math_should_offer_completions_for_flags_or_options "math" version' -l 'version' -d 'Show the version.'
  93. complete -c 'math' -n '__math_should_offer_completions_for_flags_or_options "math" h help' -s 'h' -l 'help' -d 'Show help information.'
  94. complete -c 'math' -n '__math_should_offer_completions_for_positional "math" 1' -fa 'add' -d 'Print the sum of the values.'
  95. complete -c 'math' -n '__math_should_offer_completions_for_positional "math" 1' -fa 'multiply' -d 'Print the product of the values.'
  96. complete -c 'math' -n '__math_should_offer_completions_for_positional "math" 1' -fa 'stats' -d 'Calculate descriptive statistics.'
  97. complete -c 'math' -n '__math_should_offer_completions_for_positional "math" 1' -fa 'help' -d 'Show subcommand help information.'
  98. complete -c 'math' -n '__math_should_offer_completions_for_flags_or_options "math add" hex-output x' -l 'hex-output' -s 'x' -d 'Use hexadecimal notation for the result.'
  99. complete -c 'math' -n '__math_should_offer_completions_for_flags_or_options "math add" version' -l 'version' -d 'Show the version.'
  100. complete -c 'math' -n '__math_should_offer_completions_for_flags_or_options "math add" h help' -s 'h' -l 'help' -d 'Show help information.'
  101. complete -c 'math' -n '__math_should_offer_completions_for_flags_or_options "math multiply" hex-output x' -l 'hex-output' -s 'x' -d 'Use hexadecimal notation for the result.'
  102. complete -c 'math' -n '__math_should_offer_completions_for_flags_or_options "math multiply" version' -l 'version' -d 'Show the version.'
  103. complete -c 'math' -n '__math_should_offer_completions_for_flags_or_options "math multiply" h help' -s 'h' -l 'help' -d 'Show help information.'
  104. complete -c 'math' -n '__math_should_offer_completions_for_flags_or_options "math stats" version' -l 'version' -d 'Show the version.'
  105. complete -c 'math' -n '__math_should_offer_completions_for_flags_or_options "math stats" h help' -s 'h' -l 'help' -d 'Show help information.'
  106. complete -c 'math' -n '__math_should_offer_completions_for_positional "math stats" 1' -fa 'average' -d 'Print the average of the values.'
  107. complete -c 'math' -n '__math_should_offer_completions_for_positional "math stats" 1' -fa 'stdev' -d 'Print the standard deviation of the values.'
  108. complete -c 'math' -n '__math_should_offer_completions_for_positional "math stats" 1' -fa 'quantiles' -d 'Print the quantiles of the values (TBD).'
  109. complete -c 'math' -n '__math_should_offer_completions_for_flags_or_options "math stats average" kind' -l 'kind' -d 'The kind of average to provide.' -rfka 'mean median mode'
  110. complete -c 'math' -n '__math_should_offer_completions_for_flags_or_options "math stats average" version' -l 'version' -d 'Show the version.'
  111. complete -c 'math' -n '__math_should_offer_completions_for_flags_or_options "math stats average" h help' -s 'h' -l 'help' -d 'Show help information.'
  112. complete -c 'math' -n '__math_should_offer_completions_for_flags_or_options "math stats stdev" version' -l 'version' -d 'Show the version.'
  113. complete -c 'math' -n '__math_should_offer_completions_for_flags_or_options "math stats stdev" h help' -s 'h' -l 'help' -d 'Show help information.'
  114. complete -c 'math' -n '__math_should_offer_completions_for_positional "math stats quantiles" 1' -fka 'alphabet alligator branch braggart'
  115. complete -c 'math' -n '__math_should_offer_completions_for_positional "math stats quantiles" 2' -fka '(__math_custom_completion ---completion stats quantiles -- positional@1 (count (__math_tokens -pc)) (__math_tokens -tC))'
  116. complete -c 'math' -n '__math_should_offer_completions_for_positional "math stats quantiles" 3' -fka '(__math_custom_completion ---completion stats quantiles -- positional@2)'
  117. complete -c 'math' -n '__math_should_offer_completions_for_flags_or_options "math stats quantiles" file' -l 'file' -rfa '(set -l exts \'txt\' \'md\';for p in (string match -e -- \'*/\' (commandline -t);or printf \n)*.{$exts};printf %s\n $p;end;__fish_complete_directories (commandline -t) \'\')'
  118. complete -c 'math' -n '__math_should_offer_completions_for_flags_or_options "math stats quantiles" directory' -l 'directory' -rfa '(__math_complete_directories)'
  119. complete -c 'math' -n '__math_should_offer_completions_for_flags_or_options "math stats quantiles" shell' -l 'shell' -rfka '(head -100 \'/usr/share/dict/words\' | tail -50)'
  120. complete -c 'math' -n '__math_should_offer_completions_for_flags_or_options "math stats quantiles" custom' -l 'custom' -rfka '(__math_custom_completion ---completion stats quantiles -- --custom (count (__math_tokens -pc)) (__math_tokens -tC))'
  121. complete -c 'math' -n '__math_should_offer_completions_for_flags_or_options "math stats quantiles" custom-deprecated' -l 'custom-deprecated' -rfka '(__math_custom_completion ---completion stats quantiles -- --custom-deprecated)'
  122. complete -c 'math' -n '__math_should_offer_completions_for_flags_or_options "math stats quantiles" version' -l 'version' -d 'Show the version.'
  123. complete -c 'math' -n '__math_should_offer_completions_for_flags_or_options "math stats quantiles" h help' -s 'h' -l 'help' -d 'Show help information.'
  124. complete -c 'math' -n '__math_should_offer_completions_for_flags_or_options "math help" version' -l 'version' -d 'Show the version.'