Skip to content
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 helper scripts for testing the shell completions #3072

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions scripts/test-completions.bash
Original file line number Diff line number Diff line change
@@ -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 changes: 11 additions & 0 deletions scripts/test-completions.fish
Original file line number Diff line number Diff line change
@@ -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 changes: 24 additions & 0 deletions scripts/test-completions.zsh
Original file line number Diff line number Diff line change
@@ -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"
Loading