Skip to content

Commit

Permalink
Fix packaging and Use parameterized names for zsh completion
Browse files Browse the repository at this point in the history
  • Loading branch information
Kienyew authored and sharkdp committed Sep 14, 2020
1 parent d9e8bbc commit a86f3e5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -3,5 +3,6 @@

# Generated files
/assets/completions/bat.fish
/assets/completions/bat.zsh
/assets/manual/bat.1
/assets/metadata.yaml
14 changes: 7 additions & 7 deletions assets/completions/bat.zsh → assets/completions/bat.zsh.in
@@ -1,4 +1,4 @@
#compdef bat
#compdef {{PROJECT_EXECUTABLE}}

local context state state_descr line
typeset -A opt_args
Expand All @@ -19,8 +19,8 @@ _cache_subcommand() {
_arguments -S -s $args
}

(( $+functions[_bat_main] )) ||
_bat_main() {
(( $+functions[_main] )) ||
_main() {
local -a args
args=(
'(-A --show-all)'{-A,--show-all}'[Show non-printable characters (space, tab, newline, ..)]'
Expand Down Expand Up @@ -55,15 +55,15 @@ _bat_main() {
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) }') )
languages=( $({{PROJECT_EXECUTABLE}} --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) )
themes=( $({{PROJECT_EXECUTABLE}} --list-themes | sort) )

_values 'theme' $themes
;;
Expand All @@ -79,15 +79,15 @@ if (( ${#words} == 2 )); then
local -a subcommands
subcommands=('cache:Modify the syntax-definition and theme cache')
_describe subcommand subcommands
_bat_main
_main
else
case $words[2] in
cache)
_cache_subcommand
;;

*)
_bat_main
_main
;;
esac
fi
5 changes: 5 additions & 0 deletions build.rs
Expand Up @@ -53,6 +53,11 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
"assets/completions/bat.fish.in",
out_dir.join("assets/completions/bat.fish"),
)?;
template(
&variables,
"assets/completions/bat.zsh.in",
out_dir.join("assets/completions/bat.zsh"),
)?;

Ok(())
}
Expand Down

0 comments on commit a86f3e5

Please sign in to comment.