Skip to content

Commit

Permalink
Convert --generate-completion flag to subcommand and add docs/tests (
Browse files Browse the repository at this point in the history
…#22)

- Add documention
- Add tests
- Fix github action
  • Loading branch information
JamyGolden authored Apr 29, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 9f9346f commit 8df5a2e
Showing 14 changed files with 454 additions and 38 deletions.
6 changes: 1 addition & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -178,11 +178,7 @@ jobs:
run: |
files="example.toml THIRD_PARTY_LICENSES.md LICENSE README.md"
$GITHUB_WORKSPACE/scripts/package_build \
"example.toml THIRD_PARTY_LICENSES.md LICENSE README.md" \
"contrib/completion/tinty.bash" \
"contrib/completion/tinty.zsh" \
"contrib/completion/tinty.fish" \
"contrib/completion/tinty.ps1" \
"example.toml THIRD_PARTY_LICENSES.md LICENSE README.md contrib/completion/tinty.bash contrib/completion/tinty.elvish contrib/completion/tinty.fish contrib/completion/tinty.powershell contrib/completion/tinty.zsh" \
"${{ matrix.target }}" \
"$GITHUB_WORKSPACE" \
"${{ steps.cargo_version.outputs.value }}"
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## [Unreleased]

### Added

- Add shell completions functionality with `generate-completion`
subcommand

## [0.11.0] - 2024-03-10

### Added
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -162,6 +162,7 @@ The following is a table of the available subcommands for the CLI tool (Tinty),
| `init` | Initializes the tool with the last applied theme otherwise `default-scheme` from `config.toml`. | - | `tinty init` |
| `current` | Displays the currently applied theme. | - | `tinty current` |
| `info` | Provides information about themes. | `[<scheme_system>-<scheme_name>]`: Optional argument to specify a theme for detailed info. | `tinty info base16-mocha` |
| `generate-completion` | Generates a shell completion file to source in your shell startup file (`*rc`). | `<shell_name>`: Name of the shell to generate a completion script for. Supports `bash`, `elvish`, `fish`, `powershell`, `zsh` | `tinty generate-completion bash` |

Some subcommands support additional flags and options to modify their behavior:

18 changes: 18 additions & 0 deletions USAGE.md
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@ For more general usage, look at the [Usage section] in [README.md].

## Table of contents

- [Shell completions](#shell-completions)
- [How it works](#how-it-works)
- [Sourcing scripts that set environment variables](#sourcing-scripts-that-set-environment-variables)
- [shell](#shell)
@@ -13,6 +14,21 @@ For more general usage, look at the [Usage section] in [README.md].
- [fzf](#fzf)
- [bat](#bat)

## Shell completions

You can generate shell completions with the `generate-completion`
subcommand, source the generated file in your shell startup file (`*rc`)
and completions will exist for `tinty`. Have a look at the [README CLI
section] for more information about the command usage.

A shell completion generation via `tinty` doesn't include any dynamic
values, meaning scheme names (such as `base16-ocean`) won't be completed
typing `tinty apply base`. We've created modified completion script
files for this reason so it can also generate the scheme names.
Currently this is only supported for the `bash` completion file, but we
plan to include the other shells too. You can find these completion
files in [contrib/completion].

## How it works

There are some concepts which some of the following instructions will
@@ -371,3 +387,5 @@ alias bat="bat --theme='base16-256'"
[tmux tpm]: https://github.com/tmux-plugins/tpm
[XDG Base Directory specification]: https://wiki.archlinux.org/title/XDG_Base_Directory
[Sourcing scripts that set environment variables]: #sourcing-scripts-that-set-environment-variables
[README CLI section]: README.md#cli
[contrib/completion]: contrib/completion
12 changes: 12 additions & 0 deletions contrib/completion/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Shell Completions

Run `tinty generate-completion <bash|elvish|fish|powershell|zsh>` to
generate a shell completion script for your shell of choice. Make sure
to source the generated script in your shell startup file (`*rc`).

The files in this directory are custom completion scripts which has been
optimised further than the standard completions `tinty` generates. These
scripts complete dynamic values (scheme names) as well as the standard
subcommands and flags. Currently `bash` is the completion which has been
optimised this way, the rest are the default completions generated by
`tinty generate-completion <shell_name>`.
58 changes: 52 additions & 6 deletions contrib/completion/tinty.bash
Original file line number Diff line number Diff line change
@@ -18,6 +18,9 @@ _tinty() {
tinty,current)
cmd="tinty__current"
;;
tinty,generate-completion)
cmd="tinty__generate__completion"
;;
tinty,help)
cmd="tinty__help"
;;
@@ -42,6 +45,9 @@ _tinty() {
tinty__help,current)
cmd="tinty__help__current"
;;
tinty__help,generate-completion)
cmd="tinty__help__generate__completion"
;;
tinty__help,help)
cmd="tinty__help__help"
;;
@@ -67,7 +73,7 @@ _tinty() {

case "${cmd}" in
tinty)
opts="-c -d -h -V --config --data-dir --generate-completion --help --version current info init list apply install update help"
opts="-c -d -h -V --config --data-dir --help --version current generate-completion info init list apply install update help"
if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
@@ -89,10 +95,6 @@ _tinty() {
COMPREPLY=($(compgen -f "${cur}"))
return 0
;;
--generate-completion)
COMPREPLY=($(compgen -W "bash elvish fish powershell zsh" -- "${cur}"))
return 0
;;
*)
COMPREPLY=()
;;
@@ -164,8 +166,38 @@ _tinty() {
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
;;
tinty__generate__completion)
opts="-c -d -h --config --data-dir --help bash elvish fish powershell zsh"
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
fi
case "${prev}" in
--config)
COMPREPLY=($(compgen -f "${cur}"))
return 0
;;
-c)
COMPREPLY=($(compgen -f "${cur}"))
return 0
;;
--data-dir)
COMPREPLY=($(compgen -f "${cur}"))
return 0
;;
-d)
COMPREPLY=($(compgen -f "${cur}"))
return 0
;;
*)
COMPREPLY=()
;;
esac
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
;;
tinty__help)
opts="current info init list apply install update help"
opts="current generate-completion info init list apply install update help"
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
@@ -206,6 +238,20 @@ _tinty() {
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
;;
tinty__help__generate__completion)
opts=""
if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
fi
case "${prev}" in
*)
COMPREPLY=()
;;
esac
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
;;
tinty__help__help)
opts=""
if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then
134 changes: 134 additions & 0 deletions contrib/completion/tinty.elvish
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@

