-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add zsh completion #1136
Merged
Merged
Add zsh completion #1136
Changes from 2 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
62bf8d4
Add zsh completion
Kienyew 1a3eb71
Fix character escape problem
Kienyew 32905f7
add completion for 'cache' subcommand
Kienyew dfa8705
use _describe instead of _values on subcommand
Kienyew 62149b1
Update CHANGELOG.md
Kienyew 55c01d6
Fix typo
Kienyew 5333e23
Handle zsh completion when packaging
Kienyew bb56fc7
Fix packaging and Use parameterized names for zsh completion
Kienyew File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#compdef bat | ||
# FIXME: help me with the subcommand `cache`, zsh completion is hard as hell | ||
|
||
local -a args | ||
local state | ||
|
||
args=( | ||
'(-A --show-all)'{-A,--show-all}'[Show non-printable characters (space, tab, newline, ..)]' | ||
{-p,--plain}'[Show plain style (alias for `--style=plain`)]:When `-p` is used twice (`-pp`), it also disables automatic paging (alias for `--style=plain --paging=never`)' | ||
'(-l --language)'{-l+,--language=}'[Set the language for syntax highlighting]:<language>:->language' | ||
'(-H --highlight-line)'{-H,--highlight-line}'[Highlight lines N through M]:<N\:M>...' | ||
'(--file-name)'--file-name'[Specify the name to display for a file]:<name>...:_files' | ||
'(-d --diff)'--diff'[Only show lines that have been added/removed/modified]' | ||
'(--diff-context)'--diff-context'[Include N lines of context around added/removed/modified lines when using `--diff`]:<N> (lines):()' | ||
'(--tabs)'--tabs'[Set the tab width to T spaces]:<T> (tab width):()' | ||
'(--wrap)'--wrap='[Specify the text-wrapping mode]:<when>:(auto never character)' | ||
'(--terminal-width)'--terminal-width'[Explicitly set the width of the terminal instead of determining it automatically]:<width>' | ||
'(-n --number)'{-n,--number}'[Show line numbers]' | ||
'(--color)'--color='[When to use colors]:<when>:(auto never always)' | ||
'(--italic-text)'--italic-text='[Use italics in output]:<when>:(always never)' | ||
'(--decorations)'--decorations='[When to show the decorations]:<when>:(auto never always)' | ||
'(--paging)'--paging='[Specify when to use the pager]:<when>:(auto never always)' | ||
'(-m --map-syntax)'{-m+,--map-syntax=}'[Use the specified syntax for files matching the glob pattern]:<glob\:syntax>...' | ||
'(--theme)'--theme='[Set the color theme for syntax highlighting]:<theme>:->theme' | ||
'(: --list-themes --list-languages -L)'--list-themes'[Display all supported highlighting themes]' | ||
'(--style)'--style='[Comma-separated list of style elements to display]:<components>:->style' | ||
'(-r --line-range)'{-r+,--line-range=}'[Only print the lines from N to M]:<N\:M>...' | ||
'(: --list-themes --list-languages -L)'{-L,--list-languages}'[Display all supported languages]' | ||
'(: -)'{-h,--help}'[Print this help message]' | ||
'(: -)'{-V,--version}'[Show version information]' | ||
'*: :_files' | ||
) | ||
|
||
_arguments -S -s $args | ||
|
||
case "$state" in | ||
language) | ||
local IFS=$'\n' | ||
local -a languages | ||
languages=( $(bat --list-languages | awk -F':|,' '{ for (i = 1; i <= NF; ++i) printf("%s:%s\n", $i, $1) }') ) | ||
|
||
_describe 'language' languages | ||
;; | ||
|
||
theme) | ||
local IFS=$'\n' | ||
local -a themes | ||
themes=( $(bat --list-themes | sort) ) | ||
|
||
_values 'theme' $themes | ||
;; | ||
|
||
style) | ||
_values -s , 'style' auto full plain changes header grid numbers snip | ||
;; | ||
esac |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have never written any completion scripts. Let's leave this open until someone can help?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe I'll dive into the zsh manual again later, sorry to say but is one of the most difficult manual I have read IMO 🤣
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd be also okay with merging this without support for the
cache
subcommand.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added the completion of
cache
subcommand in 32905f7