mirror of
https://github.com/ChrisTitusTech/mybash.git
synced 2026-04-03 02:58:17 +00:00
33
.bashrc
33
.bashrc
@@ -1,4 +1,4 @@
|
||||
#!/bin/bash
|
||||
#!/usr/bin/env bash
|
||||
iatest=$(expr index "$-" i)
|
||||
|
||||
#######################################################
|
||||
@@ -42,6 +42,15 @@ shopt -s checkwinsize
|
||||
shopt -s histappend
|
||||
PROMPT_COMMAND='history -a'
|
||||
|
||||
# set up XDG folders
|
||||
export XDG_DATA_HOME="$HOME/.local/share"
|
||||
export XDG_CONFIG_HOME="$HOME/.config"
|
||||
export XDG_STATE_HOME="$HOME/.local/state"
|
||||
export XDG_CACHE_HOME="$HOME/.cache"
|
||||
|
||||
# Seeing as other scripts will use it might as well export it
|
||||
export LINUXTOOLBOXDIR="$HOME/linuxtoolbox"
|
||||
|
||||
# Allow ctrl-S for history navigation (with ctrl-R)
|
||||
[[ $- == *i* ]] && stty -ixon
|
||||
|
||||
@@ -475,10 +484,10 @@ install_bashrc_support() {
|
||||
sudo apt-get install multitail tree zoxide trash-cli fzf bash-completion
|
||||
# Fetch the latest fastfetch release URL for linux-amd64 deb file
|
||||
FASTFETCH_URL=$(curl -s https://api.github.com/repos/fastfetch-cli/fastfetch/releases/latest | grep "browser_download_url.*linux-amd64.deb" | cut -d '"' -f 4)
|
||||
|
||||
|
||||
# Download the latest fastfetch deb file
|
||||
curl -sL $FASTFETCH_URL -o /tmp/fastfetch_latest_amd64.deb
|
||||
|
||||
|
||||
# Install the downloaded deb file using apt-get
|
||||
sudo apt-get install /tmp/fastfetch_latest_amd64.deb
|
||||
;;
|
||||
@@ -628,5 +637,19 @@ fi
|
||||
export PATH=$PATH:"$HOME/.local/bin:$HOME/.cargo/bin:/var/lib/flatpak/exports/bin:/.local/share/flatpak/exports/bin"
|
||||
|
||||
# Install Starship - curl -sS https://starship.rs/install.sh | sh
|
||||
eval "$(starship init bash)"
|
||||
eval "$(zoxide init bash)"
|
||||
# cache starship and zoxide for faster startup also creates the cache the first time
|
||||
# refreshes the cache every 14 days so if you update during that time and the script
|
||||
# for starship or zoxide initialization changes you will get the new script
|
||||
local STARSHIP_CACHE="$LINUXTOOLBOXDIR/mybash/_starship.sh"
|
||||
if [[ ! $(find "$STARSHIP_CACHE" -newermt "14 days ago" -print) ]]; then
|
||||
starship init bash --print-full-init > "$STARSHIP_CACHE"
|
||||
fi
|
||||
source "$STARSHIP_CACHE"
|
||||
|
||||
local ZOXIDE_CACHE="$LINUXTOOLBOXDIR/mybash/_zoxide.sh"
|
||||
if [[ ! $(find "$ZOXIDE_CACHE" -newermt "14 days ago" -print) ]]; then
|
||||
zoxide init bash > "$ZOXIDE_CACHE"
|
||||
fi
|
||||
source "$ZOXIDE_CACHE"
|
||||
|
||||
unset STARSHIP_CACHE ZOXIDE_CACHE
|
||||
|
||||
@@ -2,6 +2,14 @@
|
||||
|
||||
The `.bashrc` file is a script that runs every time a new terminal session is started in Unix-like operating systems. It is used to configure the shell session, set up aliases, define functions, and more, making the terminal easier to use and more powerful. Below is a summary of the key sections and functionalities defined in the provided `.bashrc` file.
|
||||
|
||||
## How to install
|
||||
```
|
||||
git clone --depth=1 https://github.com/ChrisTitusTech/mybash.git
|
||||
cd mybash
|
||||
chmod +x setup.sh
|
||||
./setup.sh
|
||||
```
|
||||
|
||||
### Initial Setup and System Checks
|
||||
|
||||
- **Environment Checks**: The script checks if it is running in an interactive mode and sets up the environment accordingly.
|
||||
|
||||
29
setup.sh
29
setup.sh
@@ -25,6 +25,11 @@ else
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# add variables to top level so can easily be accessed by all functions
|
||||
PACKAGER=""
|
||||
SUDO_CMD=""
|
||||
SUGROUP=""
|
||||
GITPATH=""
|
||||
|
||||
cd "$LINUXTOOLBOXDIR/mybash" || exit
|
||||
|
||||
@@ -43,7 +48,7 @@ checkEnv() {
|
||||
done
|
||||
|
||||
## Check Package Handler
|
||||
PACKAGEMANAGER='apt yum dnf pacman zypper'
|
||||
PACKAGEMANAGER='nala apt dnf yum pacman zypper emerge xbps-install nix-env'
|
||||
for pgm in $PACKAGEMANAGER; do
|
||||
if command_exists "$pgm"; then
|
||||
PACKAGER="$pgm"
|
||||
@@ -65,8 +70,8 @@ checkEnv() {
|
||||
SUDO_CMD="su -c"
|
||||
fi
|
||||
|
||||
echo "Using ${SUDO_CMD} as privilege escalation software"
|
||||
|
||||
echo "Using $SUDO_CMD as privilege escalation software"
|
||||
|
||||
## Check if the current directory is writable.
|
||||
GITPATH=$(dirname "$(realpath "$0")")
|
||||
if [ ! -w "$GITPATH" ]; then
|
||||
@@ -75,6 +80,7 @@ checkEnv() {
|
||||
fi
|
||||
|
||||
## Check SuperUser Group
|
||||
|
||||
SUPERUSERGROUP='wheel sudo root'
|
||||
for sug in $SUPERUSERGROUP; do
|
||||
if groups | grep -q "$sug"; then
|
||||
@@ -144,12 +150,14 @@ installDepend() {
|
||||
${SUDO_CMD} ${PACKAGER} -v ${DEPENDENCIES}
|
||||
elif [ "$PACKAGER" = "nix-env" ]; then
|
||||
${SUDO_CMD} ${PACKAGER} -iA nixos.bash nixos.bash-completion nixos.gnutar nixos.neovim nixos.bat nixos.tree nixos.multitail nixos.fastfetch
|
||||
elif [[ "$PACKAGER" == "dnf" ]]; then
|
||||
${SUDO_CMD} ${PACKAGER} install -y ${DEPENDENCIES}
|
||||
else
|
||||
${SUDO_CMD} ${PACKAGER} install -yq ${DEPENDENCIES}
|
||||
fi
|
||||
}
|
||||
|
||||
installStarship() {
|
||||
installStarshipAndFzf() {
|
||||
if command_exists starship; then
|
||||
echo "Starship already installed"
|
||||
return
|
||||
@@ -180,7 +188,11 @@ installZoxide() {
|
||||
}
|
||||
|
||||
install_additional_dependencies() {
|
||||
case $(command -v apt || command -v zypper || command -v dnf || command -v pacman) in
|
||||
# we have PACKAGER so just use it
|
||||
# for now just going to return early as we have already installed neovim in `installDepend`
|
||||
# so I am not sure why we are trying to install it again
|
||||
return
|
||||
case "$PACKAGER" in
|
||||
*apt)
|
||||
if [ ! -d "/opt/neovim" ]; then
|
||||
curl -LO https://github.com/neovim/neovim/releases/latest/download/nvim.appimage
|
||||
@@ -196,11 +208,11 @@ install_additional_dependencies() {
|
||||
;;
|
||||
*dnf)
|
||||
${SUDO_CMD} dnf check-update
|
||||
${SUDO_CMD} dnf install -y neovim
|
||||
${SUDO_CMD} dnf install -y neovim
|
||||
;;
|
||||
*pacman)
|
||||
${SUDO_CMD} pacman -Syu
|
||||
${SUDO_CMD} pacman -S --noconfirm neovim
|
||||
${SUDO_CMD} pacman -S --noconfirm neovim
|
||||
;;
|
||||
*)
|
||||
echo "No supported package manager found. Please install neovim manually."
|
||||
@@ -236,7 +248,6 @@ linkConfig() {
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
echo "${YELLOW}Linking new bash config file...${RC}"
|
||||
ln -svf "$GITPATH/.bashrc" "$USER_HOME/.bashrc"
|
||||
ln -svf "$GITPATH/starship.toml" "$USER_HOME/.config/starship.toml"
|
||||
@@ -244,7 +255,7 @@ linkConfig() {
|
||||
|
||||
checkEnv
|
||||
installDepend
|
||||
installStarship
|
||||
installStarshipAndFzf
|
||||
installZoxide
|
||||
install_additional_dependencies
|
||||
create_fastfetch_config
|
||||
|
||||
Reference in New Issue
Block a user