Squashed commit of the following:

commit baadd91ee2a879dee1f25380102b3a2771d001f3
Author: TrudeEH <ehtrude@gmail.com>
Date:   Mon Mar 25 13:18:48 2024 +0000

    Finished preparations to merge

commit 4789d301aef540216b900141372bf6b925e7931e
Author: TrudeEH <ehtrude@gmail.com>
Date:   Mon Mar 25 13:03:14 2024 +0000

    Update bashrc

commit 465d5c43ea87928dcf1cb77efb2131cb7ddb4133
Author: TrudeEH <ehtrude@gmail.com>
Date:   Mon Mar 25 12:56:15 2024 +0000

    Fix bashrc on debian

commit 193cd30089c2102909d3b8d22e335845455d9934
Author: TrudeEH <ehtrude@gmail.com>
Date:   Mon Mar 25 12:52:25 2024 +0000

    Attempt to reduce linking steps

commit 39589aaeb92c6bdb87fc38fc5a6c9adf320630a4
Author: TrudeEH <ehtrude@gmail.com>
Date:   Mon Mar 25 12:51:28 2024 +0000

    Added --adopt flag to stow

commit 6d575fb675408eecd721e82433ffd0f3391629b8
Author: TrudeEH <ehtrude@gmail.com>
Date:   Mon Mar 25 12:49:28 2024 +0000

    Try to force stow to override existing symlinks

commit b646179a0e50f71057ad4c2f87b6cadd35be1eb1
Author: TrudeEH <ehtrude@gmail.com>
Date:   Mon Mar 25 12:45:26 2024 +0000

    Fix grep

commit 614167978708a24e9e738fe2bdb3b9c5aff35c67
Author: TrudeEH <ehtrude@gmail.com>
Date:   Mon Mar 25 12:42:44 2024 +0000

    Fix last commit

commit e460693bf708e9a3ad882da143daf7f621ae7b96
Author: TrudeEH <ehtrude@gmail.com>
Date:   Mon Mar 25 12:41:33 2024 +0000

    Test label fix

commit a93ecf4bc09c3f6f6e2a0381eb83528c84e991b5
Author: TrudeEH <ehtrude@gmail.com>
Date:   Mon Mar 25 12:40:09 2024 +0000

    Update grep to separate "-" from normal package names

commit e556aaf8d9acb54f05866da33223eb7bc03c8248
Author: TrudeEH <ehtrude@gmail.com>
Date:   Mon Mar 25 12:36:46 2024 +0000

    revert to last commit

commit f2658d974dc0c738e4e2b62df900b0dcc286dda7
Author: TrudeEH <ehtrude@gmail.com>
Date:   Mon Mar 25 12:34:01 2024 +0000

    Try to fix incorrect search command

commit 8f099335f510e31ae44a1d720c68f12b4c68aab6
Author: TrudeEH <ehtrude@gmail.com>
Date:   Mon Mar 25 12:32:24 2024 +0000

    Fix APT search output

commit 0f0acbf13e4e82b59f5e4975a99c83b0636d7c7a
Author: TrudeEH <ehtrude@gmail.com>
Date:   Mon Mar 25 12:28:57 2024 +0000

    fix apt search package command

commit ef66be61203321c22d4968c0f0002559db1a72a4
Author: TrudeEH <ehtrude@gmail.com>
Date:   Mon Mar 25 12:25:31 2024 +0000

    Fix remove bug

commit 627fdc72887d521b7a7f0b24ceb84a23bf787f5e
Author: TrudeEH <ehtrude@gmail.com>
Date:   Mon Mar 25 12:21:36 2024 +0000

    Add warning if app isn't installed.

commit b341caa088cce0134360757014cc8e06df206868
Author: TrudeEH <ehtrude@gmail.com>
Date:   Mon Mar 25 12:20:05 2024 +0000

    fix check input

commit 399163f9b8cf62fe6c211e98733524fcb041bb29
Author: TrudeEH <ehtrude@gmail.com>
Date:   Mon Mar 25 12:19:36 2024 +0000

    debug print

commit 2cb7904fe3a2ae5350a60b2f0f16975e397ed497
Author: TrudeEH <ehtrude@gmail.com>
Date:   Mon Mar 25 12:14:09 2024 +0000

    Fix string

