You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
404 lines
12 KiB
404 lines
12 KiB
################################################################################
|
|
# #
|
|
# ● ○ ○ ○ ● #
|
|
# ● ● ○ ● ● Mike Ochmann #
|
|
# ● ○ ● ○ ● https://mike-ochmann.de #
|
|
# ● ○ ○ ○ ● #
|
|
# ● ○ ○ ○ ● #
|
|
# #
|
|
# My configuration for the Bourne Again Shell #
|
|
# Version 1.5.2 #
|
|
# #
|
|
################################################################################
|
|
|
|
#PS4='+ $(/usr/local/bin/gdate "+%s.%N")\011 '
|
|
#exec 3>&2 2>/tmp/bashstart.$$.log
|
|
#set -x
|
|
|
|
# Do not use this .bashrc if bash is not running in interactive mode
|
|
case $- in
|
|
*i*) ;;
|
|
*) return;;
|
|
esac
|
|
|
|
# HISTORY
|
|
HISTCONTROL=ignoreboth:erasedups # don't put duplicate lines or lines starting with space in the history
|
|
HISTIGNORE="ls:bg:fg:history" # Hist ignores exact match
|
|
HISTTIMEFORMAT="%F %T " # add timestamp
|
|
HISTSIZE=10000 # History size
|
|
HISTFILESIZE=20000 # History file size
|
|
|
|
shopt -s histappend # Append to the history file, don't overwrite it
|
|
shopt -s cmdhist # Save multi-line histroy as one line
|
|
shopt -s checkwinsize # Update columns/lines after commands
|
|
shopt -sq autocd # Can change dir without `cd`
|
|
shopt -s cdspell # Fixes minor spelling errors in cd paths
|
|
shopt -s no_empty_cmd_completion # Stops empty line tab comp
|
|
shopt -sq dirspell # Tab comp can fix dir name typos
|
|
|
|
|
|
# PATH
|
|
export PATH="/usr/local/opt/ncurses/bin:$PATH"
|
|
export PATH="/usr/local/bin:/Users/mochmann/.cargo/bin:$PATH"
|
|
#export PATH="/usr/local/Cellar:$PATH"
|
|
export PATH="/usr/local/sbin:$PATH"
|
|
export PATH="$HOME/.local/bin:$PATH"
|
|
export PATH="/usr/texbin:$PATH"
|
|
export PATH="$PATH:/Users/mochmann/.dotnet/tools"
|
|
export PATH="/usr/local/opt/mysql@5.7/bin:$PATH"
|
|
export PATH="/usr/local/opt/libpq/bin:$PATH"
|
|
export PATH="/usr/local/share/dotnet:$PATH"
|
|
export CC=clang
|
|
export CXX=clang++
|
|
export PATH="/usr/local/lib/python3.9/site-packages:$PATH"
|
|
export PATH="/usr/local/Cellar/mono/6.12.0.122_1/bin/:$PATH"
|
|
export PATH="~/.composer/vendor/bin:$PATH"
|
|
export PATH="~/apps:$PATH"
|
|
export PATH="~/apps/instantclient:$PATH"
|
|
|
|
if [[ "$OSTYPE" == "darwin"* ]]
|
|
then
|
|
export PATH="/Applications/Emacs.app/Contents/MacOS:$PATH"
|
|
fi
|
|
|
|
if [ -f ~/.venv/bin/activate ]; then
|
|
source ~/.venv/bin/activate
|
|
fi
|
|
|
|
|
|
# COLORS
|
|
|
|
## enabling directory colors if possible
|
|
if [ -x /usr/bin/dircolors ] || [ -x /usr/local/bin/gdircolorsi ] || [ -x /opt/homebrew/bin/gdircolors ]
|
|
then
|
|
# NOTE: you will get dircolors by running `brew install coreutils`
|
|
## `dircolors` is called `gdircolors` if installed via homebrew
|
|
if [[ "$OSTYPE" == "darwin"* ]]
|
|
then
|
|
dircolors() {
|
|
gdircolors "$@"
|
|
}
|
|
shopt -s expand_aliases
|
|
fi
|
|
if [ ! -f ~/.dircolors ]
|
|
then
|
|
dircolors -p > ~/.dircolors
|
|
fi
|
|
test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
|
|
if [[ "$OSTYPE" == "darwin"* ]]
|
|
then
|
|
alias ls="ls -G"
|
|
else
|
|
alias ls="ls --color=auto"
|
|
alias grep="grep --color=auto"
|
|
alias fgrep="fgrep --color=auto"
|
|
alias egrep="egrep --color=auto"
|
|
#alias dir="dir --color=auto"
|
|
#alias vdir="vdir --color=auto"
|
|
fi
|
|
fi
|
|
|
|
__prompt_command() {
|
|
local EXIT="$?"
|
|
## promp colors
|
|
|
|
## Regular Bold Underline High Intensity BoldHigh Intensity Background High Intensity Backgrounds
|
|
local Bla='\[\e[0;30m\]'; local BBla='\[\e[1;30m\]'; local UBla='\[\e[4;30m\]'; local IBla='\[\e[0;90m\]'; local BIBla='\[\e[1;90m\]'; local On_Bla='\e[40m'; local On_IBla='\[\e[0;100m\]';
|
|
local Red='\[\e[0;31m\]'; local BRed='\[\e[1;31m\]'; local URed='\[\e[4;31m\]'; local IRed='\[\e[0;91m\]'; local BIRed='\[\e[1;91m\]'; local On_Red='\e[41m'; local On_IRed='\[\e[0;101m\]';
|
|
local Gre='\[\e[0;32m\]'; local BGre='\[\e[1;32m\]'; local UGre='\[\e[4;32m\]'; local IGre='\[\e[0;92m\]'; local BIGre='\[\e[1;92m\]'; local On_Gre='\e[42m'; local On_IGre='\[\e[0;102m\]';
|
|
local Yel='\[\e[0;33m\]'; local BYel='\[\e[1;33m\]'; local UYel='\[\e[4;33m\]'; local IYel='\[\e[0;93m\]'; local BIYel='\[\e[1;93m\]'; local On_Yel='\e[43m'; local On_IYel='\[\e[0;103m\]';
|
|
local Blu='\[\e[0;34m\]'; local BBlu='\[\e[1;34m\]'; local UBlu='\[\e[4;34m\]'; local IBlu='\[\e[0;94m\]'; local BIBlu='\[\e[1;94m\]'; local On_Blu='\e[44m'; local On_IBlu='\[\e[0;104m\]';
|
|
local Pur='\[\e[0;35m\]'; local BPur='\[\e[1;35m\]'; local UPur='\[\e[4;35m\]'; local IPur='\[\e[0;95m\]'; local BIPur='\[\e[1;95m\]'; local On_Pur='\e[45m'; local On_IPur='\[\e[0;105m\]';
|
|
local Cya='\[\e[0;36m\]'; local BCya='\[\e[1;36m\]'; local UCya='\[\e[4;36m\]'; local ICya='\[\e[0;96m\]'; local BICya='\[\e[1;96m\]'; local On_Cya='\e[46m'; local On_ICya='\[\e[0;106m\]';
|
|
local Whi='\[\e[0;37m\]'; local BWhi='\[\e[1;37m\]'; local UWhi='\[\e[4;37m\]'; local IWhi='\[\e[0;97m\]'; local BIWhi='\[\e[1;97m\]'; local On_Whi='\e[47m'; local On_IWhi='\[\e[0;107m\]';
|
|
local Mag='\[\e[0;95m\]';
|
|
|
|
local RCol='\[\e[0m\]' # Text Reset
|
|
|
|
PS1="${debian_chroot:+(${Red}$debian_chroot${RCol})}"
|
|
|
|
if [ $UID -eq "0" ]
|
|
then
|
|
PS1+="${BRed}\u${RCol}"
|
|
else
|
|
PS1+="${BGre}\u${Mag}"
|
|
fi
|
|
PS1+="${Red}@\h "
|
|
local PSCol="$BPur"
|
|
|
|
PS1+="${PSCol}\w${RCol}" # Current working dir
|
|
if [ $EXIT != 0 ]
|
|
then
|
|
## can add `kill -l $?` to test to filter backgrounded
|
|
PS1+=" [${BRed}${EXIT}${RCol}]" # Add exit code, if non 0
|
|
fi
|
|
|
|
## Backgrounded running jobs
|
|
local BKGJBS=$(jobs -r | wc -l | tr -d ' ')
|
|
if [ ${BKGJBS} -gt 2 ]
|
|
then
|
|
PS1+=" ${Red}[bg:${BKGJBS}]${RCol}"
|
|
elif [ ${BKGJBS} -gt 0 ]
|
|
then
|
|
PS1+=" ${Yel}[bg:${BKGJBS}]${RCol}"
|
|
fi
|
|
|
|
## Stopped Jobs
|
|
local STPJBS=$(jobs -s | wc -l | tr -d ' ')
|
|
if [ ${STPJBS} -gt 2 ]
|
|
then
|
|
PS1+=" ${Red}[stp:${STPJBS}]${RCol}"
|
|
elif [ ${STPJBS} -gt 0 ]
|
|
then
|
|
PS1+=" ${Yel}[stp:${STPJBS}]${RCol}"
|
|
if [ $UID -eq "0" ]
|
|
then
|
|
PS1+=" ${BRed}# ${RCol}" ## End of PS1
|
|
else
|
|
PS1+=" ${BBlu}\$ ${RCol}" ## End of PS1
|
|
fi
|
|
fi
|
|
|
|
local branch=$(git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/')
|
|
if [ "$branch" != "" ]
|
|
then
|
|
branch="${Whi}⎇${Blu} $branch"
|
|
fi
|
|
PS1+=" ${branch}${Yel} ❯ ${RCol}"
|
|
}
|
|
|
|
#PS1='[\u]@\H \w [\$?] \\$ \[$(tput sgr0)\]'
|
|
export TERM=xterm-256color
|
|
export PROMPT_COMMAND=__prompt_command # Func to gen PS1 after CMDs
|
|
|
|
## directory coloring
|
|
export LS_COLORS='di=35:ln=36:so=30;46:pi=30;43:ex=33:bd=30;45:cd=30;42:su=31;40:sg=30;41:tw=35:ow=35'
|
|
|
|
|
|
# INTERNALS
|
|
|
|
# enable bash completion if nessecary
|
|
if ! shopt -oq posix
|
|
then
|
|
if [ -f /usr/share/bash-completion/bash_completion ]
|
|
then
|
|
. /usr/share/bash-completion/bash_completion
|
|
elif [ -f /etc/bash_completion ]; then
|
|
. /etc/bash_completion
|
|
fi
|
|
fi
|
|
|
|
## git completion for macOS
|
|
if [[ "$OSTYPE" == "darwin"* ]]
|
|
then
|
|
[ -f /usr/local/etc/bash_completion ] && . /usr/local/etc/bash_completion || {
|
|
[ -f "$(brew --prefix)/etc/bash_completion.d/git-completion.bash" ] && \
|
|
. $(brew --prefix)/etc/bash_completion.d/git-completion.bash
|
|
}
|
|
fi
|
|
|
|
[[ -r "/usr/local/etc/profile.d/bash_completion.sh" ]] && . "/usr/local/etc/profile.d/bash_completion.sh"
|
|
|
|
# FUNCTIONS
|
|
cd() {
|
|
builtin cd "$@" && ls
|
|
}
|
|
|
|
man() {
|
|
env \
|
|
LESS_TERMCAP_mb=$(printf "\e[1;31m") \
|
|
LESS_TERMCAP_md=$(printf "\e[1;31m") \
|
|
LESS_TERMCAP_me=$(printf "\e[0m") \
|
|
LESS_TERMCAP_se=$(printf "\e[0m") \
|
|
LESS_TERMCAP_so=$(printf "\e[1;44;33m") \
|
|
LESS_TERMCAP_ue=$(printf "\e[0m") \
|
|
LESS_TERMCAP_us=$(printf "\e[1;32m") \
|
|
man "$@"
|
|
}
|
|
|
|
## goes up `n` directories
|
|
function up {
|
|
[ "${1/[^0-9]/}" == "$1" ] && {
|
|
local ups=""
|
|
for i in $(seq 1 $1)
|
|
do
|
|
ups=$ups"../"
|
|
done
|
|
cd $ups
|
|
} || echo "usage: up INTEGER"
|
|
}
|
|
|
|
ytAudio() {
|
|
youtube-dl -x --audio-format mp3 $1
|
|
}
|
|
|
|
passgen() {
|
|
cat /dev/urandom | strings | grep -o '[a-zA-Z0-9]' | head -n ${1:-30} | tr -d '\n'
|
|
echo
|
|
}
|
|
|
|
multipass() {
|
|
for n in $(seq 1 $1); do
|
|
echo $(passgen)
|
|
done
|
|
}
|
|
nslookupr() {
|
|
nslookup $(nslookup $1 | grep Address | sed -n 2p | cut -d " " -f2)
|
|
}
|
|
digfull() {
|
|
dig +nocmd $1 any +multiline +noall +answer
|
|
}
|
|
|
|
sshttp() {
|
|
if [ -z "$3" ]
|
|
then
|
|
port=80
|
|
else
|
|
port=$3
|
|
fi
|
|
|
|
ssh -L 9000:$1:$port $2
|
|
}
|
|
|
|
sshttps() {
|
|
sshttp $1 $2 443
|
|
}
|
|
|
|
whichport() {
|
|
sudo lsof -i -P | grep LISTEN | grep ":$1"
|
|
}
|
|
|
|
panpdf() {
|
|
folder=$(dirname $1)
|
|
file=$(basename $1)
|
|
|
|
if [ ! -f "$folder/$file" ]
|
|
then
|
|
echo "no such file or directory : '$folder/$file'"
|
|
return
|
|
fi
|
|
|
|
name=$(echo $file | cut -d '.' -f 1)
|
|
|
|
pandoc -w pdf -o "$folder/$name.pdf" "$folder/$file"
|
|
}
|
|
|
|
# custom bash bultins
|
|
bash_plugin() {
|
|
input=$(history 1 | tr -s ' ' | cut -d " " -f 5)
|
|
prefix=${input:0:2}
|
|
|
|
|
|
if [[ "$prefix" == "0x" ]]; then
|
|
printf "%d\n" $input
|
|
echo -n "0b"
|
|
binary=$(printf "obase=2;%d\n" $input | bc)
|
|
echo -n "$binary"
|
|
history -d -1
|
|
kill -INT $$
|
|
elif [[ "$prefix" == "0b" ]]; then
|
|
value=${input:2}
|
|
decimal="$((2#$value))"
|
|
echo $decimal
|
|
printf "0x%x" $decimal
|
|
history -d -1
|
|
kill -INT $$
|
|
fi
|
|
}
|
|
|
|
#go() {
|
|
# DIRS=($(cat -n ~/bin/go_dirs))
|
|
|
|
# select=$(dialog --menu "Go to..." 20 100 16 "${DIRS[@]}" 3>&1 1>&2 2>&3)
|
|
|
|
# dialog --clear
|
|
# if [ $? -ne 0 ]
|
|
# then
|
|
# exit 1
|
|
# fi
|
|
|
|
# p="${DIRS[$select * 2 - 1]}"
|
|
# p="${p/#\~/$HOME}"
|
|
# cd $p
|
|
#}
|
|
|
|
ipcur() {
|
|
wget "https://ip.mike-ochmann.de/plain" -O - -q
|
|
echo ""
|
|
}
|
|
|
|
#trap bash_plugin DEBUG
|
|
|
|
|
|
# ENVIRONMENT
|
|
NPM_PACKAGES="${HOME}/.npm-packages"
|
|
|
|
export PATH="$NPM_PACKAGES/bin:$PATH"
|
|
export EDITOR=vim
|
|
|
|
if command -v manpath &> /dev/null
|
|
then
|
|
unset MANPATH # delete if you already modified MANPATH elsewhere in your config
|
|
export MANPATH="$NPM_PACKAGES/share/man:$(manpath)"
|
|
fi
|
|
|
|
#export LDFLAGS="-L/usr/local/opt/libffi/lib"
|
|
export PKG_CONFIG_PATH="/usr/local/opt/libffi/lib/pkgconfig"
|
|
|
|
export DOCKER_BUILDKIT=0
|
|
export COMPOSE_DOCKER_CLI_BUILD=0
|
|
export TNS_ADMIN=/Users/mochmann/oraclesql
|
|
|
|
# env_tools
|
|
if [ -x /usr/local/bin/anyenv ] || [ -x /opt/homebrew/bin/anyenv ]; then
|
|
eval "$(anyenv init -)"
|
|
fi
|
|
if [ -x /usr/local/bin/rbenv ]; then
|
|
eval "$(rbenv init -)"
|
|
fi
|
|
|
|
# ALIASES
|
|
alias ll="ls -lisah"
|
|
alias la="ls -A"
|
|
alias l="ls -CF"
|
|
alias histgrep='history | grep $@'
|
|
alias batt="pkill -f indicator-power-service"
|
|
alias pgcp="/home/miko/bash/pgcopy"
|
|
alias sqlplus="rlwrap -c sqlplus db070/Ru6fuyuDi2@pcork1"
|
|
alias atvim="vim"
|
|
alias nano="vim"
|
|
alias fullupdate="sudo apt update && sudo apt upgrade && sudo apt dist-upgrade"
|
|
alias ygrep=ytAudio
|
|
alias sv="sudo -E vim"
|
|
alias reload="source ~/.bashrc"
|
|
alias editrc="vim ~/.bashrc && reload"
|
|
alias shutdowncause="log show --predicate 'eventMessage contains \"Previous shutdown cause\"' --last 24h"
|
|
alias gl="glab"
|
|
alias mime="file --mime-type"
|
|
alias mountmunki="sshfs -o allow_other,defer_permissions munki:/uploads/ ~/munki/"
|
|
alias lg="lazygit"
|
|
|
|
# PROPELLER TMUX SSH
|
|
#if [ -z "$TMUX" ] && [ $(dpkg-query -W -f='${Status}' tmux 2>/dev/null | grep -c "ok installed") -eq 1 ] && [ -n "$SSH_TTY" ] && [ -z "$NO_AUTO_TMUX" ] && [[ $- =~ i ]]
|
|
if [ -z "$TMUX" ] && command -v tmux &> /dev/null && [ -n "$SSH_TTY" ] && [ -z "$NO_AUTO_TMUX" ] && [[ $- =~ i ]]
|
|
then
|
|
tmux attach-session -t $USER || tmux new-session -s $USER
|
|
exit
|
|
fi
|
|
|
|
if [ -f "$HOME/.cargo/env" ]
|
|
then
|
|
. "$HOME/.cargo/env"
|
|
fi
|
|
|
|
if [ -f "$HOME/.bash_override" ]; then
|
|
. "$HOME/.bash_override"
|
|
fi
|
|
|
|
# OVERRIDE
|
|
if [ -f "$HOME/.bashoverride" ]; then
|
|
source "$HOME/.bashoverride"
|
|
fi
|
|
|
|
#set +x
|
|
#exec 2>&3 3>&-
|
|
|