From 4045b18753f6db92facad4018451ffbfdf63ec7f Mon Sep 17 00:00:00 2001 From: Dan Kendall Date: Sat, 18 May 2024 23:36:32 +0100 Subject: [PATCH] Fix interactive shell, add nala and rg --- .bashrc | 17 +++++++++++++++-- setup.sh | 44 +++++++++++++++++++++++++++----------------- 2 files changed, 42 insertions(+), 19 deletions(-) diff --git a/.bashrc b/.bashrc index bd53c78..ef17fe1 100644 --- a/.bashrc +++ b/.bashrc @@ -75,7 +75,15 @@ fi export CLICOLOR=1 export LS_COLORS='no=00:fi=00:di=00;34:ln=01;36:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.gz=01;31:*.bz2=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.avi=01;35:*.fli=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.ogg=01;35:*.mp3=01;35:*.wav=01;35:*.xml=00;31:' #export GREP_OPTIONS='--color=auto' #deprecated -alias grep="/usr/bin/grep $GREP_OPTIONS" + +# Check if ripgrep is installed +if command -v rg &> /dev/null; then + # Alias grep to rg if ripgrep is installed + alias grep='rg' +else + # Alias grep to /usr/bin/grep with GREP_OPTIONS if ripgrep is not installed + alias grep="/usr/bin/grep $GREP_OPTIONS" +fi unset GREP_OPTIONS # Color for manpages in less makes manpages a little easier to read @@ -554,7 +562,12 @@ lazyg() { ####################################################### alias hug="hugo server -F --bind=10.0.0.97 --baseURL=http://10.0.0.97" -bind '"\C-f":"zi\n"' + +# Check if the shell is interactive +if [[ $- == *i* ]]; then + # Bind Ctrl+f to insert 'zi' followed by a newline + bind '"\C-f":"zi\n"' +fi export PATH=$PATH:"$HOME/.local/bin:$HOME/.cargo/bin:/var/lib/flatpak/exports/bin:/.local/share/flatpak/exports/bin" diff --git a/setup.sh b/setup.sh index fcfa011..3fbd303 100755 --- a/setup.sh +++ b/setup.sh @@ -6,28 +6,31 @@ YELLOW='\e[33m' GREEN='\e[32m' command_exists() { - command -v $1 >/dev/null 2>&1 + command -v "$1" >/dev/null 2>&1 } checkEnv() { ## Check for requirements. REQUIREMENTS='curl groups sudo' - if ! command_exists ${REQUIREMENTS}; then - echo -e "${RED}To run me, you need: ${REQUIREMENTS}${RC}" - exit 1 - fi + for req in ${REQUIREMENTS}; do + if ! command_exists ${req}; then + echo -e "${RED}To run me, you need: ${REQUIREMENTS}${RC}" + exit 1 + fi + done - ## Check Package Handeler - PACKAGEMANAGER='apt yum dnf pacman zypper' + ## Check Package Manager + PACKAGEMANAGER='nala apt yum dnf pacman zypper' for pgm in ${PACKAGEMANAGER}; do if command_exists ${pgm}; then PACKAGER=${pgm} echo -e "Using ${pgm}" + break fi done if [ -z "${PACKAGER}" ]; then - echo -e "${RED}Can't find a supported package manager" + echo -e "${RED}Can't find a supported package manager${RC}" exit 1 fi @@ -41,23 +44,27 @@ checkEnv() { ## Check SuperUser Group SUPERUSERGROUP='wheel sudo root' for sug in ${SUPERUSERGROUP}; do - if groups | grep ${sug}; then + if groups | (command_exists rg && rg -q ${sug} || grep -q ${sug}); then SUGROUP=${sug} echo -e "Super user group ${SUGROUP}" + break fi done ## Check if member of the sudo group. - if ! groups | grep ${SUGROUP} >/dev/null; then - echo -e "${RED}You need to be a member of the sudo group to run me!" + if ! groups | (command_exists rg && rg -q ${SUGROUP} || grep -q ${SUGROUP}); then + echo -e "${RED}You need to be a member of the sudo group to run me!${RC}" exit 1 fi - } installDepend() { ## Check for dependencies. - DEPENDENCIES='bash bash-completion tar neovim bat tree multitail fastfetch' + DEPENDENCIES='bash bash-completion tar bat tree multitail fastfetch' + if ! command_exists nvim; then + DEPENDENCIES="${DEPENDENCIES} neovim" + fi + echo -e "${YELLOW}Installing dependencies...${RC}" if [[ $PACKAGER == "pacman" ]]; then if ! command_exists yay && ! command_exists paru; then @@ -66,7 +73,7 @@ installDepend() { cd /opt && sudo git clone https://aur.archlinux.org/yay-git.git && sudo chown -R ${USER}:${USER} ./yay-git cd yay-git && makepkg --noconfirm -si else - echo "Aur helper already installed" + echo "AUR helper already installed" fi if command_exists yay; then AUR_HELPER="yay" @@ -77,6 +84,8 @@ installDepend() { exit 1 fi ${AUR_HELPER} --noconfirm -S ${DEPENDENCIES} + elif [[ $PACKAGER == "nala" ]]; then + sudo ${PACKAGER} install -y ${DEPENDENCIES} else sudo ${PACKAGER} install -yq ${DEPENDENCIES} fi @@ -113,8 +122,8 @@ installZoxide() { } install_additional_dependencies() { - sudo apt update - sudo apt install -y trash-cli bat meld jpico + sudo apt update + sudo apt install -y trash-cli bat meld jpico } linkConfig() { @@ -143,7 +152,8 @@ installZoxide install_additional_dependencies if linkConfig; then - echo -e "${GREEN}Done!\nrestart your shell to see the changes.${RC}" + echo -e "${GREEN}Done!\nRestart your shell to see the changes.${RC}" else echo -e "${RED}Something went wrong!${RC}" fi +