@hardfin/cli 0.1.0-dev.20 → 0.1.0-dev.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +85 -16
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -1056,31 +1056,100 @@ async function runCompletion(input) {
|
|
|
1056
1056
|
}
|
|
1057
1057
|
/** toScript writes a shell's completion, each one asking __complete for the candidates. */
|
|
1058
1058
|
function toScript(shell) {
|
|
1059
|
-
|
|
1059
|
+
return SCRIPTS[shell];
|
|
1060
|
+
}
|
|
1061
|
+
const SCRIPTS = {
|
|
1062
|
+
bash: `# hardfin completion for bash
|
|
1063
|
+
_hardfin_words() {
|
|
1064
|
+
# Bash splits a word at = and :, so the pieces are joined again wherever no space
|
|
1065
|
+
# separates them in the line, and the word under the cursor ends at the cursor.
|
|
1066
|
+
local line=\${COMP_LINE:0:COMP_POINT} offset=0 i word rest gap
|
|
1067
|
+
_hardfin_line_words=()
|
|
1068
|
+
|
|
1069
|
+
for ((i = 0; i <= COMP_CWORD; i++)); do
|
|
1070
|
+
rest=\${line:offset}
|
|
1071
|
+
|
|
1072
|
+
if ((i < COMP_CWORD)); then
|
|
1073
|
+
word=\${COMP_WORDS[i]}
|
|
1074
|
+
gap=\${rest%%"$word"*}
|
|
1075
|
+
offset=$((offset + \${#gap} + \${#word}))
|
|
1076
|
+
else
|
|
1077
|
+
word=\${rest#"\${rest%%[![:space:]]*}"}
|
|
1078
|
+
gap=\${rest%"$word"}
|
|
1079
|
+
fi
|
|
1080
|
+
|
|
1081
|
+
if ((i > 0)) && [[ -z $gap ]]; then
|
|
1082
|
+
_hardfin_line_words[\${#_hardfin_line_words[@]} - 1]+=$word
|
|
1083
|
+
else
|
|
1084
|
+
_hardfin_line_words+=("$word")
|
|
1085
|
+
fi
|
|
1086
|
+
done
|
|
1087
|
+
}
|
|
1088
|
+
|
|
1060
1089
|
_hardfin_complete() {
|
|
1061
|
-
local
|
|
1062
|
-
|
|
1063
|
-
COMPREPLY=(
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1090
|
+
local _hardfin_line_words candidate current prefix breaks
|
|
1091
|
+
_hardfin_words
|
|
1092
|
+
COMPREPLY=()
|
|
1093
|
+
|
|
1094
|
+
while IFS= read -r candidate; do
|
|
1095
|
+
COMPREPLY+=("$candidate")
|
|
1096
|
+
done < <(hardfin __complete -- "\${_hardfin_line_words[@]:1}" 2>/dev/null)
|
|
1097
|
+
|
|
1098
|
+
# Readline replaces only the text after the last = or : in the word, so a candidate
|
|
1099
|
+
# loses what comes before it or the line would repeat that part.
|
|
1100
|
+
current=\${_hardfin_line_words[\${#_hardfin_line_words[@]} - 1]}
|
|
1101
|
+
breaks=\${COMP_WORDBREAKS//[^=:]/}
|
|
1102
|
+
|
|
1103
|
+
if [[ -n $breaks && $current == *["$breaks"]* ]]; then
|
|
1104
|
+
prefix=\${current%"\${current##*["$breaks"]}"}
|
|
1105
|
+
COMPREPLY=("\${COMPREPLY[@]#"$prefix"}")
|
|
1106
|
+
fi
|
|
1107
|
+
}
|
|
1108
|
+
|
|
1109
|
+
complete -F _hardfin_complete hardfin`,
|
|
1110
|
+
zsh: `# hardfin completion for zsh
|
|
1067
1111
|
_hardfin_complete() {
|
|
1068
1112
|
local -a candidates
|
|
1069
|
-
candidates=(\${(f)"$(hardfin __complete -- \${words[2
|
|
1113
|
+
candidates=(\${(f)"$(hardfin __complete -- "\${(@)words[2,CURRENT]}" 2>/dev/null)"})
|
|
1070
1114
|
compadd -a candidates
|
|
1071
1115
|
}
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1116
|
+
|
|
1117
|
+
compdef _hardfin_complete hardfin`,
|
|
1118
|
+
fish: `# hardfin completion for fish
|
|
1119
|
+
function __hardfin_complete
|
|
1120
|
+
# Older fish lacks -x, which replaced -o, so it falls back to the older option.
|
|
1121
|
+
set -l words (commandline -xpc 2>/dev/null; or commandline -opc)
|
|
1122
|
+
set -l current (commandline -ct)
|
|
1123
|
+
hardfin __complete -- $words[2..-1] "$current" 2>/dev/null
|
|
1124
|
+
end
|
|
1125
|
+
|
|
1126
|
+
complete -c hardfin -f -a "(__hardfin_complete)"`,
|
|
1127
|
+
powershell: `# hardfin completion for PowerShell
|
|
1076
1128
|
Register-ArgumentCompleter -Native -CommandName hardfin -ScriptBlock {
|
|
1077
1129
|
param($wordToComplete, $commandAst, $cursorPosition)
|
|
1078
|
-
|
|
1130
|
+
|
|
1131
|
+
# Only the words before the cursor decide what is offered, and PowerShell leaves out the
|
|
1132
|
+
# empty word after a trailing space, so it is added back.
|
|
1133
|
+
$words = @($commandAst.CommandElements | Select-Object -Skip 1 | Where-Object { $_.Extent.StartOffset -lt $cursorPosition } | ForEach-Object { $_.Extent.Text })
|
|
1134
|
+
|
|
1135
|
+
if ($wordToComplete -eq '') {
|
|
1136
|
+
# Before 7.3, and in Legacy mode, an empty argument never reaches the program unless
|
|
1137
|
+
# it is written as a pair of quotes.
|
|
1138
|
+
$isLegacy = $PSVersionTable.PSVersion -lt [version]'7.3' -or $PSNativeCommandArgumentPassing -eq 'Legacy'
|
|
1139
|
+
$words += if ($isLegacy) { '""' } else { '' }
|
|
1140
|
+
}
|
|
1141
|
+
|
|
1079
1142
|
hardfin __complete -- @words 2>$null | ForEach-Object {
|
|
1080
|
-
|
|
1143
|
+
$text = $_
|
|
1144
|
+
|
|
1145
|
+
if ($text -match '[\\s#@$;,''{}()"\`|<>&]') {
|
|
1146
|
+
$text = "'" + ($text -replace "'", "''") + "'"
|
|
1147
|
+
}
|
|
1148
|
+
|
|
1149
|
+
[System.Management.Automation.CompletionResult]::new($text, $_, 'ParameterValue', $_)
|
|
1081
1150
|
}
|
|
1082
|
-
}
|
|
1083
|
-
}
|
|
1151
|
+
}`
|
|
1152
|
+
};
|
|
1084
1153
|
//#endregion
|
|
1085
1154
|
//#region src/command/config.ts
|
|
1086
1155
|
const configCommand = defineCommand({
|