Skip to content

Commit

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

.PHONY: build
build:
Expand Down Expand Up @@ -27,3 +28,7 @@ clean:
.PHONY: top
top:
dune utop .

.PHONY: install_bash_completions
install_bash_completions:
. ./install-bash-completions.sh
33 changes: 33 additions & 0 deletions install-bash-completions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash

# Define variables
completion_dir="$HOME/.local/share/bash-completion"
completion_file="passage-completion.sh"
completion_path="$completion_dir/$completion_file"
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
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"
fi
1 change: 1 addition & 0 deletions passage.opam
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ build: [
]
]
dev-repo: "git+https://github.com/ahrefs/passage.git"
install: [make "install_bash_completions"]
x-ci-accept-failures: [
"alpine-3.20"
"archlinux"
Expand Down
1 change: 1 addition & 0 deletions passage.opam.template
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
install: [make "install_bash_completions"]
x-ci-accept-failures: [
"alpine-3.20"
"archlinux"
Expand Down

0 comments on commit c996118

Please sign in to comment.