commit d83e4f95595683cdc8166162af14d160b30fd79d
Author: TrudeEH <ehtrude@gmail.com>
Date:   Mon Mar 25 12:13:11 2024 +0000

    Fix check input

commit 992343066539ab2b5780c5fa6e73ba3a68f0e8f2
Author: TrudeEH <ehtrude@gmail.com>
Date:   Mon Mar 25 12:11:38 2024 +0000

    debug print 2

commit bc0cf43a28c5a701bd90158eb10efcc1b1cae611
Author: TrudeEH <ehtrude@gmail.com>
Date:   Mon Mar 25 12:10:28 2024 +0000

    debug print

commit 8fa90f9b602d5e18a4632022b6a2a131f2131150
Author: TrudeEH <ehtrude@gmail.com>
Date:   Mon Mar 25 12:09:27 2024 +0000

    style fix

commit 3358c726a93d808f5ec53f321302ce6525a2111f
Author: TrudeEH <ehtrude@gmail.com>
Date:   Mon Mar 25 12:07:09 2024 +0000

    fix nix return again

commit e3db3959aff42722bc0e3076b92e5a83d40a52ce
Author: TrudeEH <ehtrude@gmail.com>
Date:   Mon Mar 25 12:05:06 2024 +0000

    tr with nix for newline

commit 165c3e8c86581b3ecc5c4b7f801d4a3570c394a1
Author: TrudeEH <ehtrude@gmail.com>
Date:   Mon Mar 25 12:03:12 2024 +0000

    test nix return fix

commit 16b6825362a2e456ea8758fbe0a20e4763a58562
Author: TrudeEH <ehtrude@gmail.com>
Date:   Mon Mar 25 12:02:25 2024 +0000

    test nix return

commit a108b47ac189bb4ddd4891c80bbb5044da4501de
Author: TrudeEH <ehtrude@gmail.com>
Date:   Mon Mar 25 12:01:35 2024 +0000

    Fix wrong apt-get usage

commit bcc3b9f32cead6fa439a057a995086943dfe9e36
Author: TrudeEH <ehtrude@gmail.com>
Date:   Mon Mar 25 11:55:41 2024 +0000

    Switch apt to apt-get

commit eb5b272055e000a60e91042529e7c976c84be274
Author: TrudeEH <ehtrude@gmail.com>
Date:   Mon Mar 25 11:53:24 2024 +0000

    Fix return codes

commit 07e424e3de6f115aefa50778d0ffdf89e13c2fe8
Author: TrudeEH <ehtrude@gmail.com>
Date:   Mon Mar 25 11:47:14 2024 +0000

    Removed unnecessary checks

commit b6e08e978a6ce420e8f7bb85087aef30a151aede
Author: TrudeEH <ehtrude@gmail.com>
Date:   Mon Mar 25 11:41:47 2024 +0000

    Attempt fix, again

commit 5e95a13f75fa234da0a330f0a878fb2f4eec8b39
Author: TrudeEH <ehtrude@gmail.com>
Date:   Mon Mar 25 11:37:11 2024 +0000

    Fix last commit

commit 2babffa9e124928e9e46395d9199138e1800c265
Author: TrudeEH <ehtrude@gmail.com>
Date:   Mon Mar 25 11:35:32 2024 +0000

    Check if program is installed before installing it.

commit 938fd9fe5ea39c4e55944c0488f33437de06e7b7
Author: TrudeEH <ehtrude@gmail.com>
Date:   Mon Mar 25 11:26:04 2024 +0000

    Dotfiles rewrite (using stew)

    Full rewrite; Still in testing
This commit is contained in:
2024-03-25 13:19:08 +00:00
parent 0f48444ffd
commit 29967fcf2c
16 changed files with 320 additions and 240 deletions

View File

@@ -1,2 +0,0 @@
echo "Generate: brew bundle dump --describe"
echo "Restore: brew bundle --file FileToRestore"

View File

@@ -1,5 +1,3 @@
#! /bin/bash
RED="\e[31m"
GREEN="\e[32m"
YELLOW="\e[33m"

View File

@@ -1,2 +0,0 @@
defaults write com.apple.dock persistent-apps -array-add '{"tile-type"="small-spacer-tile";}'
killall Dock

View File

