Add helper scripts for testing the completions

This commit is contained in:
Tau Gärtli 2024-08-18 18:56:06 +02:00
parent b662fec214
commit e0ad6beb60
No known key found for this signature in database
3 changed files with 46 additions and 0 deletions

11
scripts/test-completions.bash Executable file
View File

@ -0,0 +1,11 @@
#!/usr/bin/env bash
# Spawns a new bash shell that's set up with a PATH that points
# the `bat` executable and completions from the `target/` dir.
# Requires https://github.com/scop/bash-completion
target_dir="$(dirname "$(realpath "$0")")/../target/debug"
completion_file=$target_dir/build/bat-*/out/assets/completions/bat.bash
export PATH="$target_dir:$PATH"
bash --noprofile --rcfile <(echo "source /usr/share/bash-completion/bash_completion; source $completion_file") +o history

11
scripts/test-completions.fish Executable file
View File

@ -0,0 +1,11 @@
#!/usr/bin/env fish
# Spawns a new fish shell that's set up with a PATH that points
# the `bat` executable and completions from the `target/` dir.
set target_dir "$(dirname (realpath (status -f)))/../target/debug"
set completion_file $target_dir/build/bat-*/out/assets/completions/bat.fish
set --export PATH "$target_dir:$PATH"
fish \
--no-config --private \
--init-command="set -U fish_color_command brcyan; set -U fish_pager_color_description yellow; source $completion_file"

24
scripts/test-completions.zsh Executable file
View File

@ -0,0 +1,24 @@
#!/usr/bin/env bash
# Spawns a new zsh shell that's set up with a PATH that points
# the `bat` executable and completions from the `target/` dir.
# Yes, this is a .zsh file that's executed with bash instead :)
target_dir="$(dirname "$(realpath "$0")")/../target/debug"
completion_file=$target_dir/build/bat-*/out/assets/completions/bat.zsh
# Setup a temporary ZDOTDIR-
# that's the place where ZSH looks up config files (defaults to $HOME)
ZDOTDIR=$(mktemp -d); export ZDOTDIR
mkdir "$ZDOTDIR/completions"
cp $completion_file "$ZDOTDIR/completions/_bat"
# Setup an RC file that adds our temporary completions dir to the autoload path
# and initializes completions.
echo 'fpath+=("$ZDOTDIR/completions"); autoload -U compinit; compinit' > "$ZDOTDIR/.zshrc"
export PATH="$target_dir:$PATH"
zsh --no-globalrcs
rm -rf "$ZDOTDIR"