Content-Length: 341197 | pFad | http://github.com/kerl/kerl/commit/47c1a3721fc3dad1c6dd9623068a3967628fcfe0

17 Add fish shell completion support (#543) · kerl/kerl@47c1a37 · GitHub
Skip to content

Commit

Permalink
Add fish shell completion support (#543)
Browse files Browse the repository at this point in the history
* Add fish shell completion support

* Add directory completion for build-install subcommand

* fix typo

Co-authored-by: Paulo F. Oliveira <paulo.ferraz.oliveira@gmail.com>

* improve command-line completion instructions

---------

Co-authored-by: Paulo F. Oliveira <paulo.ferraz.oliveira@gmail.com>
  • Loading branch information
Bryan2333 and paulo-ferraz-oliveira authored Aug 24, 2024
1 parent a7c3074 commit 47c1a37
Show file tree
Hide file tree
Showing 2 changed files with 149 additions and 6 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -914,15 +914,15 @@ Deactivation is the same as in other shells:
$ kerl_deactivate
```

### Bash
### Command-line completion

Bash completion is available from
<https://github.com/kerl/kerl/raw/master/bash_completion/kerl>.
Optionally, download and install `kerl`'s:

### Zsh
- `bash_completion` file from <https://github.com/kerl/kerl/raw/master/bash_completion/kerl>
- `zsh_completion` file from <https://github.com/kerl/kerl/raw/master/zsh_completion/_kerl>
- `fish-completion` file from <https://github.com/kerl/kerl/raw/master/fish_completion/kerl.fish>

Zsh completion is available from
<https://github.com/kerl/kerl/raw/master/zsh_completion/_kerl>.
depending on your preferred shell.

## The `kerl` glossary

Expand Down
143 changes: 143 additions & 0 deletions fish_completion/kerl.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
# Completion for kerl (https://github.com/kerl/kerl)

if ! set -q KERL_BASE_DIR
set KERL_BASE_DIR $HOME/.kerl
end

set -l kerl_args build install build-install deploy update list delete path active plt status prompt cleanup emit-activate upgrade version
set -l kerl_list_args releases builds installations
set -l kerl_delete_args installation build

function kerl_otp_releases
set -l file $KERL_BASE_DIR/otp_releases
test -f $file && cat $file
end

function kerl_otp_builds
set -l file $KERL_BASE_DIR/otp_builds
test -f $file && cat $file | cut -f 2 -d ","
end

function kerl_otp_installations_names
set -l file $KERL_BASE_DIR/otp_installations
test -f $file && cat $file | cut -f 2 -d " "
end

function kerl_otp_installations_directories
set -l file $KERL_BASE_DIR/otp_installations
test -f $file && cat $file | cut -f 2 -d " " | xargs basename
end

function kerl_build_complete
set -l cmd (commandline -poc)

if test (count $cmd) -ge 3
return 1
end

if test $cmd[2] = "build" && ! contains "delete" $cmd
echo "git" && kerl_otp_releases
end
end

function kerl_deploy_complete
set -l cmd (commandline -poc)
set -l arg_index (count $cmd)

switch $arg_index
case 2
__fish_print_hostnames | uniq
case 3
kerl_otp_installations_names
case '*'
return 1
end
end

function kerl_delete_complete
set -l cmd (commandline -poc)
set -l arg_index (count $cmd)

switch $arg_index
case 2
printf "%s\t%s\n" build "Delete a specific build"
printf "%s\t%s\n" installation "Delete a specific installation"
case 3
if test $cmd[$arg_index] = "build"
kerl_otp_builds
else if test $cmd[$arg_index] = "installation"
kerl_otp_installations_names
end
case '*'
return 1
end
end

function kerl_emit_activate_complete
set -l cmd (commandline -poc)
set -l arg_index (count $cmd)

switch $arg_index
case 2
kerl_otp_releases
case 3
kerl_otp_builds
case 4
kerl_otp_installations_names
case 5
printf "%s\n%s\n%s\n%s" sh bash fish csh
end
end

complete -c kerl -f
complete -c kerl -n "not __fish_seen_subcommand_from $kerl_args" -a build -d "Build specified release or git repository"
complete -c kerl -n "not __fish_seen_subcommand_from $kerl_args" -a install -d "Install the specified release at the given location"
complete -c kerl -n "not __fish_seen_subcommand_from $kerl_args" -a build-install -d "Builds and installs the specified release or git repository at the given location"
complete -c kerl -n "not __fish_seen_subcommand_from $kerl_args" -a deploy -d "Deploy the specified installation to the given host and location"
complete -c kerl -n "not __fish_seen_subcommand_from $kerl_args" -a update -d "Update the list of available releases from your source provider"
complete -c kerl -n "not __fish_seen_subcommand_from $kerl_args" -a list -d "List releases, builds and installations"
complete -c kerl -n "not __fish_seen_subcommand_from $kerl_args" -a delete -d "Delete builds and installations"
complete -c kerl -n "not __fish_seen_subcommand_from $kerl_args" -a path -d "Print the path of a given installation"
complete -c kerl -n "not __fish_seen_subcommand_from $kerl_args" -a active -d "Print the path of the active installation"
complete -c kerl -n "not __fish_seen_subcommand_from $kerl_args" -a plt -d "Print Dialyzer PLT path for the active installation"
complete -c kerl -n "not __fish_seen_subcommand_from $kerl_args" -a status -d "Print available builds and installations"
complete -c kerl -n "not __fish_seen_subcommand_from $kerl_args" -a prompt -d "Print a string suitable for insertion in prompt"
complete -c kerl -n "not __fish_seen_subcommand_from $kerl_args" -a cleanup -d "Remove compilation artifacts (use after installation)"
complete -c kerl -n "not __fish_seen_subcommand_from $kerl_args" -a emit-activate -d "Print the activate script"
complete -c kerl -n "not __fish_seen_subcommand_from $kerl_args" -a upgrade -d "Fetch and install the most recent kerl release"
complete -c kerl -n "not __fish_seen_subcommand_from $kerl_args" -a version -d "Print current version"


## build subcommand
complete -c kerl -n "__fish_seen_subcommand_from build" -a "(kerl_build_complete)"

## install command
complete -c kerl -n "__fish_seen_subcommand_from install && not __fish_seen_argument (kerl_otp_builds)" -a "(kerl_otp_builds)"
complete -c kerl -n "__fish_seen_subcommand_from install && __fish_seen_argument (kerl_otp_builds)" -a "(__fish_complete_directories)"

## build-install subcommand
complete -c kerl -n "__fish_seen_subcommand_from build-install && not __fish_seen_argument git (kerl_otp_releases)" -a "git (kerl_otp_releases)"
complete -c kerl -n "__fish_seen_subcommand_from build-install && __fish_seen_argument git (kerl_otp_releases)" -a "(__fish_complete_directories)"

## deploy subcommand
complete -c kerl -n "__fish_seen_subcommand_from deploy" -a "(kerl_deploy_complete)"

## update subcommand
complete -c kerl -n "__fish_seen_subcommand_from update && not __fish_seen_argument releases" -a "releases" -d "All available OTP releases"

## list subcommand
complete -c kerl -n "__fish_seen_subcommand_from list && not __fish_seen_argument $kerl_list_args" -a releases -d "Available OTP releases"
complete -c kerl -n "__fish_seen_subcommand_from list && not __fish_seen_argument $kerl_list_args" -a builds -d "All locally built OTP releases"
complete -c kerl -n "__fish_seen_subcommand_from list && not __fish_seen_argument $kerl_list_args" -a installations -d "All locally installed OTP builds"

## delete subcommand
complete -c kerl -n "__fish_seen_subcommand_from delete" -a "(kerl_delete_complete)"

## path subcommand
complete -c kerl -n "__fish_seen_subcommand_from path && not __fish_seen_argument (kerl_otp_installations_directories)" -a "(kerl_otp_installations_directories)"

## cleanup subcommand
complete -c kerl -n "__fish_seen_subcommand_from cleanup && not __fish_seen_argument all (kerl_otp_builds)" -a "all (kerl_otp_builds)"

## emit-activate
complete -c kerl -n '__fish_seen_subcommand_from emit-activate' -a "(kerl_emit_activate_complete)"

0 comments on commit 47c1a37

Please sign in to comment.








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/kerl/kerl/commit/47c1a3721fc3dad1c6dd9623068a3967628fcfe0

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy