Skip to content

Commit

Permalink
Add tab completion for zsh / fish
Browse files Browse the repository at this point in the history
  • Loading branch information
eeclfrei committed Sep 9, 2021
1 parent 448e879 commit 4b08d03
Show file tree
Hide file tree
Showing 6 changed files with 557 additions and 20 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,14 @@ jobs:
cp lib/install.sh phylum-cli-release/
cp lib/src/bin/settings.yaml phylum-cli-release/
cp lib/src/bin/phylum.bash phylum-cli-release/
cp lib/src/bin/phylum.fish phylum-cli-release/
cp lib/src/bin/_phylum phylum-cli-release/
cp phylum-linux-x86_64 phylum-cli-release/
cp phylum-macos-x86_64 phylum-cli-release/
cp lib/install.sh .
cp lib/src/bin/settings.yaml .
cp lib/src/bin/phylum.bash .
cp lib/src/bin/_phylum .
env:
MINISIGN_KEY: ${{ secrets.MINISIGN_KEY }}
MINISIGN_PASSWORD: ${{ secrets.MINISIGN_PASSWORD }}
Expand All @@ -61,6 +64,7 @@ jobs:
install.sh
settings.yaml
phylum.bash
_phylum
phylum-cli-release.zip
phylum-linux-x86_64.minisig
phylum-macos-x86_64.minisig
Expand Down
29 changes: 25 additions & 4 deletions lib/build.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,36 @@
use clap::{load_yaml, App};
use clap_generate::{generate_to, generators::Bash};
use clap_generate::{
generate_to,
generators::{Bash, Fish, Zsh},
};

const BIN_NAME: &str = "phylum";
const OUT_DIR: &str = "src/bin/";

fn main() {
println!("Running build");
let yml = load_yaml!("src/bin/.conf/cli.yaml");
let mut app = App::from(yml);

// Create tab completions files for some popular shells
generate_to::<Bash, _, _>(
&mut app, // We need to specify what generator to use
"phylum", // We need to specify the bin name manually
"src/bin/", // We need to specify where to write to
&mut app, // We need to specify what generator to use
BIN_NAME, // We need to specify the bin name manually
OUT_DIR, // We need to specify where to write to
)
.unwrap();

generate_to::<Zsh, _, _>(
&mut app, // We need to specify what generator to use
BIN_NAME, // We need to specify the bin name manually
OUT_DIR, // We need to specify where to write to
)
.unwrap();

generate_to::<Fish, _, _>(
&mut app, // We need to specify what generator to use
BIN_NAME, // We need to specify the bin name manually
OUT_DIR, // We need to specify where to write to
)
.unwrap();
}
24 changes: 16 additions & 8 deletions lib/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@ if [ ! -f ${HOME}/.phylum/settings.yaml ]; then
check_copy "settings.yaml" "${HOME}/.phylum/"
fi

# Copy the bash completion to phylum directory.
check_copy "phylum.bash" "${HOME}/.phylum/"

# Copy the specific platform binary.
platform=$(get_platform)
arch="x86_64"
Expand All @@ -62,17 +59,28 @@ chmod +x ${HOME}/.phylum/phylum
# Update some paths.
rc_path=""

if [ -n "$ZSH_VERSION" ]; then
# If zsh is installed, we assume that's preferred
if [ -d /usr/local/share/zsh/site-functions ]; then
rc_path=".zshrc"

if ! grep -q '.phylum/completions' $HOME/${rc_path}; then
echo "fpath+=(\"$HOME/.phylum/completions\")" >> ${HOME}/${rc_path}
fi
if ! grep -q 'autoload -U compinit && compinit' $HOME/${rc_path}; then
echo "autoload -U compinit && compinit" >> ${HOME}/${rc_path}
fi
else
rc_path=".bashrc"
fi

if ! grep -q 'phylum.bash' $HOME/${rc_path}; then
echo "source \$HOME/.phylum/phylum.bash" >> ${HOME}/${rc_path}
# Copy the bash completion to phylum directory.
check_copy "phylum.bash" "${HOME}/.phylum/"

if ! grep -q 'phylum.bash' $HOME/${rc_path}; then
echo "source \$HOME/.phylum/phylum.bash" >> ${HOME}/${rc_path}
fi
fi

if ! grep -q '.phylum/:\$PATH' $HOME/${rc_path}; then
if ! grep -q '.phylum:\$PATH' $HOME/${rc_path}; then
export PATH="$HOME/.phylum:$PATH"
echo 'export PATH="$HOME/.phylum:$PATH"' >> ${HOME}/${rc_path}
success "Updating path to include ${HOME}/.phylum/."
Expand Down
Loading

0 comments on commit 4b08d03

Please sign in to comment.