.files/.bashrc

104 lines
2.3 KiB
Bash

# Source other files
[ -r ~/.prompt ] && . ~/.prompt
[ -r ~/.devspec ] && . ~/.devspec
[ -r ~/.config/isotope.dark ] && . ~/.config/isotope.dark
# History stuff
export HISTCONTROL=ignoredups:erasedups
export HISTFILESIZE=1000
export HISTSIZE=1000
export GPG_TTY=$(tty)
# We hate sudo here
alias sudo='sh -c "exit 1"'
# Other aliases
alias clear="printf '\033c'" # faster than ncurses clear by a lot
alias c='clear'
alias ls='ls --color=auto -FAh'
alias ll='ls -l'
alias rebash='. ~/.bashrc'
alias bashrc="$EDITOR ~/.bashrc && rebash"
alias nf='neofetch'
alias sshd='boas /usr/sbin/sshd'
alias ga='git add'
alias gc='git commit -sS'
alias gp='git push'
alias wv='mpv $($PASTE_COMMAND)'
alias lc='fc -nl $HISTCMD'
alias curl='curl -L'
# Completions for elevation program (https://codeberg.org/Bowuigi/Unit21 in management/boas)
complete -cf boas
# Random string (passwords)
randstr() {
tr -cd '[:graph:]' </dev/urandom | head -c ${1:-256}
}
# Get CPU usage
cpusage() {
bc<<<"scale=3;$(ps aux | awk 'BEGIN {sum=0} {sum+=$3}; END {print sum}') / $(nproc --all)"
}
# Update and upgrade system
update() { boas sh -c "$UPDATE"; }
# Im too lazy to type
copy() {
printf "%s" "$(</dev/stdin)" > >($COPY_COMMAND)
}
# URL-encode stdin
urlencode() {
LC_COLLATE_OLD=$LC_COLLATE
LC_COLLATE=C
local TEXT="$(</dev/stdin)"
local LENGTH="${#TEXT}"
for (( i = 0; i < LENGTH; i++ )); do
local c="${TEXT:$i:1}"
case $c in
[a-zA-Z0-9.~_-]) printf '%s' "$c" ;;
*) printf '%%%02X' "'$c" ;;
esac
done
LC_COLLATE=$LC_COLLATE_OLD
}
diffhome() { find . -type f -regex '\./\.[^g].*' -exec diff -q ~/{} {} 2> /dev/null \;; }
fixdh() {
diffhome | while read -r _ SRC _ DEST _; do
cp $SRC $DEST;
done;
}
strlen() {
N=$(wc -c <<< "$*")
((N--))
printf '%u\n' "$N"
}
uppweb() {
pushd ~/git/cobra.vern.cc
local DIR="/home/cobra/git/cobra.vern.cc"
rsync -rtvzP --exclude ".git" --exclude ".gitignore" --exclude 'README.md' --exclude 'LICENSE' $DIR/* vern.cc:~/public_html/
popd
}
upvweb() {
pushd ~/git/website
rsync --rsh='ssh -p1813' -rtvzP --exclude '.git' --exclude 'LICENSE' /home/cobra/git/website/ root@vern.cc:/var/www/website
popd
}
upvgem() {
pushd ~/git/gemini
rsync --rsh='ssh -p1813' -rtvzP --exclude '.git' --exclude 'LICENSE' /home/cobra/git/gemini/ root@vern.cc:/home/gemini/gemini/vern.cc
popd
}
pubdate() {
date +'%a, %d %b %Y %T %z'
}