Skip to content
This repository was archived by the owner on Apr 5, 2025. It is now read-only.

Commit 3e61bab

Browse files
Merge pull request #9 from xb-bx/main
More completion scripts
2 parents be8683f + 1ca4b8a commit 3e61bab

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
lines changed

readme.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ Usage: --text <text>
8484
Arguments:
8585
--text, -t <text> The text to display
8686
```
87+
## Tab Completion
88+
### Powershell
8789

8890
To enable completion in powershell, execute the following line:
8991
```
@@ -92,6 +94,14 @@ hello completion powershell | out-string | invoke-expression
9294
This line can be added to the $Profile.CurrentUserAllHost file to enable completion for every new session.
9395

9496
Now, type `hello` followed by a space, and press tab or Ctrl+Space. The arguments are suggested.
97+
### Bash
98+
```bash
99+
hello completion bash >> ~/.bashrc
100+
```
101+
### Fish
102+
```fish
103+
hello completion fish > ~/.config/fish/completions/hello.fish
104+
```
95105

96106
## Arg<'t>
97107

src/Fargo/Fargo.fs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,7 @@ module Run =
658658
printDescription usages
659659
printOptions usages.Options
660660

661-
type Shell = Powershell
661+
type Shell = Powershell | Fish | Bash
662662

663663
let printCompletion appName shell =
664664
match shell with
@@ -671,6 +671,26 @@ Register-ArgumentCompleter -Native -CommandName %s -ScriptBlock {
671671
}
672672
}
673673
""" appName appName
674+
| Fish ->
675+
printfn """
676+
function __%s_completion
677+
set -l count (commandline -pC)
678+
set -l cmd (commandline -opc)
679+
%s complete --position (math $count - (string length $cmd[1])) - 1 "$cmd[2..]"
680+
end
681+
complete -f -c %s -a '(__%s_completion)'
682+
""" appName appName appName appName
683+
| Bash ->
684+
printfn """
685+
__%s_completion()
686+
{
687+
local words=${COMP_WORDS[@]:1}
688+
local first_len=${#COMP_WORDS[0]}
689+
local point=$(( $COMP_POINT - $first_len - 1 ))
690+
COMPREPLY=( $(compgen -W "$(%s complete --position $point ${words[*]})") )
691+
}
692+
complete -F __%s_completion %s
693+
""" appName appName appName appName
674694

675695

676696
type TopCmd = CompleteCmd | CompletionCmd | RunCmd
@@ -692,7 +712,7 @@ Register-ArgumentCompleter -Native -CommandName %s -ScriptBlock {
692712
|> defaultValue Int32.MaxValue
693713

694714
let pShell =
695-
let shells = Map.ofList [ "powershell", Powershell ]
715+
let shells = Map.ofList [ "powershell", Powershell; "fish", Fish; "bash", Bash ]
696716
argc "shell" "the shell for which to emit the script" (Completer.choices (shells |> Map.toList |> List.map fst) )
697717
|> reqArg
698718
|> parse (fun shell ->

src/Fargo/Fargo.fsi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ module Run =
179179
val printOptions: Usage list -> unit
180180
val printHelp: Usages -> unit
181181

182-
type Shell = Powershell
182+
type Shell = Powershell | Fish | Bash
183183

184184
val printCompletion: appName:string -> shell:Shell -> unit
185185

0 commit comments

Comments
 (0)