more script adds

This commit is contained in:
xsghetti 2024-03-13 13:01:33 -04:00
parent a11d325a19
commit e1df303d71
15 changed files with 621 additions and 0 deletions

View file

@ -0,0 +1,45 @@
# ------------------------------------------- // System
com.github.tchx84.Flatseal # Flatseal
# org.gnome.Boxes # Boxes
# com.usebottles.bottles # Bottles
# io.github.dimtpap.coppwr # Coppwr
# ------------------------------------------- // Browser
com.brave.Browser # Brave
# org.torproject.torbrowser-launcher # Tor
# ------------------------------------------- // Social
# io.github.spacingbat3.webcord # Webcord
# dev.vencord.Vesktop # Vesktop
com.discordapp.Discord # Discord
org.signal.Signal # Signal
# ------------------------------------------- // Productivity
# md.obsidian.Obsidian # Obsidian
# org.mozilla.Thunderbird # Thunderbird
# io.github.alainm23.planify # Planify
# ------------------------------------------- // Image/Graphics
org.inkscape.Inkscape # Inkscape
org.kde.krita # Krita
org.gimp.GIMP # Gimp
org.blender.Blender # Blender
io.gitlab.theevilskeleton.Upscaler # ImageUpscaler
# ------------------------------------------- // Photography
# org.gnome.Shotwell # Shotwell
# org.darktable.Darktable # Darktable
# org.kde.digikam # Digikam
org.gnome.eog # ImageViewer
# ------------------------------------------- // Audio/Video
# com.spotify.Client # Spotify
# org.kde.kdenlive # Kdenlive
com.obsproject.Studio # Obs
com.github.rafostar.Clapper # Clapper
com.github.unrud.VideoDownloader # VideoDownloader
# ------------------------------------------- // Gaming
# hu.kramo.Cartridges # Cartridges
# com.github.Matoking.protontricks # ProtonTricks
# net.davidotek.pupgui2 # ProtonUp

34
Scripts/.extra/install_fpk.sh Executable file
View file

@ -0,0 +1,34 @@
#!/bin/bash
#|---/ /+-----------------------------------+---/ /|#
#|--/ /-| Script to install flatpaks (user) |--/ /-|#
#|-/ /--| Prasanth Rangan |-/ /--|#
#|/ /---+-----------------------------------+/ /---|#
BaseDir=`dirname "$(realpath "$0")"`
ScrDir=`dirname "$(dirname "$(realpath "$0")")"`
source $ScrDir/global_fn.sh
if [ $? -ne 0 ] ; then
echo "Error: unable to source global_fn.sh, please execute from $(dirname "$(realpath "$0")")..."
exit 1
fi
if ! pkg_installed flatpak
then
sudo pacman -S flatpak
fi
flatpak remote-add --user --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo
flats=`awk -F '#' '{print $1}' $BaseDir/custom_flat.lst | sed 's/ //g' | xargs`
flatpak install --user -y flathub ${flats}
flatpak remove --unused
GtkTheme=`gsettings get org.gnome.desktop.interface gtk-theme | sed "s/'//g"`
GtkIcon=`gsettings get org.gnome.desktop.interface icon-theme | sed "s/'//g"`
flatpak --user override --filesystem=~/.themes
flatpak --user override --filesystem=~/.icons
flatpak --user override --env=GTK_THEME=${GtkTheme}
flatpak --user override --env=ICON_THEME=${GtkIcon}

View file

