From c40cb09409ad0414bc080f947c179ef6dbba59c9 Mon Sep 17 00:00:00 2001 From: Azalea Gui Date: Mon, 1 May 2023 17:23:58 -0400 Subject: [PATCH] [+] Script to install autocompletion https://github.com/hykilpikonna/hyfetch/issues/96 --- hyfetch/scripts/autocomplete.csh | 4 +- hyfetch/scripts/install-autocomplete.sh | 62 +++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 2 deletions(-) create mode 100755 hyfetch/scripts/install-autocomplete.sh diff --git a/hyfetch/scripts/autocomplete.csh b/hyfetch/scripts/autocomplete.csh index 8fb3a4b5..46e56c79 100644 --- a/hyfetch/scripts/autocomplete.csh +++ b/hyfetch/scripts/autocomplete.csh @@ -3,8 +3,8 @@ complete hyfetch \ - 'c/--/(version test-distro ascii-file preset c-set-l help debug config-file c-scale config backend mode distro)/' \ - 'c/-/(C m V h p b c -)/' \ + 'c/--/(mode test-distro preset config c-scale c-set-l config-file ascii-file version debug distro help backend)/' \ + 'c/-/(m h V C p b c -)/' \ 'n/-p/(rainbow transgender nonbinary agender queer genderfluid bisexual pansexual polysexual omnisexual omniromantic gay-men lesbian abrosexual asexual aromantic aroace1 aroace2 aroace3 autosexual intergender greygender akiosexual bigender demigender demiboy demigirl transmasculine transfeminine genderfaun demifaun genderfae demifae neutrois biromantic1 biromantic2 autoromantic boyflux2 finsexual unlabeled1 unlabeled2 pangender gendernonconforming1 gendernonconforming2 femboy tomboy gendervoid voidgirl voidboy beiyang burger)/' \ 'n/--preset/(rainbow transgender nonbinary agender queer genderfluid bisexual pansexual polysexual omnisexual omniromantic gay-men lesbian abrosexual asexual aromantic aroace1 aroace2 aroace3 autosexual intergender greygender akiosexual bigender demigender demiboy demigirl transmasculine transfeminine genderfaun demifaun genderfae demifae neutrois biromantic1 biromantic2 autoromantic boyflux2 finsexual unlabeled1 unlabeled2 pangender gendernonconforming1 gendernonconforming2 femboy tomboy gendervoid voidgirl voidboy beiyang burger)/' \ 'n/-m/(8bit rgb)/' \ diff --git a/hyfetch/scripts/install-autocomplete.sh b/hyfetch/scripts/install-autocomplete.sh new file mode 100755 index 00000000..652013ed --- /dev/null +++ b/hyfetch/scripts/install-autocomplete.sh @@ -0,0 +1,62 @@ +#!/usr/bin/env bash + +# Usage: ./install-autocomplete.sh [Uninstall] +if [[ "$1" == "uninstall" ]]; then + uninstall=true + echo -n "Uninstalling " +else + echo -n "Installing " +fi +echo "autocomplete scripts for HyFetch..." + +# Stop on error +set -e + +# Obtain path of the current bash script +script_path="$(dirname "$(realpath "$0")")" + +# Installing for a specific shell in a specific directory if it exists +install-for() +{ + shell=$1 + dir=$2 + + case $shell in + bash) + filename="hyfetch" + ;; + zsh) + filename="_hyfetch" + ;; + csh) + filename="hyfetch.completion.csh" + ;; + *) + echo "Unknown shell: $shell" + exit 1 + ;; + esac + + if [[ -d "$dir" ]]; then + if [[ "$uninstall" ]]; then + rm -f "$dir/$filename" + echo "⭐ Uninstalled for $shell in $dir" + else + cp "$script_path/autocomplete.$shell" "$dir/$filename" + echo "⭐ Installed for $shell in $dir" + fi + fi +} + +# Copy files +install-for bash /etc/bash_completion.d +install-for bash /usr/share/bash-completion/completions + +install-for zsh /usr/share/zsh/functions/Completion/Unix +install-for zsh /usr/share/zsh/site-functions +install-for zsh /usr/share/zsh-completions +install-for zsh /usr/local/share/zsh/site-functions + +install-for csh /etc/profile.d + +echo "Done!"