Files
lnx-arch/dots/bash/.bashrc
T

512 lines
13 KiB
Bash
Raw Normal View History

2024-05-03 13:52:41 -05:00
#
2025-04-12 11:49:58 -05:00
# ~/.bashrc :: by frode klevstul
2024-05-03 13:52:41 -05:00
#
2026-06-02 09:23:17 -05:00
# if not running interactively, don't do anything
[[ $- != *i* ]] && return
2025-04-12 11:49:58 -05:00
# ---
2026-06-02 09:23:17 -05:00
# shell integrations
2025-04-12 11:49:58 -05:00
# ---
# https://github.com/gsamokovarov/jump
eval "$(jump shell --bind=j)"
2026-02-27 13:28:03 -05:00
# https://github.com/ajeetdsouza/zoxide
eval "$(zoxide init bash)"
2026-01-13 09:33:57 -05:00
2026-06-02 09:23:17 -05:00
# ---
# prompt
# ---
# https://bash-prompt-generator.org/
PS1='\[⚙\][\D{%y%m%d%H%M}|\u@\h|\w]\$ '
# change the window title of x terminals
case ${TERM} in
xterm*|rxvt*|Eterm*|aterm|kterm|gnome*|interix|konsole*)
PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/\~}\007"'
;;
screen*)
PROMPT_COMMAND='echo -ne "\033_${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/\~}\033\\"'
;;
esac
2025-04-12 11:49:58 -05:00
# ---
# environment variables
# ---
# see `dots/environment/environment`
# ---
2026-06-02 09:23:17 -05:00
# aliases : system
2025-04-12 11:49:58 -05:00
# ---
2025-03-29 05:22:52 -05:00
2025-08-05 10:00:15 -05:00
alias cp="cp -i" # confirm before overwriting something
alias df='df -h' # human-readable sizes
2025-04-21 07:08:35 -05:00
alias du="du --summarize --human-readable"
alias dus="du --summarize --human-readable * | sort -h"
2025-04-06 18:22:35 -05:00
alias grep='grep --color=auto'
2026-06-02 09:23:17 -05:00
alias ls='ls --color=auto'
alias tree="tree --du -h"
# ---
# aliases : files & disk
# ---
alias biggestfiles="find ~ -type f -exec du -h {} + 2>/dev/null | sort -hr | head -n 20"
alias diskusage="ncdu -x"
alias dragon="dragon-drop --and-exit --all --print-path"
alias extract="extract.sh"
alias sizeInBytes="stat -c %s"
alias zipr='zip -r "$1" . -x "$1"'
# ---
# aliases : trash
# ---
alias tp="tp.sh"
alias tp-empty="trash-put /dev/null; trash-empty; gio trash --empty" # fixed: was recursive
alias tp-list="tree ~/.local/share/Trash/"
alias tp-restore="trash-restore"
# ---
# aliases : networking
# ---
2026-03-11 10:18:45 -05:00
alias ipadr='ip -br a'
2025-12-16 09:05:35 -05:00
alias ipify='http https://api.ipify.org?format=json'
2025-06-02 18:11:07 -05:00
alias journal='journalctl --since "1 hour ago"'
2026-06-02 09:23:17 -05:00
alias ssh="ssh -v"
alias ssh_weba_r="ssh -t root@weba -p 1808 'export TERM=xterm; cd /tmp; bash -l'"
alias ssh_weba_u="ssh -t usr@weba -p 1808 'export TERM=xterm; cd /tmp; bash -l'"
# ---
# aliases : applications
# ---
alias azurevpnclient="/opt/microsoft/microsoft-azurevpnclient/microsoft-azurevpnclient"
alias ct="sudo ct"
alias decrypt="gpg --decrypt"
alias dragon="dragon-drop --and-exit --all --print-path"
alias encrypt="gpg --encrypt --sign --recipient frode@klevstul.com"
alias gparted="sudo gparted"
alias ipcam="ffplay rtsp://192.168.31.220:554/1"
2025-04-08 14:55:30 -05:00
alias keyringreset="trash-put /home/poq/.local/share/keyrings/*.keyrings"
2025-12-16 09:05:35 -05:00
alias neofetch='fastfetch'
2026-01-06 11:58:01 -05:00
alias quantumfix="pw-metadata -n settings 0 clock.force-quantum 1024"
2025-04-25 09:33:13 -05:00
2026-06-02 09:23:17 -05:00
# ---
# aliases : hyprland
# ---
alias hyprRld="hyprctl reload"
alias hyprUpd="sudo ct d h && hyprRld"
# ---
# aliases : app images
# ---
2026-01-18 18:10:44 -05:00
alias pgmodeler="/home/poq/syncDir/swas/portableApps/pgmodeler_plus-1*"
2026-06-02 09:23:17 -05:00
alias pgmodeler2="/home/poq/syncDir/swas/portableApps/pgmodeler_plus-2*"
2025-03-29 05:22:52 -05:00
2026-01-13 09:33:57 -05:00
2025-04-12 11:49:58 -05:00
# ---
2026-06-02 09:23:17 -05:00
# aliases : bash
2025-04-12 11:49:58 -05:00
# ---
2026-06-02 09:23:17 -05:00
alias sb="unalias -a; source ~/.bashrc"
alias sbr="unalias -a; source /home/poq/syncDir/repos/git/gi.op.fo/lnx-arch/dots/bash/.bashrc"
2024-05-03 13:52:41 -05:00
2026-06-02 09:23:17 -05:00
# ---
# aliases : nas mounting
# ---
alias nas-mount="nas mount 192.168.31.77"
alias nas-umount="nas umount"
2025-03-29 05:22:52 -05:00
2024-05-05 22:04:57 -05:00
2026-02-27 11:27:25 -05:00
# ---
2026-06-02 09:23:17 -05:00
# functions : networking
2026-02-28 22:01:55 -05:00
# ---
2026-06-02 09:23:17 -05:00
myip() {
wget http://ipinfo.io/ip -qO -
echo
}
nmrestart() {
systemctl restart NetworkManager
systemctl status NetworkManager
}
# ---
# functions : file managers
2026-02-27 13:21:01 -05:00
# ---
2026-06-02 09:23:17 -05:00
# lf (change directory on quit)
2026-02-27 13:21:01 -05:00
lf() {
2026-06-02 09:23:17 -05:00
local tmp
tmp=$(mktemp)
command lf -last-dir-path="$tmp" "$@"
2026-02-27 13:21:01 -05:00
if [[ -f "$tmp" ]]; then
2026-06-02 09:23:17 -05:00
local dir
dir=$(cat "$tmp")
2026-02-27 13:21:01 -05:00
rm -f "$tmp"
if [[ -d "$dir" && "$dir" != "$(pwd)" ]]; then
cd "$dir"
fi
fi
}
# superfile (change directory on quit)
2026-02-27 11:27:25 -05:00
spf() {
2026-06-02 09:23:17 -05:00
local SPF_LAST_DIR="${XDG_STATE_HOME:-$HOME/.local/state}/superfile/lastdir"
command spf "$@"
if [[ -f "$SPF_LAST_DIR" ]]; then
source "$SPF_LAST_DIR"
rm -f "$SPF_LAST_DIR"
2026-02-27 11:27:25 -05:00
fi
2026-06-02 09:23:17 -05:00
}
2026-02-27 11:27:25 -05:00
2026-06-02 09:23:17 -05:00
# ---
# functions : nas
# ---
nas() {
if [[ ! -e "/mnt/nas" ]]; then
sudo mkdir -p "/mnt/nas" "/mnt/nas-fam"
elif [[ ! -d "/mnt/nas" ]] || [[ ! -d "/mnt/nas-fam" ]]; then
echo "'/mnt/nas' and/or '/mnt/nas-fam' exist, but is not a directory" >&2
return 1
fi
case "$1" in
umount|unmount)
echo "umount /mnt/nas & /mnt/nas-fam"
sudo umount -l /mnt/nas
sudo umount -l /mnt/nas-fam
;;
mount)
if [[ -z "$2" ]]; then
echo "missing ip address. try: 'nas mount <ip>'" >&2
return 1
fi
echo "mount /mnt/nas & /mnt/nas-fam"
local creds=/home/poq/syncDir/secrets/nas/lillesorteboks.txt
local opts="credentials=${creds},iocharset=utf8,noperm"
sudo mount -t cifs -o "$opts" "//$2/fro" /mnt/nas
sudo mount -t cifs -o "$opts" "//$2/fam" /mnt/nas-fam
tree -L 2 /mnt/nas
tree -L 2 /mnt/nas-fam
;;
*)
echo "usage: nas {mount <ip>|umount}" >&2
return 1
;;
esac
2026-02-27 11:27:25 -05:00
}
2025-05-09 17:42:59 -05:00
# ---
2026-06-02 09:23:17 -05:00
# functions : multimedia
2025-05-09 17:42:59 -05:00
# ---
2026-01-13 09:33:57 -05:00
2026-06-02 09:23:17 -05:00
# https://itsfoss.com/compress-pdf-linux/
pdfCompress() {
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.5 -dPDFSETTINGS=/ebook \
-dNOPAUSE -dQUIET -dBATCH -sOutputFile="$1.compressed.pdf" "$1"
2026-05-08 12:13:26 -05:00
}
2026-06-02 09:23:17 -05:00
# https://stackoverflow.com/questions/8933053/check-duration-of-audio-files-on-the-command-line
lengthInSeconds() {
ffprobe -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 "$1" 2>/dev/null
}
# ---
# functions : misc
# ---
2026-05-24 07:48:09 -05:00
generate_password() {
2026-06-02 09:23:17 -05:00
local length=30
local chars='A-Za-z0-9!@#$%^&*()_+[]{}|;:,.<>?'
tr -dc "$chars" < /dev/urandom | head -c "$length"
echo
2026-05-24 07:48:09 -05:00
}
2026-02-28 21:56:08 -05:00
randoms() {
echo "----------"
2026-06-02 09:23:17 -05:00
local ranwrd1 ranwrd2 rancmd randnum randalp
2026-02-28 21:56:08 -05:00
ranwrd1=$(shuf -n 1 /usr/share/dict/cracklib-small)
ranwrd1="${ranwrd1//[^[:alpha:]]/}"
ranwrd2=$(shuf -n 1 /usr/share/dict/cracklib-small)
ranwrd2="${ranwrd2//[^[:alpha:]]/}"
rancmd=$(compgen -ac | shuf -n 1)
randnum=$(( 1000 + SRANDOM % 9000 ))
2026-06-02 09:23:17 -05:00
randalp=$(tr -dc 'a-zA-Z0-9' < /dev/urandom | head -c 10)
2026-02-28 21:56:08 -05:00
echo "w1: ${ranwrd1} | w2: ${ranwrd2} | c: ${rancmd} | n: ${randnum} | a: ${randalp}"
2026-06-02 09:23:17 -05:00
echo "s0: ${randnum} ${ranwrd1} ${ranwrd2} ${rancmd} ${randalp}"
echo "s1: ${randnum}_${ranwrd1}_${ranwrd2}_${rancmd}_${randalp}"
echo "s2: ${randnum}${ranwrd1}${ranwrd2}${rancmd//[^[:alpha:]]/}${randalp}"
echo "s3: $(generate_password)"
2026-02-28 21:56:08 -05:00
echo "----------"
}
2026-06-02 09:17:48 -05:00
quick_hours() {
local location=$1
local balance=$2
local worked=$3
local target=450 # 7:30 in minutes
local hours minutes worked_minutes
hours="${worked%%:*}"
minutes="${worked##*:}"
worked_minutes=$(( 10#$hours * 60 + 10#$minutes ))
local new_balance=$(( balance + worked_minutes - target ))
echo "[@${location} ${new_balance}]"
}
2026-02-28 21:56:08 -05:00
2026-02-28 22:01:55 -05:00
# ---
2026-06-02 09:23:17 -05:00
# functions : searching
2026-02-28 22:01:55 -05:00
# ---
2026-06-02 09:23:17 -05:00
# find a file (faf)
faf() {
local path="${2:-.}"
find "$path" -type f -iname "$1" 2>/dev/null
2026-02-28 22:01:55 -05:00
}
2026-06-02 09:23:17 -05:00
# find in file (fif)
# https://stackoverflow.com/questions/16956810/find-all-files-containing-a-specific-text-string-on-linux
fif() {
local path="${2:-.}"
grep -rnw "$path" -e "$1" 2>/dev/null
2026-02-28 22:01:55 -05:00
}
2026-02-28 21:56:08 -05:00
# ---
2026-06-02 09:23:17 -05:00
# functions : rotate / encode
2026-02-28 21:56:08 -05:00
# ---
2026-06-02 09:23:17 -05:00
decimal_to_base36() {
local BASE36=($(echo {0..9} {A..Z}))
for i in $(bc <<< "obase=36; $1"); do
echo -n "${BASE36[$(( 10#$i ))]}"
done
echo
2025-10-31 05:51:19 -05:00
}
decimal_to_base36_wrap() {
2026-06-02 09:23:17 -05:00
decimal_to_base36 $(( $1 % 36 ))
}
2025-08-24 08:26:31 -05:00
rot() {
local shift=$1
local text=$2
local alpha=abcdefghijklmnopqrstuvwxyz
if [[ -z $shift || -z $text ]]; then
2026-06-02 09:23:17 -05:00
echo "usage: rot <shift> <text>"
return 1
2025-08-08 07:27:45 -05:00
fi
2026-06-02 09:23:17 -05:00
local n=$(( (shift % 26 + 26) % 26 ))
local rotated="${alpha:n}${alpha:0:n}"
echo "$text" | tr "a-z" "$rotated"
2025-08-08 06:41:48 -05:00
}
2025-08-24 08:26:31 -05:00
rotl() {
2026-06-02 09:23:17 -05:00
local input=$1
if [[ -z "$input" ]]; then return 1; fi
2025-08-08 07:27:45 -05:00
2026-06-02 09:23:17 -05:00
local size=${#input}
if (( size > 25 && size < 51 )); then # fixed: was string comparison
size=$(( size - 25 ))
fi
2025-08-27 19:58:08 -05:00
2026-06-02 09:23:17 -05:00
if [[ -n $2 ]]; then
rot "$size" "$input"
else
{ echo "rot +$size: "; rot "$size" "$input"; } | tr "\n" " "
echo
{ echo "rot -$size: "; rot "-$size" "$input"; } | tr "\n" " "
echo
2025-08-24 08:26:31 -05:00
fi
}
2025-08-08 06:41:48 -05:00
2025-08-27 19:58:25 -05:00
rote() {
2026-06-02 09:23:17 -05:00
local input="${1//./}"
_rote_encode "$input"
2025-10-31 05:51:19 -05:00
}
2026-06-02 09:23:17 -05:00
_rote_encode() {
local input=$1
if [[ -z "$input" ]]; then return 1; fi
2025-08-27 19:58:08 -05:00
2026-06-02 09:23:17 -05:00
local year month day
year=$(decimal_to_base36_wrap "$(date +%y)")
month=$(decimal_to_base36 "$(date +%m)")
day=$(decimal_to_base36 "$(date +%d)")
2025-10-31 05:51:19 -05:00
2026-06-02 09:23:17 -05:00
local datestamp
datestamp=$(echo "${year}${month}${day}_" | tr '[A-Z]' '[a-z]')
2025-10-31 05:51:19 -05:00
2026-06-02 09:23:17 -05:00
local rotl_result
rotl_result=$(rotl "$input" 0)
2026-06-02 09:23:17 -05:00
echo "${datestamp}${rotl_result}@reduxmail.com"
2025-08-27 19:58:08 -05:00
}
2025-05-09 17:42:59 -05:00
drote() {
local email="$1"
2026-05-22 05:51:59 -05:00
local local_part="${email%@reduxmail.com}"
local ds="${local_part%%_*}"
local encoded="${local_part#*_}"
_b36_to_dec() {
2026-06-02 09:23:17 -05:00
local c="${1,,}"
2026-05-22 05:51:59 -05:00
if [[ "$c" =~ [0-9] ]]; then
echo "$c"
else
printf "%d" $(( $(printf '%d' "'$c") - 87 ))
fi
}
2026-06-02 09:23:17 -05:00
local yy mm dd
2026-05-22 05:51:59 -05:00
yy=$(_b36_to_dec "${ds:0:1}")
mm=$(_b36_to_dec "${ds:1:1}")
dd=$(_b36_to_dec "${ds:2:1}")
2026-06-02 09:23:17 -05:00
local yymmdd
2026-05-22 05:51:59 -05:00
yymmdd=$(printf "%02d%02d%02d" "$yy" "$mm" "$dd")
local size=${#encoded}
if (( size > 25 && size < 51 )); then
size=$(( size - 25 ))
fi
local shift=$(( size % 26 ))
2026-06-02 09:23:17 -05:00
local decoded="" i c ascii rotated
2026-05-22 05:51:59 -05:00
for (( i = 0; i < ${#encoded}; i++ )); do
c="${encoded:$i:1}"
ascii=$(printf '%d' "'$c")
if (( ascii >= 97 && ascii <= 122 )); then
rotated=$(( (ascii - 97 - shift + 26) % 26 + 97 ))
decoded+=$(printf "\\$(printf '%03o' "$rotated")")
elif (( ascii >= 65 && ascii <= 90 )); then
rotated=$(( (ascii - 65 - shift + 26) % 26 + 65 ))
decoded+=$(printf "\\$(printf '%03o' "$rotated")")
else
decoded+="$c"
fi
done
echo "$yymmdd: $decoded"
}
2025-10-31 05:51:19 -05:00
2026-06-02 09:23:17 -05:00
2024-05-21 07:00:18 -05:00
# ---
2026-06-02 09:23:17 -05:00
# functions : web / jongleur
2024-05-21 07:00:18 -05:00
# ---
2026-01-13 09:33:57 -05:00
2026-06-02 09:23:17 -05:00
_jongleur_base=/home/poq/syncDir/repos/git/gi.op.fo
_jongleur_deploy_user=usr@178.156.192.201
2025-05-10 08:59:44 -05:00
2026-06-02 09:23:17 -05:00
jongleur-activate() {
cd /home/poq/syncDir/repos/git/gitlab.com/jongleur/src
source venv/bin/activate
2025-04-06 18:18:37 -05:00
}
2026-06-02 09:23:17 -05:00
_jongleur_site() {
local site=$1
local action=$2
local base="$_jongleur_base/${site}"
case "$action" in
build)
jongleur-activate
"${base}/jongleur/run.sh"
deactivate
cd /home/poq/syncDir/0_downloads
;;
build-all)
jongleur-activate
"${base}/jongleur/runAll.sh"
deactivate
cd /home/poq/syncDir/0_downloads
;;
deploy)
rsync -v -a --progress --stats --delete-delay \
-e 'ssh -p 1808' \
"${base}/jongleur/html_export/" \
"${_jongleur_deploy_user}:/var/www/${site}/jongleur/"
;;
*)
echo "usage: <site>-{build|build-all|deploy}" >&2
return 1
;;
esac
}
# site shortcuts
for _site in ajp.fm antijanteboka.com antijantemiriam.com billgoats.com curious.art curiouscreators.com frodr.com klevstul.com; do
eval "${_site//./_}-build() { _jongleur_site '${_site}' build; }"
eval "${_site//./_}-build-all() { _jongleur_site '${_site}' build-all; }"
eval "alias ${_site}-build=\"${_site//./_}-build\""
eval "alias ${_site}-build-all=\"${_site//./_}-build-all\""
eval "alias ${_site}-deploy=\"rsync -v -a --progress --stats --delete-delay -e 'ssh -p 1808' ${_jongleur_base}/${_site}/jongleur/html_export/ ${_jongleur_deploy_user}:/var/www/${_site}/jongleur/\""
done
unset _site
# special case: klevstul.com deploys to weba
alias klevstul.com-deploy="rsync -v -a --progress --stats --delete-delay -e 'ssh -p 1808' ${_jongleur_base}/klevstul.com/jongleur/html_export/ usr@weba:/var/www/klevstul.com/jongleur/"
# misc website deploys
alias 00101111.xyz-deploy="rsync -v -a --progress --stats --delete-delay -e 'ssh -p 1808' /home/poq/syncDir/repos/git/gi.op.fo/00101111.xyz/www/ usr@weba:/var/www/00101111.xyz/"
alias factor.red-deploy="rsync -v -a --progress --stats --delete-delay -e 'ssh -p 1808' /home/poq/syncDir/repos/git/gi.op.fo/mini-websites/factor.red/ usr@weba:/var/www/factor.red/"
alias op.fo-deploy="rsync -v -a --progress --stats --delete-delay -e 'ssh -p 1808' /home/poq/syncDir/repos/git/gi.op.fo/mini-websites/op.fo/ usr@weba:/var/www/op.fo/"
alias wa.fo-deploy="rsync -v -a --progress --stats --delete-delay -e 'ssh -p 1808' /home/poq/syncDir/repos/git/gi.op.fo/mini-websites/wa.fo/ usr@weba:/var/www/wa.fo/"
2024-05-11 15:52:06 -05:00
2025-04-12 11:49:58 -05:00
# ---
2026-06-02 09:23:17 -05:00
# functions : ajp / podigy / jeton
2025-04-12 11:49:58 -05:00
# ---
2024-05-11 15:52:06 -05:00
podigy() {
2026-04-29 09:46:11 -05:00
cd /home/poq/syncDir/repos/git/gi.op.fo/podigy/src
2026-05-19 07:40:59 -05:00
source venv/bin/activate
python archi.py -s /home/poq/syncDir/repos/git/gi.op.fo/fiodb/db/podigy/sites
2024-05-11 15:52:06 -05:00
deactivate
}
2024-05-20 07:32:15 -05:00
jeton() {
2026-05-19 07:40:59 -05:00
cd /home/poq/syncDir/repos/git/gi.op.fo/jeton/src/
source venv/bin/activate
2026-06-02 09:23:17 -05:00
python archi.py -s /home/poq/syncDir/repos/git/gi.op.fo/fiodb/db/jeton/in/sites -r "$1"
2026-05-19 07:40:59 -05:00
deactivate
2024-05-20 07:32:15 -05:00
}
2024-05-11 16:05:43 -05:00
jcssbuilder() {
2026-05-19 07:40:59 -05:00
cd /home/poq/syncDir/repos/git/gi.op.fo/jCssBuilder/src
source venv/bin/activate
python /home/poq/syncDir/repos/git/gi.op.fo/jCssBuilder/src/archi.py
deactivate
2024-05-11 16:05:43 -05:00
}