@ -0,0 +1,80 @@
#!/bin/env bash
source global_fn.sh
if [ $? -ne 0 ]; then
echo "Error: unable to source global_fn.sh, please execute from $(dirname $(realpath $0))..."
exit 1
fi
hyprland_clone="$HOME/.cache/hyprdots/Hyprland-clone"
chk_aurh
if ! pkg_installed hyprland-git ; then
$aurhlpr ${use_default} -S hyprland-git || true
if ! pkg_installed hyprland-git ; then #? redunduncy
echo -e "\n\033[0;31mWARNING!!! READ ME!\033[0m"
cat << WARN
Hyprland installation failed!
Please check your internet connection and consider reporting the issue to your package manager's support.
For manual installation of Hyprland, you can proceed with this installation or follow the guide at https://wiki.hyprland.org/Getting-Started/Installation/ (Press any key to exit)
Note: This process is a work around.
Typically, it's recommended to use package managers for installations/updates as they handle the process more efficiently.
IMPORTANT: After installation with this method please be aware that you should install hyprland with your package manager if already available.
example: "$aurhlpr -Sy hyprland-git", or run ./install.sh again
The script will now attempt to:
1. Manually compile and install Hyprland.
2. Check and install any missing dependencies.
3. Clone Hyprland to $hyprland_clone
4. Execute [ make all && sudo make install ]
Please ensure you have sufficient permissions, internet connection and disk space for this operation.
WARN
echo ""
read -n 1 -s -r -p "[ENTER/SPACE:yes ANY:no] Do you want to proceed with the installation? " key
[[ -z "$key" ]] || exit 0
echo -e "\nChecking dependencies..."
dependencies=(gdb ninja gcc cmake meson libxcb xcb-proto xcb-util xcb-util-keysyms libxfixes libx11 libxcomposite xorg-xinput libxrender pixman wayland-protocols cairo pango seatd libxkbcommon xcb-util-wm xorg-xwayland libinput libliftoff libdisplay-info cpio tomlplusplus)
missing_dependencies=()
for dependency in "${dependencies[@]}"; do
if ! pkg_installed $dependency; then
missing_dependencies+=($dependency)
fi
done
if [ ${#missing_dependencies[@]} -gt 0 ]; then
echo "Missing dependencies: ${missing_dependencies[@]}"
echo "Installing missing dependencies..."
$aurhlpr ${use_default} -S ${missing_dependencies[@]}
fi
if cd "$hyprland_clone" 2>/dev/null; then
git fetch
if [ "$(git rev-parse HEAD)" != "$(git rev-parse @{u})" ]; then
echo "Changes are available in the remote repository. Pulling changes..."
git reset --hard
git clean -fd
git pull
else
if command -v Hyprland >/dev/null; then
echo -e "\033[1;33mLatest version of Hyprland is already compiled and installed!\033[0m"
exit 0
fi
fi
else
mkdir -p "$hyprland_clone"
git clone --recursive https://github.com/hyprwm/Hyprland "$hyprland_clone"
cd $hyprland_clone
fi
echo "Compiling Directory: $(pwd)"
make all && sudo make install
fi
else
echo -e "\033[0;32m[OK]\033[0m Hyprland"
fi

17
Scripts/.extra/install_mod.sh Executable file
View file

@ -0,0 +1,17 @@
#!/bin/bash
#|---/ /+-----------------------------------------------+---/ /|#
#|--/ /-| Script to enable early loading for nvidia drm |--/ /-|#
#|-/ /--| Prasanth Rangan |-/ /--|#
#|/ /---+-----------------------------------------------+/ /---|#
if [ `lspci -k | grep -A 2 -E "(VGA|3D)" | grep -i nvidia | wc -l` -gt 0 ] ; then
if [ `grep 'MODULES=' /etc/mkinitcpio.conf | grep nvidia | wc -l` -eq 0 ] ; then
sudo sed -i "/MODULES=/ s/)$/ nvidia nvidia_modeset nvidia_uvm nvidia_drm)/" /etc/mkinitcpio.conf
sudo mkinitcpio -P
if [ `grep 'options nvidia-drm modeset=1' /etc/modprobe.d/nvidia.conf | wc -l` -eq 0 ] ; then
echo 'options nvidia-drm modeset=1' | sudo tee -a /etc/modprobe.d/nvidia.conf
fi
fi
fi

View file

@ -0,0 +1,2 @@
/dev/sdb1
/dev/nvme0n1p1

71
Scripts/.extra/mnt_drives.sh Executable file
View file

@ -0,0 +1,71 @@
#!/bin/bash
#|---/ /+---------------------------+---/ /|#
#|--/ /-| Script to mount my drives |--/ /-|#
#|-/ /--| Prasanth Rangan |-/ /--|#
#|/ /---+---------------------------+/ /---|#
# function to check device parameters
chk_blk()
{
local BlkParm=$1
local MyDrive=$2
local ChkFlag=$3
BlkVal=`lsblk --noheadings --raw -o $BlkParm $MyDrive`
if [ ! -z $BlkVal ] && [ $ChkFlag == 'y' ] ; then
#echo "$MyDrive : $BlkParm is $BlkVal"
return 0
elif [ -z $BlkVal ] && [ $ChkFlag == 'n' ] ; then
#echo "$MyDrive : $BlkParm not available"
return 0
else
return 1
fi
}
ext_lab()
{
local MyMount=$1
local MyLabel=$2
local MyDrive=""
MyDrive=`findmnt --mountpoint $MyMount --noheadings -o source`
if [ `lsblk --noheadings --raw -o fstype $MyDrive` == "ext4" ] && chk_blk label $MyDrive n ; then
sudo e2label $MyDrive $MyLabel
fi
}
# main loop to mount listed partition
while read dev_part
do
if chk_blk uuid $dev_part y && chk_blk label $dev_part y && chk_blk mountpoint $dev_part n ; then
dev_label=`lsblk --noheadings --raw -o label $dev_part`
dev_uuid=`lsblk --noheadings --raw -o uuid $dev_part`
dev_fstype=`lsblk --noheadings --raw -o fstype $dev_part`
if [ ! -d /mnt/$dev_label ] ; then
sudo mkdir /mnt/$dev_label
echo "/mnt/$dev_label dir created..."
fi
if [ `grep $dev_uuid /etc/fstab | wc -l` -eq 0 ] ; then
fstEntry=`echo -e "${fstEntry}\n# $dev_part \nUUID=$dev_uuid /mnt/$dev_label \t$dev_fstype \t\tnosuid,nodev,nofail,x-gvfs-show \t 0 0\n "`
fi
sudo mount $dev_part /mnt/$dev_label
fi
done < mnt_drives.lst
echo -e "${fstEntry}\n" | sudo tee -a /etc/fstab
sudo systemctl daemon-reload
ext_lab '/home' '9S'
ext_lab '/' 'YoRHa'

84
Scripts/.extra/restore_app.sh Executable file
View file

@ -0,0 +1,84 @@
#!/bin/bash
#|---/ /+-----------------------------+---/ /|#
#|--/ /-| Script to configure my apps |--/ /-|#
#|-/ /--| Prasanth Rangan |-/ /--|#
#|/ /---+-----------------------------+/ /---|#
ScrDir=`dirname "$(dirname "$(realpath "$0")")"`
source $ScrDir/global_fn.sh
if [ $? -ne 0 ] ; then
echo "Error: unable to source global_fn.sh, please execute from $(dirname "$(realpath "$0")")..."
exit 1
fi
CloneDir=`dirname "$(realpath $CloneDir)"`
# icons
if [ -f /usr/share/applications/rofi-theme-selector.desktop ] && [ -f /usr/share/applications/rofi.desktop ]
then
sudo rm /usr/share/applications/rofi-theme-selector.desktop
sudo rm /usr/share/applications/rofi.desktop
fi
sudo sed -i "/^Icon=/c\Icon=adjust-colors" /usr/share/applications/nwg-look.desktop
sudo sed -i "/^Icon=/c\Icon=spectacle" /usr/share/applications/swappy.desktop
# steam
#if pkg_installed steam
# then
# skinsDir="${XDG_DATA_HOME:-$HOME/.local/share}/Steam/Skins/"
# if [ ! -d "$skinsDir" ]
# then
# mkdir -p "$skinsDir"
# fi
# tar -xzf ${CloneDir}/Source/arcs/Steam_Metro.tar.gz -C "$skinsDir"
#fi
# spotify
if pkg_installed spotify && pkg_installed spicetify-cli
then
if [ ! -w /opt/spotify ] || [ ! -w /opt/spotify/Apps ]; then
sudo chmod a+wr /opt/spotify
sudo chmod a+wr /opt/spotify/Apps -R
fi
spicetify &> /dev/null
mkdir -p ~/.config/spotify
touch ~/.config/spotify/prefs
sptfyConf=$(spicetify -c)
sed -i "/^prefs_path/ s+=.*$+= $HOME/.config/spotify/prefs+g" "${sptfyConf}"
tar -xzf ${CloneDir}/Source/arcs/Spotify_Sleek.tar.gz -C ~/.config/spicetify/Themes/
spicetify backup apply
spicetify config current_theme Sleek
spicetify config color_scheme Wallbash
spicetify apply
fi
# firefox
if pkg_installed firefox
then
FoxRel=$(find ~/.mozilla/firefox -maxdepth 1 -type d -name "*.default-release" | head -1)
if [ -z "${FoxRel}" ] ; then
firefox &> /dev/null &
sleep 1
FoxRel=$(find ~/.mozilla/firefox -maxdepth 1 -type d -name "*.default-release" | head -1)
else
BkpDir="${HOME}/.config/cfg_backups/$(date +'%y%m%d_%Hh%Mm%Ss')_apps"
mkdir -p "${BkpDir}"
cp -r ~/.mozilla/firefox "${BkpDir}"
fi
tar -xzf ${CloneDir}/Source/arcs/Firefox_UserConfig.tar.gz -C "${FoxRel}"
tar -xzf ${CloneDir}/Source/arcs/Firefox_Extensions.tar.gz -C ~/.mozilla/
find ~/.mozilla/extensions -maxdepth 1 -type f -name "*.xpi" | while read fext
do
firefox -profile "${FoxRel}" "${fext}" &> /dev/null &
done
fi

View file

@ -0,0 +1,16 @@
NV50|NV50|G80|GeForce 8800 (GTS, GTX, Ultra), Quadro FX (4600 (SDI), 5600)
NV50|NV84|G84|GeForce 8600 (GT, GTS, M GT, M GS), 8700M GT, GeForce 9500M GS, 9650M GS, Quadro FX (370, 570, 570M, 1600M, 1700), NVS 320M
NV50|NV86|G86|GeForce 8300 GS, 8400 (GS, M G, M GS, M GT), 8500 GT, GeForce 9300M G, Quadro FX 360M, NVS (130M, 135M, 140M, 290)
NV50|NV92|G92|GeForce 8800 (GT, GS, GTS 512, M GTS, M GTX), GeForce 9600 GSO, 9800 (GT, GTX, GTX+, GX2, M GT, M GTX), GeForce GTS 150(M), GTS 160M, GTS 240, GTS 250, GTX (260M, 280M, 285M), GT (330, 340), Quadro FX (2800M, 3600M, 3700, 3700M, 3800M, 4700 X2), VX 200
NV50|NV94|G94|GeForce 9600 (GSO 512, GT, S), 9700M GTS, 9800M GTS, GeForce G 110M, GT 130(M), GT 140, Quadro FX (1800, 2700M)
NV50|NV96|G96|GeForce 9400 GT, 9500 (GT, M G), 9600 (M GS, M GT), 9650M GT, 9700M GT, GeForce G 102M, GT 120, Quadro FX (380, 580, 770M, 1700M)
NV50|NV98|G98|GeForce 8400 GS, GeForce 9200M GS, 9300 (GE, GS, M GS), GeForce G 100, G 105M, Quadro FX (370 LP, 370M), NVS (150M, 160M, 295, 420, 450)
NV50|NVA0|GT200|GeForce GTX (260, 275, 280, 285, 295), Quadro CX, FX (3800, 4800, 5800)
NV50|NVA3|GT215|GeForce GT (240, 320, 335M), GTS (250M, 260M, 350M, 360M), Quadro FX 1800M
NV50|NVA5|GT216|GeForce GT (220, 230M, 240M, 325M, 330M), 315, Quadro 400, FX 880M, NVS 5100M
NV50|NVA8|GT218|GeForce 8400 GS, ION 2, GeForce 205, 210, G 210M, 305M, 310(M), 405, Quadro FX (380 LP, 380M), NVS (300, 2100M, 3100M)
NV50|NVAA|MCP77|GeForce 8100, 8200, 8300 mGPU
NV50|NVAA|MCP78|nForce 700a series, 8200M G
NV50|NVAC|MCP79|ION, GeForce 9300, 9400 mGPU
NV50|NVAC|MCP7A|nForce 700i series, 8200M G, 9100M, 9400M (G)
NV50|NVAF|MCP89|GeForce 320M

View file

@ -0,0 +1,9 @@
NVC0|NVC0|GF100|GeForce GTX (465, 470, 480, 480M), Quadro 4000, 5000[M] (??), 6000
NVC0|NVC1|GF108|GeForce GT (415M, 420, 420M, 425M, 430, 435M, 520M, 525M, 530, 540M, 550M, 555M, 620, 630M, 635M, 640M LE), Quadro 600, 1000M
NVC0|NVC3|GF106|GeForce GT (440, 445M, 545, 555M, 630M, 635M), GTS 450, GTX 460M, Quadro 2000 (D), 2000M
NVC0|NVC4|GF104|GeForce GTX (460, 460 SE, 470M, 485M), Quadro 5000M (??)
NVC0|NVC8|GF110|GeForce GTX (560 Ti OEM, 570, 580, 590), Quadro 3000M, 4000M, 5010M
NVC0|NVCE|GF114|GeForce GTX (460 v2, 560, 560 Ti, 570M, 580M, 670M, 675M)
NVC0|NVCF|GF116|GeForce GTS 450 v2, GTX (550 Ti, 560M)
NVC0|NVD7|GF117|Geforce GT 620M, 625M, (some) 630M, 710M, 720M
NVC0|NVD9|GF119|GeForce 410M, 510 (?), GT (520, 520M, 520MX, 610), 610M, Quadro NVS 4200M

View file

@ -0,0 +1,9 @@
NVE0|NVE4|GK104|GeForce GTX (660 Ti, 670[M], 680[M], 690, 760, 760 Ti, 770, 775M, 780M, 860M), Quadro K3000[M], K3100M, K4000[M], K4100[M], K5000[M], K5100M, Tesla K10
NVE0|NVE7|GK107|GeForce GT (640[M], 645M, 650M, 710M, 720M, 730M, 740[M], 745M, 750M, 755M), GTX (650, 660M), Quadro 410, K500[M], K600, K1000[M], K1100M, K2000[M], NVS 510, 1000
NVE0|NVE6|GK106|GeForce GTX (645, 650 Ti, 660, 760M, 765M, 770M), Quadro K2100M, K4000
NVE0|NVF0|GK110|GeForce GTX 780, Titan, Tesla K20, Quadro K6000
NVE0|NVF1|GK110B|GeForce GTX 780 Ti, Titan Z, Tesla K40
NVE0|NV106|GK208B|GeForce GT 720
NVE0|NV108|GK208|GeForce GT 630, 635, 640, 710M, 720M, 730M, 735M, 740M, 920M, Quadro K510M, K610M
NVE0|NVEA|GK20A|Tegra K1
NVE0|NV???|GK210|Tesla K80

View file

@ -0,0 +1,26 @@
NV110|NV117|GM107|GeForce GTX (745, 750, 750 Ti, 840M, 845M, 850M, 860M, 950M, 960M) Quadro K620, K1200, K2200, M1000M, M1200M; GRID M30, M40
NV110|NV118|GM108|GeForce 830M, 840M, 930M, 940M[X]
NV110|NV120|GM200|GeForce GTX Titan X
NV110|NV124|GM204|GeForce GTX (970, 980)
NV110|NV126|GM206|GeForce GTX (950, 960)
NV110|NV12B|GM20B|Tegra X1
NV130|NV132|GP102|NVIDIA Titan (X, Xp), GeForce GTX 1080 Ti
NV130|NV134|GP104|GeForce GTX (1070, 1080)
NV130|NV136|GP106|GeForce GTX 1060
NV130|NV137|GP107|GeForce GTX (1050, 1050 Ti)
NV130|NV138|GP108|GeForce GT 1030
NV140|NV140|GV100|NVIDIA Titan V, NVIDIA Quadro GV100
NV160|NV162|TU102|NVIDIA Titan RTX, GeForce RTX 2080 Ti
NV160|NV164|TU104|GeForce RTX (2070 Super, 2080, 2080 Super)
NV160|NV166|TU106|GeForce RTX (2060, 2060 Super, 2070)
NV160|NV168|TU116|GeForce GTX (1650 Super, 1660, 1660 Ti, 1660 Super)
NV160|NV167|TU117|GeForce GTX 1650
NV170|NV172|GA102|GeForce RTX (3080, 3090)
NV170|NV174|GA104|GeForce RTX (3060 Ti, 3070, 3080 Mobile)
NV170|NV176|GA106|GeForce RTX (3050, 3060)
NV170|NV177|GA107|GeForce RTX 3050
NV190|NV192|AD102|GeForce RTX 4090
NV190|NV193|AD103|GeForce RTX 4080
NV190|NV194|AD104|GeForce RTX (4070, 4070 Ti)
NV190|NV196|AD106|GeForce RTX 4060 Ti
NV190|NV197|AD107|GeForce RTX 4060

26
Scripts/.old/font_glyphs.sh Executable file
View file

@ -0,0 +1,26 @@
#!/bin/bash -
Usage() { echo "$0 FontFile"; exit 1; }
SayError() { local error=$1; shift; echo "$0: $@"; exit "$error"; }
[ "$#" -ne 1 ] && Usage
width=70
fontfile="$1"
[ -f "$fontfile" ] || SayError 4 'File not found'
list=$(fc-query --format='%{charset}\n' "$fontfile")
for range in $list
do IFS=- read start end <<<"$range"
if [ "$end" ] ; then
start=$((16#$start))
end=$((16#$end))
for((i=start;i<=end;i++)) ; do
printf -v char '\\U%x' "$i"
printf '%b' "$char"
done
else
printf '%b' "\\U$start"
fi
done | grep -oP '.{'"$width"'}'

65
Scripts/.old/install_v1.sh Executable file
View file

@ -0,0 +1,65 @@
#!/bin/bash
#|---/ /+--------------------------+---/ /|#
#|--/ /-| Main installation script |--/ /-|#
#|-/ /--| Prasanth Rangan |-/ /--|#
#|/ /---+--------------------------+/ /---|#
#--------------------------------#
# import variables and functions #
#--------------------------------#
source global_fn.sh
if [ $? -ne 0 ] ; then
echo "Error: unable to source global_fn.sh, please execute from $(dirname "$(realpath "$0")")..."
exit 1
fi
#----------------------#
# prepare package list #
#----------------------#
cp custom_hypr.lst install_pkg.lst
if [ -f "$1" ] && [ ! -z "$1" ] ; then
cat $1 >> install_pkg.lst
fi
#--------------------------------#
# add nvidia drivers to the list #
#--------------------------------#
if [ `lspci -k | grep -A 2 -E "(VGA|3D)" | grep -i nvidia | wc -l` -gt 0 ] ; then
cat /usr/lib/modules/*/pkgbase | while read krnl
do
echo "${krnl}-headers" >> install_pkg.lst
done
echo -e "nvidia-dkms\nnvidia-utils" >> install_pkg.lst
sed -i "s/^hyprland-git/hyprland-nvidia-git/g" install_pkg.lst
else
echo "nvidia card not detected, skipping nvidia drivers..."
fi
#--------------------------------#
# install packages from the list #
#--------------------------------#
./install_pkg.sh install_pkg.lst
#---------------------------#
# restore my custom configs #
#---------------------------#
./restore_fnt.sh
./restore_cfg.sh
./restore_sgz.sh
#------------------------#
# enable system services #
#------------------------#
service_ctl NetworkManager
service_ctl bluetooth
service_ctl sddm

32
Scripts/.old/restore_chk.sh Executable file
View file

@ -0,0 +1,32 @@
#!/bin/bash
#|---/ /+--------------------------------------+---/ /|#
#|--/ /-| Script to compare git and local dots |--/ /-|#
#|-/ /--| Prasanth Rangan |-/ /--|#
#|/ /---+--------------------------------------+/ /---|#
source global_fn.sh
if [ $? -ne 0 ] ; then
echo "Error: unable to source global_fn.sh, please execute from $(dirname "$(realpath "$0")")..."
exit 1
fi
CfgDir=`echo $CloneDir/Configs`
while read lst
do
pth=`echo $lst | awk -F '|' '{print $1}'`
cfg=`echo $lst | awk -F '|' '{print $2}'`
pth=`eval echo $pth`
echo "${cfg}" | xargs -n 1 | while read cfg_chk
do
tgt=`echo $pth | sed "s+^${HOME}++g"`
if [ `diff -qr --no-dereference ${pth}/$cfg_chk $CfgDir$tgt/$cfg_chk | wc -l` -gt 0 ]
then
echo "diff found ${pth}/$cfg_chk <--> $CfgDir$tgt/$cfg_chk"
fi
done
done < restore_conf.lst

View file

@ -0,0 +1,105 @@
#! /usr/bin/python3
# |---/ /+----------------------------------------+---/ /|#
# |--/ /-| Script to install pkgs from input list |--/ /-|#
# |-/ /--| Effibot |-/ /--|#
# |/ /---+----------------------------------------+/ /---|#
import argparse
# get reference to directories
# ZSH_FOLDER="/usr/share/oh-my-zsh"
import os
from os.path import exists, expanduser, isdir, join
# define folders
global ZSH_FOLDER
global ZSH_CUSTOM_PLUGINS
global WORKARAOUND
global RC_FILE
# those folders are hardcoded for now because the script is
# meant to be used with the configuration of main install script
ZSH_FOLDER = expanduser("/usr/share/oh-my-zsh")
ZSH_CUSTOM_PLUGINS = join(ZSH_FOLDER, "custom/plugins")
WORKARAOUND = False
RC_FILE = os.getenv('ZDOTDIR', default='') if os.getenv('ZDOTDIR', default='') != '' else expanduser(f"/home/{os.getlogin()}/.zshrc")
# this is a workaround string to be able to load the completion plugin manually
workaround = "fpath+=${ZSH_CUSTOM:-${ZSH:-/usr/share/oh-my-zsh}/custom}/plugins/zsh-completions/src"
def get_plugin_list(input_file):
# read the input file
with open(input_file, "r") as f:
plugin_list = [line.strip() for line in f.readlines()]
if "zsh-completions" in plugin_list:
WORKARAOUND = True
return plugin_list
def generate_plugin_block(plugin_list):
"""generate the line for the .zshrc file to load the plugins"""
line = "plugins=("
to_download = []
for plugin in plugin_list:
# checks if the plugin comes from a git repo
if plugin.startswith("http"):
# if it does, append it to the list of plugins to download
to_download.append(plugin)
# get the name of the plugin and append it to the line
plugin_name = plugin.split("/")[-1].split(".")[0]
line += f"{plugin_name} "
else:
# if not, it is assumed that the plugin is in the default plugin folder
line += f"{plugin} "
line += ")\n"
return line, to_download
def download_plugins(to_download):
"""downloads the plugins from the list of plugins"""
for plugin in to_download:
plugin_name = plugin.split("/")[-1].split(".")[0]
plugin_folder = join(ZSH_CUSTOM_PLUGINS, plugin_name)
if not exists(plugin_folder) and not isdir(plugin_folder):
# os.makedirs(plugin_folder)
print(f"Downloading plugins: {plugin_name} from {plugin}")
os.system(f"git clone {plugin} {plugin_folder}")
else:
print(f"Plugin {plugin_name} already exists")
def main(input_file) -> None:
print("\nInstalling ZSH plugins\n")
# get the list of plugins
plugin_list = get_plugin_list(input_file)
# generate the line to be added to the .zshrc file
plugin_line, to_download = generate_plugin_block(plugin_list)
print(f"Your desired plugins are: {plugin_line}")
if WORKARAOUND:
print("Workaround is needed to load the completion plugin")
plugin_line += workaround + "\n"
# download the plugins
download_plugins(to_download)
# add the line to the .zshrc file
updated_line = ""
print(f"rc file is {RC_FILE}")
try:
with open(RC_FILE, "r") as f:
# search for the line that loads the plugins
f_content = f.read()
updated_line = f_content.replace("plugins=(git)", plugin_line)
with open(RC_FILE, "w") as g:
g.write(updated_line)
print("Plugin list updated")
except FileNotFoundError:
print("File not found")
except IOError as e:
print(f"IO error -> {e}")
if __name__ == "__main__":
parser = argparse.ArgumentParser("Input file containing list of plugins")
parser.add_argument("-f", help="Input file containing list of plugins")
input_file = parser.parse_args().f
main(input_file)