use builtin;
use str;

set edit:completion:arg-completer[tinty] = {|@words|
fn spaces {|n|
builtin:repeat $n ' ' | str:join ''
}
fn cand {|text desc|
edit:complex-candidate $text &display=$text' '(spaces (- 14 (wcswidth $text)))$desc
}
var command = 'tinty'
for word $words[1..-1] {
if (str:has-prefix $word '-') {
break
}
set command = $command';'$word
}
var completions = [
&'tinty'= {
cand -c 'Optional path to the tinty config.toml file'
cand --config 'Optional path to the tinty config.toml file'
cand -d 'Optional path to the tinty data directory'
cand --data-dir 'Optional path to the tinty data directory'
cand -h 'Print help'
cand --help 'Print help'
cand -V 'Print version'
cand --version 'Print version'
cand current 'Prints the last scheme name applied'
cand generate-completion 'Generates a shell completion script'
cand info 'Shows scheme colors for all schemes matching <scheme_system>-<scheme_name> (Eg: tinty info base16-mocha)'
cand init 'Initializes with the exising config. Used to Initialize exising theme for when your shell starts up'
cand list 'Lists available schemes'
cand apply 'Applies a theme based on the chosen scheme'
cand install 'Install the environment needed for tinty'
cand update 'Update to the latest themes'
cand help 'Print this message or the help of the given subcommand(s)'
}
&'tinty;current'= {
cand -c 'Optional path to the tinty config.toml file'
cand --config 'Optional path to the tinty config.toml file'
cand -d 'Optional path to the tinty data directory'
cand --data-dir 'Optional path to the tinty data directory'
cand -h 'Print help'
cand --help 'Print help'
}
&'tinty;generate-completion'= {
cand -c 'Optional path to the tinty config.toml file'
cand --config 'Optional path to the tinty config.toml file'
cand -d 'Optional path to the tinty data directory'
cand --data-dir 'Optional path to the tinty data directory'
cand -h 'Print help'
cand --help 'Print help'
}
&'tinty;info'= {
cand -c 'Optional path to the tinty config.toml file'
cand --config 'Optional path to the tinty config.toml file'
cand -d 'Optional path to the tinty data directory'
cand --data-dir 'Optional path to the tinty data directory'
cand -h 'Print help'
cand --help 'Print help'
}
&'tinty;init'= {
cand -c 'Optional path to the tinty config.toml file'
cand --config 'Optional path to the tinty config.toml file'
cand -d 'Optional path to the tinty data directory'
cand --data-dir 'Optional path to the tinty data directory'
cand -h 'Print help'
cand --help 'Print help'
}
&'tinty;list'= {
cand -c 'Optional path to the tinty config.toml file'
cand --config 'Optional path to the tinty config.toml file'
cand -d 'Optional path to the tinty data directory'
cand --data-dir 'Optional path to the tinty data directory'
cand -h 'Print help'
cand --help 'Print help'
}
&'tinty;apply'= {
cand -c 'Optional path to the tinty config.toml file'
cand --config 'Optional path to the tinty config.toml file'
cand -d 'Optional path to the tinty data directory'
cand --data-dir 'Optional path to the tinty data directory'
cand -h 'Print help'
cand --help 'Print help'
}
&'tinty;install'= {
cand -c 'Optional path to the tinty config.toml file'
cand --config 'Optional path to the tinty config.toml file'
cand -d 'Optional path to the tinty data directory'
cand --data-dir 'Optional path to the tinty data directory'
cand -h 'Print help'
cand --help 'Print help'
}
&'tinty;update'= {
cand -c 'Optional path to the tinty config.toml file'
cand --config 'Optional path to the tinty config.toml file'
cand -d 'Optional path to the tinty data directory'
cand --data-dir 'Optional path to the tinty data directory'
cand -h 'Print help'
cand --help 'Print help'
}
&'tinty;help'= {
cand current 'Prints the last scheme name applied'
cand generate-completion 'Generates a shell completion script'
cand info 'Shows scheme colors for all schemes matching <scheme_system>-<scheme_name> (Eg: tinty info base16-mocha)'
cand init 'Initializes with the exising config. Used to Initialize exising theme for when your shell starts up'
cand list 'Lists available schemes'
cand apply 'Applies a theme based on the chosen scheme'
cand install 'Install the environment needed for tinty'
cand update 'Update to the latest themes'
cand help 'Print this message or the help of the given subcommand(s)'
}
&'tinty;help;current'= {
}
&'tinty;help;generate-completion'= {
}
&'tinty;help;info'= {
}
&'tinty;help;init'= {
}
&'tinty;help;list'= {
}
&'tinty;help;apply'= {
}
&'tinty;help;install'= {
}
&'tinty;help;update'= {
}
&'tinty;help;help'= {
}
]
$completions[$command]
}
Loading
Oops, something went wrong.

0 comments on commit 8df5a2e

Please sign in to comment.