Skip to content

Commit

Permalink
Merge pull request #96 from rsteube/stringslice-support
Browse files Browse the repository at this point in the history
Stringslice support
  • Loading branch information
rsteube authored Oct 5, 2020
2 parents d7719af + f88f5c8 commit cf8f916
Show file tree
Hide file tree
Showing 21 changed files with 704 additions and 1,029 deletions.
4 changes: 4 additions & 0 deletions Dockerfile.bash
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
FROM golang

RUN apt-get update \
&& apt-get install -y bash-completion

RUN echo "\n\
PS1=$'\e[0;36mcarapace \e[0m'\n\
source /usr/share/bash-completion/bash_completion \n\
source <(example _carapace bash)" \
> /root/.bashrc

Expand Down
3 changes: 2 additions & 1 deletion Dockerfile.oil
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM golang

RUN apt-get update \
&& apt install -y build-essential libreadline-dev
&& apt install -y build-essential libreadline-dev bash-completion

RUN curl https://www.oilshell.org/download/oil-0.8.0.tar.gz | tar -xvz \
&& cd oil-*/ \
Expand All @@ -12,6 +12,7 @@ RUN curl https://www.oilshell.org/download/oil-0.8.0.tar.gz | tar -xvz \
RUN mkdir -p ~/.config/oil \
&& echo "\n\
PS1=$'\e[0;36mcarapace \e[0m'\n\
source /usr/share/bash-completion/bash_completion \n\
source <(example _carapace bash)" \
> ~/.config/oil/oshrc

Expand Down
36 changes: 14 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ Uids are generated to identify corresponding completions:


## Action
An [action](#action) indicates how to complete a flag or a positional argument. See [action.go](./action.go) and the examples below for current implementations.
An [action](#action) indicates how to complete a flag or a positional argument. See [action.go](./action.go) and the examples below for current implementations. A range of custom actions can be found at [rsteube/carapace-bin](https://github.com/rsteube/carapace-bin/tree/master/actions)

### ActionMessage

Expand Down Expand Up @@ -135,32 +135,24 @@ Since callbacks are simply invocations of the program they can be tested directl

### ActionMultiParts

> This is an initial version which still got some quirks, expect some changes here (in the long term this shall return Action as well)
ActionMultiParts is a [callback action](#actioncallback) where parts of an argument can be completed separately (e.g. user:group from [chown](https://github.com/rsteube/carapace-completers/blob/master/completers/chown_completer/cmd/root.go)). Divider can be empty as well, but note that `bash` and `fish` will add the space suffix for anything other than `/=@:.,` (it still works, but after each selection backspace is needed to continue the completion).

```go
carapace.ActionMultiParts(":", func(args []string, parts []string) []string {
switch len(parts) {
case 0:
return []{"user1:", "user2:", "user3:"}
case 1:
return []{"groupA", "groupB", "groupC"}
default:
return []string{}
}
})
func ActionUserGroup() carapace.Action {
return carapace.ActionMultiParts(":", func(args []string, parts []string) carapace.Action {
switch len(parts) {
case 0:
return ActionUsers().Suffix(":", args)
case 1:
return ActionGroups()
default:
return carapace.ActionValues()
}
})
}
```

### Custom Action

For [actions](#action) that aren't implemented or missing required options, a custom action can be defined.

```go
carapace.Action{Zsh: "_most_recent_file 2"}

// #./example action --custom <TAB>
```
### Shell Completion Documentation

Additional information can be found at:
- Bash: [bash-programmable-completion-tutorial](https://iridakos.com/programming/2018/03/01/bash-programmable-completion-tutorial) and [Programmable-Completion-Builtins](https://www.gnu.org/software/bash/manual/html_node/Programmable-Completion-Builtins.html#Programmable-Completion-Builtins)
Expand Down
Loading

0 comments on commit cf8f916

Please sign in to comment.