fish/init/setup.fish
2024-06-07 11:22:09 +02:00

243 lines
12 KiB
Fish

# ─────────────< Check for packagemanager and alias everything for easy use :) >───────────
function upin
# ─< check for sudo/root >──────────────────────────────────────────────────────────────────
if [ $USER = "root" ]
set su ""
else
if command -v sudo >/dev/null 2>&1
set su "sudo"
end
end
# ─────────────────────────< START | distro/packagemanger detection >─────────────────────────
# ─< DNF - Fedora >─────────────────────────────────────────────────────
if command -v dnf
set pkg "$su dnf"
set install "$pkg install"
set update "$pkg update && $pkg upgrade"
set search "$pkg search"
set remove "$pkg remove"
set unattendet "$pkg install -y"
end
# ─< APT/NALA - Debian >────────────────────────────────────────────────
if command -v nala >/dev/null 2>&1
set pkg "$su nala"
set install "$pkg update && $pkg install"
set update "$pkg update && $pkg upgrade"
set search "$pkg search"
set remove "$pkg remove"
set unattendet "$pkg install --assume-yes"
else
if command -v apt-get >/dev/null 2>&1
set pkg "$su apt-get"
set install "$pkg update && $pkg install"
set update "$pkg update && $pkg upgrade"
set search "$pkg search"
set remove "$pkg remove"
set unattendet "$pkg install --assume-yes"
end
end
# ─< Pacman - Arch >────────────────────────────────────────────────────
if command -v paru >/dev/null 2>&1
set pkg "paru"
set install "$pkg -S"
set update "$pkg -Syu"
set search "$pkg -Ss"
set remove "$pkg -R"
set unattendet "$pkg install --noconfirm"
else
if command -v yay >/dev/null 2>&1
set pkg "yay"
set install "$pkg -S"
set update "$pkg -Syu"
set search "$pkg -Ss"
set remove "$pkg -R"
set unattendet "$pkg install --noconfirm"
else
if command -v pacman >/dev/null 2>&1
set pkg "$su pacman"
set install "$pkg -S"
set update "$pkg -Syu"
set search "$pkg -Ss"
set remove "$pkg -R"
set unattendet "$pkg install --noconfirm"
end
end
end
# ─< Zypper - OpenSuse >────────────────────────────────────────────────────────────────────
if command -v zypper >/dev/null 2>&1
set pkg "$su zypper"
set install "$pkg in"
set update "$pkg dup"
set search "$pkg se"
set remove "$pkg rm"
alias lock="$pkg al"
set unattendet "$pkg install --non-interactive"
end
# ─< APK - Alpine >─────────────────────────────────────────────────────────────────────────
if command -v apk >/dev/null 2>&1
set pkg "$su apk"
set install "$pkg add"
set update "$pkg update"
set search "$pkg search"
end
if set -q unattendet
set -U FISH_INSTALL $unattendet
else
set -U FISH_INSTALL $install
end
if test -n "$install"
set vars "install" "update" "search" "remove"
for env in $vars
if not test -z "$env"
alias "$env"="$$env"
end
end
end
end
# ╭──────────────────────────────────────────────────────────────────────────────────────────────────────╮
# │ FUNCTION: Define function gsa (to ask the user which submodule to clone to which path and which name │
# ╰──────────────────────────────────────────────────────────────────────────────────────────────────────╯
function gsa
set dir $PWD
echo "-- these are the current submodules --"
if command -v rg >/dev/null 2>&1
echo "-- for $dir --"
rg -i submodule (echo $dir/.gitmodules)
else
if command -v grep >/dev/null 2>&1
echo "-- for $dir --"
grep -i submodule (echo $dir/.gitmodules)
else
echo "-- no 'grep' or 'rg' found.. your okay?? --"
end
end
# ─< Prompt the user to enter the repository URL to add as a submodule >────────────────────
echo "-- enter the repository to add as a submodule --"
echo "-- (type 'quit' to quit) --"
read repo
if [ "$repo" = "quit" ]
exit 1
end
# ─< Prompt the user to enter the relative path where the submodule will be cloned >────────
# ─< Advise not to use the leading / or ./ >────────────────────────────────────────────────
echo "-- enter the relative path, where the submodule will be cloned to. (!! do it like this: ./path/to/clone/to) --"
echo "-- (type 'quit' to quit) --"
read -S path
if [ "$path" = "quit" ]
exit 1
end
# ─< Prompt the user to enter the branch to checkout (e.g., main, master) >─────────────────
echo "-- enter the branch to checkout (main/master..) --"
echo "-- (type 'quit' to quit) --"
read branch
if [ "$branch" = "quit" ]
exit 1
end
echo "-- enter a name for the submodule --"
echo "-- (type 'quit' to quit) --"
read -l name
if [ "$name" = "quit" ]
exit 1
end
# ─< Ask the user for confirmation if the constructed command looks correct >───────────────
echo "git submodule add --branch $branch --name $name $repo $path"
echo "-- does this command look right to you? [y/n] --"
read -l comm
# ─< Switch statement to handle the user's confirmation input >─────────────────────────────
switch $comm
# ─< If the user inputs 'y' or 'Y', execute the git submodule add command >─────────────────
case 'y' 'Y'
git submodule add --branch $branch --name $name $repo $path
git submodule update --init --recursive
git add .
git commit -m "Addet $name as a submodule"
git push
# ─< If the user inputs 'n' or 'N', notify them to try again >──────────────────────────────
case 'n' 'N'
echo "-- all right, just try again :) --"
end
end
# ╭───────────────────────────────────────────────────╮
# │ FUNCTION: set tmux command to always work with ta │
# ╰───────────────────────────────────────────────────╯
if command -v tmux >/dev/null 2>&1
set tmux_y "tmux-session active!"
set tmux_n "No tmux-session found!"
function ta
command tmux list-sessions >/dev/null 2>&1
switch $status
case 0
if command -v notify-send >/dev/null 2>&1
notify-send "$tmux_y"
end
echo "$tmux_y"
sleep 0.5
tmux a
case '*'
if command -v notify-send >/dev/null 2>&1
notify-send "$tmux_n"
end
echo "No Tmux session found. Creating one now! --"
sleep 0.5
tmux
end
end
end
# ╭────────────────────────────────────────────╮
# │ FUNCTION: check fisher plugin dependencies │
# ╰────────────────────────────────────────────╯
function dep_fisher
# ─< Define dependencies for the plugins used by fisher >───────────────────────────────────
set dependencies "fzf" "btop" "fastfetch" "curl" "wget" "cmatrix"
# ─< Check and install dependencies >───────────────────────────────────────────────────────
for dep in $dependencies
if not command -v $dep >/dev/null 2>&1
echo "Dependency $dep is not installed. Installing..."
if test -n "$FISH_INSTALL"
alias fish_install="$FISH_INSTALL"
fish_install $dep
else
echo "FISH_INSTALL is not defined: $FISH_INSTALL | Please install $dep manually."
end
end
end
end
# ╭───────────────────────────────────────────────────────╮
# │ FUNCTION: check for fisher and install if not present │
# ╰───────────────────────────────────────────────────────╯
function check_fishr
if test -e $HOME/.config/fish/.fishr.init
fisher update
else
if test ! -e $HOME/.config/fish/functions/fisher.fish
echo "you did it!!"> $HOME/.config/fish/.fishr.init && curl -sL https://raw.githubusercontent.com/jorgebucaran/fisher/main/functions/fisher.fish | source & fisher install jorgebucaran/fisher
end
end
end
# ────────────────────────────────────< setup some stuff >────────────────────────────────────
upin
dep_fisher
#check_fishr