Skip to content

Commit

Permalink
simplify bash completions install
Browse files Browse the repository at this point in the history
  • Loading branch information
thatportugueseguy committed Aug 26, 2024
1 parent c996118 commit 35c136b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 16 deletions.
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
.DEFAULT_GOAL := build
SHELL := /bin/bash

.PHONY: build
build:
Expand Down Expand Up @@ -31,4 +30,4 @@ top:

.PHONY: install_bash_completions
install_bash_completions:
. ./install-bash-completions.sh
./install-bash-completions.sh
17 changes: 3 additions & 14 deletions install-bash-completions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,15 @@ bashrc="$HOME/.bashrc"
source_line="source $completion_path"

# Check if the ~/.local/share/bash-completion directory exists, create it if it doesn't
# If the directory doesn't exist it's likely the first time the script is run. We don't want to repeat it every time.
if [ ! -d "$completion_dir" ]; then
echo "Setting up bash completions for Passage. Installing in $completion_dir and source them in your .bashrc file."
echo "Directory $completion_dir does not exist. Creating it."
mkdir -p "$completion_dir"
fi

if [ ! -f "$completion_path" ]; then
# Copy the passage-completion.sh file into the completion directory, replacing any existing file
echo "Copying $completion_file into $completion_dir."
fi

# Always copy the file, even if it already exists. This will update the completions
cp -f "$completion_file" "$completion_path"

# Check if the source line is already in the ~/.bashrc file, append it if not
# Check if the completions are already sourced in the ~/.bashrc file, inform on how to add completions if not
if ! grep -Fq "$source_line" "$bashrc"; then
echo "Updating $bashrc to source the completions."
echo "$source_line" >> "$bashrc"

# Source the completions in the current shell
source "$completion_path"
echo -e "Installed bash completions script for passage. To have them working, update the $bashrc file to source the completions: \n"
echo "echo \"$source_line\" >> ~/.bashrc"
fi

0 comments on commit 35c136b

Please sign in to comment.