@@ -1,2 +0,0 @@
defaults write com.apple.dock persistent-apps -array-add '{tile-data={}; tile-type="spacer-tile";}'
killall Dock

View File

@@ -1,58 +0,0 @@
#!/bin/zsh
RED="\e[31m"
GREEN="\e[32m"
GRAY="\e[90m"
BOLD="\e[1m"
ENDCOLOR="\e[0m"
# List all installed apps
all_apps=(/Applications/*)
homebrew_apps=$(brew list --casks)
not_found_list=()
brew_available=()
for app in "${all_apps[@]}"; do
# Extract the name of the app without the path
app_name=$(basename "$app")
app_name="${app_name%.*}"
app_name=$(echo "$app_name" | tr '[:upper:]' '[:lower:]')
app_name=$(echo "$app_name" | tr " " -)
if [[ $app_name == "utilities" ]]; then continue; fi
echo -ne "${GRAY}Checking app: ${ENDCOLOR}${BOLD}$app_name${ENDCOLOR}${GRAY}...${ENDCOLOR}"
# Check if app is in homebrew list, if not print its name to terminal
echo $homebrew_apps | grep -wq $app_name
if [[ $? == 0 ]]; then
echo -e " ${GREEN}TRUE${ENDCOLOR}"
else
echo -e " ${RED}FALSE${ENDCOLOR}"
not_found_list+=($app_name)
# Check if app is available with brew
brew search --cask -q $app_name &>/dev/null | grep -x $app_name &>/dev/null
if [ $? -eq 0 ]; then
brew_available+=($app_name)
fi
fi
done
echo
echo "-------------------------------------"
echo
echo -e "${BOLD}Not installed with brew: ${ENDCOLOR}$not_found_list"
echo
echo -e "${BOLD}Available in brew: ${ENDCOLOR}$brew_available"
echo
if [[ ! -z $brew_available ]]; then
echo "-------------------------------------"
echo
echo -n "Replace the existing (available) apps with brew casks? (y/n): "
read replaceApps
if [[ $replaceApps == "y" ]]; then
for app in "${brew_available[@]}"; do
brew install --cask --force $app
done
fi
fi

199
scripts/p.sh Executable file
View File

@@ -0,0 +1,199 @@
#! /bin/bash
# Cross-distro package manager wrapper
source ~/dotfiles/scripts/color.sh
detectDistro() {
if [ "$(uname -s)" = "Darwin" ]; then
echo "macOS"
else
if [ "$(grep -Ei 'debian|buntu|mint' /etc/*release)" ]; then
echo "Debian"
elif [ "$(grep -Ei 'arch|manjaro|artix' /etc/*release)" ]; then
echo "Arch"
else
echo 1
fi
fi
}
oneline() {
# Print a command's output as a single line only.
# Example usage: for f in 'first line' 'second line' '3rd line'; do echo "$f"; sleep 1; done | oneline
local ws
while IFS= read -r line; do
if ((${#line} >= $COLUMNS)); then
# Moving cursor back to the front of the line so user input doesn't force wrapping
printf '\r%s\r' "${line:0:$COLUMNS}"
else
ws=$(($COLUMNS - ${#line}))
# by writing each line twice, we move the cursor back to position
# thus: LF, content, whitespace, LF, content
printf '\r%s%*s\r%s' "$line" "$ws" " " "$line"
fi
done
echo
}
p() (
distro=$(detectDistro)
update() {
if [[ $distro == "Arch" ]]; then
~/dotfiles/Linux/scripts/arch-maintenance.sh
elif [[ $distro == "Debian" ]]; then
~/dotfiles/Linux/scripts/debian-maintenance.sh
elif [[ $distro == "macOS" ]]; then
~/dotfiles/macOS/scripts/macos-maintenance.sh
else
echo -e "${RED}[E] System not supported.${ENDCOLOR}"
return 1
fi
}
check() {
nix_apps=$(nix-env -q)
if [[ $distro == "Debian" ]]; then
distro_apps=$(dpkg-query -l | grep '^ii' | awk '{print $2}')
elif [[ $distro == "Arch" ]]; then
distro_apps=$(pacman -Q)
else
distro_apps=""
fi
app_name=$(echo "$1" | tr '[:upper:]' '[:lower:]')
app_name=$(echo "$app_name" | tr " " -)
echo $nix_apps | grep -wq $app_name
nix_success=$?
if [[ $nix_success == 0 ]]; then
echo -e "${GREEN}Nix: $(echo $nix_apps | tr ' ' '\n' | grep -w $app_name)${ENDCOLOR}"
fi
echo $distro_apps | grep -Eq "(^|\s)$app_name($|\s)"
distro_success=$?
if [[ $distro_success == 0 ]]; then
echo -e "${GREEN}$distro: $(echo $distro_apps | tr ' ' '\n' | grep -E "(^|\s)$app_name($|\s)")${ENDCOLOR}"
fi
if [[ $nix_success == 0 && $distro_success == 0 ]]; then
return 2 #both
elif [[ $nix_success == 0 ]]; then
return 3 #nix
elif [[ $distro_success == 0 ]]; then
return 4 #distro
else
echo -e "${YELLOW}$app_name not installed.${ENDCOLOR}"
return 1
fi
# Get a list of all apps -> see if it's installed and print what installed it, and version.
}
if [[ $distro == "Debian" ]]; then
install="sudo apt-get install"
remove="sudo apt-get remove"
search="apt-cache search"
elif [[ $distro == "Arch" ]]; then
if pacman -Qs paru >/dev/null; then
install="paru -S"
remove="paru -R"
search="paru -Si"
else
install="sudo pacman -S"
remove="sudo pacman -R"
search="pacman -Ss"
fi
fi
# Install Nix.
if ! nix --version &>/dev/null; then
echo -e "${YELLOW}[E] Nix not found.${ENDCOLOR}"
echo -e "${GREEN}[+] Installing the Nix package manager...${ENDCOLOR}"
curl -L https://nixos.org/nix/install | sh
echo -e "${GREEN}[I] Installed Nix. Please reboot your device.${ENDCOLOR}"
return 2
fi
# If no parameter
if [ -z $1 ] || [ $1 = "u" ]; then
echo -e "${GREEN}[+] Running update script...${ENDCOLOR}"
update
echo -e "${GREEN}[+] Updating Nix...${ENDCOLOR}"
nix-env -u
return 0
elif [ $1 = "i" ]; then # If first parameter is i (install)
check $2
if [[ $? != 1 ]]; then
echo "$2 is already installed."
return 1
fi
nix search nixpkgs $2 --extra-experimental-features 'nix-command flakes' &>/dev/null
nix_found=$?
$search $2 &>/dev/null
distro_found=$?
if [[ $nix_found == 0 && $distro_found == 0 ]]; then
echo "1. Nix: $2 found."
echo "2. $distro: $2 found."
echo -n "Choose a package manager: "
read p_choice
if [[ $p_choice == 1 ]]; then
nix-env -iA nixpkgs.$2
elif [[ $p_choice == 2 ]]; then
$install $2
else
return 1
fi
return 0
fi
if [[ $nix_found == 0 ]]; then
nix-env -iA nixpkgs.$2
elif [[ $distro_found == 0 ]]; then
$install $2
else
echo "$2 not found."
return 1
fi
return 0
elif [ $1 = "r" ]; then # If first parameter is r (remove)
check $2
check_result=$?
if [[ $check_result == 2 ]]; then
echo "1. Nix: $2 installed."
echo "2. $distro: $2 installed."
echo -n "Choose a package manager: "
read p_choice
if [[ $p_choice == 1 ]]; then
nix-env -e $2
elif [[ $p_choice == 2 ]]; then
$remove $2
else
return 1
fi
return 0
fi
if [[ $check_result == 3 ]]; then
nix-env -e $2
elif [[ $check_result == 4 ]]; then
$remove $2
else
echo "$2 is not installed."
return 1
fi
return 0
elif [ $1 = "c" ]; then # If first parameter is c (check)
check $2
else
echo -e "${YELLOW}${UNDERLINE}[i] Usage:${ENDCOLOR}"
echo -e "p (u) ${FAINT}- update os${ENDCOLOR}"
echo -e "p i package ${FAINT}- install package${ENDCOLOR}"
echo -e "p r package ${FAINT}- remove package${ENDCOLOR}"
echo -e "p c package ${FAINT}- check if package is installed (true/false; 2 -> ERROR)${ENDCOLOR}"
return 1
fi
)