fish/aliases.fish

229 lines
12 KiB
Fish

#!/bin/fish
# ─< t stands for trash(-cli) >───────────────────────────────────────────────────────────
function _trash
if command -v trash >/dev/null 2>&1
alias rm="trash"
else
if command -v trash-cli >/dev/null 2>&1
alias rm="trash-cli"
else
red "You do not have trash or trash-cli installed! Your 'rm' will be permanent!"
end
end
end
# ─< colorized ls >─────────────────────────────────────────────────────────────────────────
# ─< lsd >──────────────────────────────────────────────────────────────────────────────────
if command -v lsd >/dev/null 2>&1
alias ls="lsd -l -1 -h1 --almost-all --git"
alias l="lsd -1"
alias ll="lsd -1 --almost-all"
alias tree="lsd --tree"
else
# ─< exa >──────────────────────────────────────────────────────────────────────────────────
if command -v exa >/dev/null 2>&1
alias ls="exa --icons --long --git"
alias l="exa --icons -l"
alias ll="exa --icons -laa"
alias tree="exa --icons -l -tree"
else
# ─< eza >──────────────────────────────────────────────────────────────────────────────────
if command -v eza >/dev/null 2>&1
alias ls="eza --icons --long --git"
alias l="eza --icons -l"
alias ll="eza --icons -laa"
alias tree="eza --icons -l -tree"
else
# ─< if nothing works -- plain old ls >─────────────────────────────────────────────────────
alias ls="ls --color=always -lAph"
alias l="ls --color=always -lph -w1"
alias ll="ls --color=always -lph"
end
end
end
alias clearl="command clear && l"
# ─< colored everything >───────────────────────────────────────────────────────────────────
alias ip="ip --color=always"
# ─< check for rg >─────────────────────────────────────────────────────────────────────────
if command -v rg >/dev/null 2>&1
alias grep="rg --color=always"
else
alias grep="grep --color=always"
end
# ─< weather >──────────────────────────────────────────────────────────────────────────────
alias www="curl wttr.in/Ulm"
# ─< linutil >────────────────────────────────────────────────────────────────────────────
alias linutil="curl -fsSL https://christitus.com/linux | sh"
# ─< telnet (starwars) >────────────────────────────────────────────────────────────────────
if command -v telnet >/dev/null 2>&1
alias starwars="telnet -a telehack.com"
end
# ─< rsync >────────────────────────────────────────────────────────────────────────────────
function _rsync
# Check if the 'find' command exists
if command -v find >/dev/null 2>&1
# Initialize the number of files to 0
set numbers 0
# Loop through all arguments except the last one (which is the destination)
for source in $argv[1..-2]
# Count the number of files in the source directory
set numbers (math $numbers + (find $source -type f | wc -l))
end
# Set the destination (last argument)
set destination $argv[-1]
# Set the color to magenta
set_color magenta
# Use rsync with pv for progress
rsync -avP --info=progress2 $argv[1..-2] $destination | pv -lpes $numbers
# Reset the color to normal
set_color normal
else
# If 'find' is not installed, display a warning message
echo "We could not find 'find'. Please install 'find' to enable the progress bar. (hit 'CTRL + C' to exit now)"
sleep 5
# Run rsync without progress bar
rsync -avP --info=progress2 $argv
end
end
if command -v rsync >/dev/null 2>&1
alias cp="_rsync"
alias scp="rsync -avP"
end
# ─< bat alias >────────────────────────────────────────────────────────────────────────────
if command -v batcat >/dev/null 2>&1
alias cat="batcat --color=always -p --paging=never"
alias less="batcat --paging always --color=always"
alias gd="batcat --diff"
end
# ─< batcat alias >─────────────────────────────────────────────────────────────────────────
if command -v bat >/dev/null 2>&1
alias cat="bat --color=always -p"
alias less="bat --paging always --color=always"
alias gd="bat --diff"
end
# ─< fastfetch >────────────────────────────────────────────────────────────────────────────
if command -v fastfetch >/dev/null 2>&1
alias ff="fastfetch"
alias clearff="command clear & fastfetch"
# ─< check for fastfetch module-existence >─────────────────────────────────────────────────
command fastfetch --config os >/dev/null 2>&1
# ─< check the status >─────────────────────────────────────────────────────────────────────
switch $status
case 0
alias f="fastfetch --config os"
# ─< unsuccessful, cloning repo >──────────────────────────────────────────────────────────
case '*'
git clone https://git.k4li.de/mirrors/fastfetch.git $HOME/.local/share/fastfetch >/dev/null 2>&1
# ─< execute fish to reinitialize aliases >────────────────────────────────────────────────
exec fish
end
clear & f
alias clear="clear & f"
end
# ─< calling the trash function, which will warn you if you don't have trash installed >──
_trash
# ─< set nmap-alias >───────────────────────────────────────────────────────────────────────
if command -v nmap >/dev/null 2>&1
alias scanvuln="sudo nmap --script vuln -vvv"
alias sv="scanvuln"
alias portscan="sudo nmap -sT"
alias ps="portscan"
end
# ─< t stands for tmux >────────────────────────────────────────────────────────────────────
if command -v tmux >/dev/null 2>&1
alias ts="tmux source $HOME/.tmux.conf"
alias t="tmux"
end
# ─< d stands for docker >──────────────────────────────────────────────────────────────────
if command -v docker >/dev/null 2>&1
alias up="docker compose up"
alias down="docker compose down"
alias pull="docker compose pull"
alias d="docker"
alias dr="docker run --rm -it"
alias ds="docker ps -a"
alias dc="docker compose"
alias appupdate="docker compose pull && docker compose up -d --force-recreate"
end
# ─< g stands for GIT >─────────────────────────────────────────────────────────────────────
if command -v git >/dev/null 2>&1
alias g="git"
alias gs="git status"
alias gm='git checkout main && git merge'
alias gc="git clone --recurse-submodule"
alias ga="git add"
alias gp="git pull --recurse-submodule"
alias gms='git maintenance start'
alias gsu="git pull --recurse-submodule && git submodule foreach git pull && git add . && git commit -m ' updated 📌submodules' && echo '-- Committed changes, pushing now..' && sleep 1 && git push"
alias gcm="git commit -m"
alias gpu="git push --recurse-submodule=on-demand"
if command -v lazygit >/dev/null 2>&1
alias lg="lazygit"
end
end
# ╭────────╮
# │ CODING │
# ╰────────╯
# ─< h stands for HUGO >──────────────────────────────────────────────────────────────────
if command -v hugo >/dev/null 2>&1
alias h='hugo'
alias hs='hugo server -D --noHTTPCache --disableFastRender'
end
# set IP (ip a | grep 'inet ' | grep -v '127.0.0.1' | awk '{print $2}' | cut -d/ -f1 | head -n 1)
function get_ip
command ip a | command grep 'inet ' | command grep -v '127.0.0.1' | command awk '{print $2}' | command cut -d/ -f1 | head -n 1
end
if command -v php >/dev/null 2>&1
alias phprun="php artisan serve --host=(get_ip) --port=8000"
end
if command -v npm >/dev/null 2>&1
alias npmrun="npm run dev -- --host=(get_ip) --port=8001"
end
# ─< c stands for bin/cake >──────────────────────────────────────────────────────────────
alias cake='bin/cake'
alias c='cake'
alias cs='c server -p 1313 --host=(get_ip)'
# ─< VSCodium >─────────────────────────────────────────────────────────────────────────────
if command -v codium >/dev/null 2>&1
alias code="codium"
set -e EDITOR
set -p EDITOR codium
end
# ─< neovide, the best frontend for any neovim-config >───────────────────────────────────
if test -d $HOME/.local/share/neovide/
if command -v neovide >/dev/null 2>&1
alias nvim='neovide --fork'
else
set -p neovide (bash -c 'find $HOME/ -name *neovide*.appimage' >/dev/null 2>&1) || exit 1
alias nvim="$neovide --fork"
end
end