From 64243895be0e6cd17ff1321ceb96ad0769817f98 Mon Sep 17 00:00:00 2001 From: Grief Date: Sun, 25 Aug 2024 01:19:14 +0100 Subject: [PATCH] install --- hook | 48 ++++++++++++++++++++++++++++++++++ hooks/install/install-oh-my.sh | 29 ++++++++++++++++++++ hooks/install/install.sh | 14 ++++++++++ 3 files changed, 91 insertions(+) create mode 100755 hook create mode 100644 hooks/install/install-oh-my.sh create mode 100644 hooks/install/install.sh diff --git a/hook b/hook new file mode 100755 index 0000000..4607817 --- /dev/null +++ b/hook @@ -0,0 +1,48 @@ +#!/bin/bash + +MUREX_SHELL="$(basename "$(readlink /proc/$$/exe)")" +export MUREX_SHELL + +case "${MUREX_SHELL}" in + zsh ) rc=${(%):-%N} ;; + bash) rc="${BASH_SOURCE[0]}" ;; + hook) rc="$0"; MUREX_SHELL="$1" ;; + *) return +esac +if [ -z "${MUREX}" ]; then + MUREX="$(dirname "$(realpath "${rc}")")" + export MUREX +fi +run_hook() { + if [ ! -d "$1" ]; then return; fi + for handler in "$1"/*; do + if [ -e "${handler}" ]; then + case "${handler}" in + *.sh|*.${MUREX_SHELL}) . "${handler}";; + *.bg) "${handler}"&;; + esac + fi + done +} +run_hooks() { + for hook in "$@"; do + run_hook "${MUREX}/hooks/${hook}"; + run_hook "${MUREX}/private/hooks/${hook}"; + done +} +if [ "$(basename -- "$0")" = "hook" ]; then + if [ "$1" = "install" ]; then run_hooks sh install; else run_hooks "$@"; fi +else + rc="$(basename "${rc}")" + case "${rc}" in + '.zshenv') run_hooks shell;; + '.zprofile') run_hooks shell-early-login;; + '.zshrc') run_hooks shell-interactive;; + '.zlogin') run_hooks shell-late-login;; + '.zlogout') run_hooks shell-logout;; + '.bash_profile') run_hooks shell shell-early-login shell-interactive shell-late-login;; + '.bashrc') run_hooks shell shell-interactive;; + '.bash_logout') run_hooks shell-logout;; + *) run_hooks "${rc}";; + esac +fi diff --git a/hooks/install/install-oh-my.sh b/hooks/install/install-oh-my.sh new file mode 100644 index 0000000..f56b136 --- /dev/null +++ b/hooks/install/install-oh-my.sh @@ -0,0 +1,29 @@ +ZSH="${MUREX}/modules/oh-my-zsh" + +install_oh_my_zsh() { + git clone https://github.com/ohmyzsh/ohmyzsh.git "$ZSH" + + themes="${ZSH}/custom/themes" + ln -s "${MUREX}/conf/murex/oh-my.zsh-theme" "$themes" + + plugins="${ZSH}/custom/plugins" + + git clone https://github.com/zsh-users/zsh-syntax-highlighting.git "${plugins}/zsh-syntax-highlighting" + git clone https://github.com/zsh-users/zsh-autosuggestions "${plugins}/zsh-autosuggestions" + git clone https://github.com/zsh-users/zsh-history-substring-search "${plugins}/zsh-history-substring-search" +} + +if [ ! -e "$ZSH" ]; then + echo 'Would you like to download and install oh-my-zsh [ http://ohmyz.sh/ ]? (yes/no)' + while true; do + read answer + case "$answer" in + "no") break ;; + "yes") + install_oh_my_zsh + break + ;; + *) echo 'Please type only "yes" or "no"' + esac + done +fi diff --git a/hooks/install/install.sh b/hooks/install/install.sh new file mode 100644 index 0000000..c3f4126 --- /dev/null +++ b/hooks/install/install.sh @@ -0,0 +1,14 @@ +backup="$(mktemp -dp "${MUREX}/backup" "$(datestamp)-install-XXXXX")" + +echo "Linking RC files..." +for rc in bash_profile bashrc bash_logout zshenv zprofile zshrc zlogin zlogout; do + mv ~/.${rc} "${backup}" + ln -sf "${MUREX}/hook" ~/.${rc} +done + +ln -sf "${MUREX}/hook" ~/.config/autostart-scripts/de-startup +ln -sf "${MUREX}/hook" ~/.config/plasma-workspace/shutdown/de-shutdown + + +echo "Generating ZSH prompts..." +zsh-prompt-generator -s \ No newline at end of file