2021-11-12 21:07:28 +01:00
|
|
|
#!/bin/bash
|
2022-06-11 14:15:25 +02:00
|
|
|
### tmux auto attach
|
|
|
|
if command -v tmux &> /dev/null && [ -z "$TMUX" ]; then
|
|
|
|
tmux attach -t default || tmux new -s default
|
|
|
|
fi
|
|
|
|
|
2022-07-17 13:25:39 +02:00
|
|
|
### keychain
|
2023-02-22 13:50:09 +01:00
|
|
|
eval "$(keychain -q --eval --timeout 60 --agents ssh,gpg)"
|
|
|
|
export GPG_TTY=$(tty)
|
2022-07-01 14:24:48 +02:00
|
|
|
|
2021-11-12 21:07:28 +01:00
|
|
|
### PS1
|
2023-08-29 09:20:40 +02:00
|
|
|
# Farben
|
|
|
|
BLUE='\[\e[34m\]'
|
|
|
|
GREEN='\[\e[32m\]'
|
|
|
|
RED='\[\e[31m\]'
|
|
|
|
YELLOW='\[\e[33m\]'
|
|
|
|
WHITE='\[\e[97m\]'
|
|
|
|
BLACK='\[\e[30m\]'
|
|
|
|
RESET='\[\e[0m\]'
|
|
|
|
ORANGE='\[e[0;33m\]'
|
2021-11-12 21:07:28 +01:00
|
|
|
# git-symbole: * unstaged, + staged, $ stashed, % untracked
|
2021-08-20 23:14:19 +02:00
|
|
|
export GIT_PS1_SHOWUNTRACKEDFILES=1
|
2021-08-20 22:47:38 +02:00
|
|
|
export GIT_PS1_SHOWDIRTYSTATE=1
|
|
|
|
export GIT_PS1_SHOWSTASHSTATE=1
|
2023-08-29 09:20:40 +02:00
|
|
|
export GIT_PS1_SHOWUPSTREAM="verbose"
|
|
|
|
export GIT_PS1_SHOWCONFLICTSTATE="yes"
|
|
|
|
export PS1="\n${BLUE}\u${GREEN}@${ORANGE}\$(cat /etc/hostname) \$(pwd | sed -E -e "s#/#${RED}/${RESET}${GREEN}#g")${YELLOW}\$(__git_ps1)${RESET}\n> "
|
2021-08-23 12:28:24 +02:00
|
|
|
# https://unix.stackexchange.com/questions/105958/terminal-prompt-not-wrapping-correctly
|
|
|
|
# alle Farben sind mit \[<wert>\] escaped, sonst kann die shelle die länge nicht richtig ausrechnen
|
2021-11-12 21:07:28 +01:00
|
|
|
# https://github.com/git/git/blob/master/contrib/completion/git-prompt.sh
|
|
|
|
# https://gist.github.com/justintv/168835
|
|
|
|
# https://misc.flogisoft.com/bash/tip_colors_and_formatting
|
2022-12-22 12:37:23 +01:00
|
|
|
# Zeige letzte Exit-Code: https://stackoverflow.com/questions/16715103/bash-prompt-with-the-last-exit-code
|
2021-08-20 22:47:38 +02:00
|
|
|
|
2021-11-12 21:07:28 +01:00
|
|
|
### Praktische Dinge
|
2021-08-20 22:47:38 +02:00
|
|
|
# Deaktiviere FlowControl
|
|
|
|
# https://unix.stackexchange.com/questions/332791/how-to-permanently-disable-ctrl-s-in-terminal
|
|
|
|
stty -ixon
|
2021-11-12 21:07:28 +01:00
|
|
|
|
2023-07-24 20:38:00 +02:00
|
|
|
# vim als MANPAGER
|
|
|
|
export MANPAGER="vim -c ASMANPAGER -"
|
|
|
|
|
2021-08-24 11:44:24 +02:00
|
|
|
# farben fur manpages
|
|
|
|
# https://opensource.com/article/18/5/bash-tricks
|
|
|
|
export LESS_TERMCAP_mb=$'\E[01;31m'
|
|
|
|
export LESS_TERMCAP_md=$'\E[01;33m'
|
|
|
|
export LESS_TERMCAP_me=$'\E[0m'
|
|
|
|
export LESS_TERMCAP_se=$'\E[0m'
|
|
|
|
export LESS_TERMCAP_so=$'\E[01;42;30m'
|
|
|
|
export LESS_TERMCAP_ue=$'\E[0m'
|
|
|
|
export LESS_TERMCAP_us=$'\E[01;36m'
|
2021-11-12 21:07:28 +01:00
|
|
|
|
2021-11-12 11:56:46 +01:00
|
|
|
# bash history bei mehreren Session
|
|
|
|
shopt -s histappend
|
2022-02-18 13:11:49 +01:00
|
|
|
# bach History Zeitstempel am Anfang der Zeile
|
|
|
|
export HISTTIMEFORMAT='[%F_%T] '
|
2021-11-12 21:07:28 +01:00
|
|
|
|
2021-11-12 11:56:46 +01:00
|
|
|
# typo bei cd entfernen
|
|
|
|
shopt -s cdspell
|
2021-11-12 21:07:28 +01:00
|
|
|
|
2021-11-12 11:56:46 +01:00
|
|
|
# less mit maus scrollen
|
2021-11-19 08:22:17 +01:00
|
|
|
export LESS='--mouse --wheel-lines=3 eFRX'
|
2021-11-12 21:07:28 +01:00
|
|
|
|
2022-01-06 21:52:58 +01:00
|
|
|
# deaktiviere alias von ll
|
|
|
|
# weiter unten ist die FUnktion ll definiert die entweder exa oder ls ausführt
|
|
|
|
unalias ll 2>/dev/null
|
|
|
|
|
2021-11-12 21:07:28 +01:00
|
|
|
### Funktionen
|
|
|
|
function sgc {
|
|
|
|
case "$1" in
|
|
|
|
--help)
|
|
|
|
echo "Suche in der kompletten git-history nach "\$1""
|
2021-12-27 12:33:21 +01:00
|
|
|
echo ""
|
|
|
|
echo " Usage: sgc <Suchbegriff>"
|
2021-11-12 21:07:28 +01:00
|
|
|
;;
|
|
|
|
"")
|
2021-12-27 12:33:21 +01:00
|
|
|
echo "[ERROR] Suchbegriff fehlt..."
|
2021-11-12 21:07:28 +01:00
|
|
|
;;
|
|
|
|
*)
|
2022-09-01 13:01:06 +02:00
|
|
|
git grep "$1" "$(git rev-list --all)"
|
2021-11-12 21:07:28 +01:00
|
|
|
esac
|
|
|
|
}
|
|
|
|
function m2m {
|
|
|
|
if [[ "$1" == "--help" ]]; then
|
|
|
|
echo "Sende Datei "\$2" per Mail; Betreff = "\$1""
|
2021-12-27 12:33:21 +01:00
|
|
|
echo ""
|
|
|
|
echo " Usage: m2m <Pfad zu Datei> <Betreff>"
|
2021-11-12 21:07:28 +01:00
|
|
|
else
|
|
|
|
if [ ! -f "$2" ]; then
|
2021-12-27 12:33:21 +01:00
|
|
|
echo "[ERROR] Dateipfad fehlt..."
|
2021-11-12 21:07:28 +01:00
|
|
|
else
|
|
|
|
if [ -z "$1" ]; then
|
2021-12-27 12:33:21 +01:00
|
|
|
echo "[ERROR] Betreff fehlt..."
|
2021-11-12 21:07:28 +01:00
|
|
|
else
|
|
|
|
echo "$1" | mail -s "$1" -A "$2" michael.grote@posteo.de
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
function rgf {
|
|
|
|
if [[ "$1" == "--help" ]]; then
|
|
|
|
echo "Finde alle Dateien die "\$1" im Namen haben."
|
2021-11-29 10:08:47 +01:00
|
|
|
echo ""
|
2021-12-27 12:33:21 +01:00
|
|
|
echo " Usage: rgf <string>"
|
2021-11-29 10:48:45 +01:00
|
|
|
return 0
|
2021-11-29 10:08:47 +01:00
|
|
|
fi
|
|
|
|
if [ -z "$1" ]; then
|
2021-12-27 12:33:21 +01:00
|
|
|
echo "[ERROR] Suchbegriff fehlt..."
|
2021-11-29 10:48:45 +01:00
|
|
|
return 1
|
2021-11-29 10:08:47 +01:00
|
|
|
fi
|
2021-11-29 10:48:45 +01:00
|
|
|
if command -v rg >/dev/null ; then
|
2023-02-15 20:28:52 +01:00
|
|
|
rg --ignore-case --files --hidden --glob=!.git/ *"$1"*
|
2021-11-12 21:07:28 +01:00
|
|
|
else
|
2021-12-27 12:33:21 +01:00
|
|
|
echo "[INFO] ripgrep ist nicht installiert... suche mit 'find'"
|
2023-02-13 09:54:31 +01:00
|
|
|
find . -type f -not -path '*/\.git/*' -name *"$1"*
|
2021-11-12 21:07:28 +01:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
function rgi {
|
|
|
|
if [[ "$1" == "--help" ]]; then
|
|
|
|
echo "Finde alle Dateien die "\$1" im Inhalt haben."
|
2021-11-29 10:08:47 +01:00
|
|
|
echo ""
|
2021-12-27 12:33:21 +01:00
|
|
|
echo " Usage: rgi <string>"
|
2021-11-29 10:48:45 +01:00
|
|
|
return 0
|
2021-11-29 10:08:47 +01:00
|
|
|
fi
|
|
|
|
if [ -z "$1" ]; then
|
2021-12-27 12:33:21 +01:00
|
|
|
echo "[ERROR] Suchbegriff fehlt..."
|
2021-11-29 10:48:45 +01:00
|
|
|
return 1
|
2021-11-29 10:08:47 +01:00
|
|
|
fi
|
2021-11-29 10:48:45 +01:00
|
|
|
if command -v rg >/dev/null ; then
|
2023-02-13 09:41:26 +01:00
|
|
|
rg --ignore-case --hidden --glob=!.git/ "$1"
|
2021-11-12 21:07:28 +01:00
|
|
|
else
|
2021-12-27 12:33:21 +01:00
|
|
|
echo "[INFO] ripgrep ist nicht installiert... suche mit 'grep'"
|
2023-02-13 09:41:26 +01:00
|
|
|
grep --recursive --line-number --ignore-case --exclude-dir=".git" "$1" .
|
2021-11-12 21:07:28 +01:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
function ssh {
|
|
|
|
# benennt das aktuelle tmux-windows nach dem ssh-ziel
|
|
|
|
# baut ssh-verbindung auf
|
|
|
|
if [ -n "${TMUX}" ]; then
|
2022-09-01 13:03:58 +02:00
|
|
|
tmux rename-window "${@: -1}"
|
2021-11-12 21:07:28 +01:00
|
|
|
fi
|
|
|
|
command ssh "$@"
|
2022-02-08 09:12:25 +01:00
|
|
|
if [ -n "${TMUX}" ]; then
|
2022-09-01 12:59:49 +02:00
|
|
|
tmux rename-window "$(hostname -f)"
|
2022-02-08 09:12:25 +01:00
|
|
|
fi
|
2021-11-12 21:07:28 +01:00
|
|
|
}
|
2021-11-23 13:55:07 +01:00
|
|
|
function gcm {
|
2022-09-01 12:59:39 +02:00
|
|
|
if [ -z "$1" ]; then
|
|
|
|
echo "Commit-Message fehlt, setze Default-Message..."
|
2023-01-19 15:29:17 +01:00
|
|
|
git commit -s -m "changed Files: $(git diff --name-only --staged)"
|
2022-09-01 12:59:39 +02:00
|
|
|
else
|
|
|
|
# übergibt alle argumente an git commit -m als commit nachricht
|
2023-01-19 15:29:17 +01:00
|
|
|
git commit -s -m "$*"
|
2022-09-01 12:59:39 +02:00
|
|
|
fi
|
2021-11-23 13:55:07 +01:00
|
|
|
}
|
2021-12-27 12:25:57 +01:00
|
|
|
function gc {
|
|
|
|
case "$1" in
|
2022-06-11 14:09:11 +02:00
|
|
|
--help | -h)
|
|
|
|
cat <<EOF
|
|
|
|
|
|
|
|
Description:
|
|
|
|
"git checkout" on steroids
|
|
|
|
|
|
|
|
Usage:
|
2022-11-30 13:50:25 +01:00
|
|
|
gc [--help|--new-branch] [branch]
|
2022-06-11 14:09:11 +02:00
|
|
|
|
|
|
|
Options:
|
2022-11-30 13:50:25 +01:00
|
|
|
-h, --help Print this help.
|
2022-06-11 14:09:11 +02:00
|
|
|
-b, --new-branch Create a new Branch instead changing to an existing branch.
|
|
|
|
|
|
|
|
Author:
|
|
|
|
michael.grote@posteo.de - git.mgrote.net
|
|
|
|
EOF
|
2022-07-25 17:31:09 +02:00
|
|
|
;;
|
|
|
|
--new-branch | -b)
|
2022-07-25 19:14:38 +02:00
|
|
|
(git checkout --quiet -b "$2" && git push --set-upstream "$(git remote | head -n 1)" "$2" && echo '>>> Create new branch "'"$2"'"') ||
|
2022-06-11 14:09:11 +02:00
|
|
|
(git checkout --quiet "$2" > /dev/null 2>&1 && echo '>>> Branch already exists, checking out... ')
|
2021-12-27 12:25:57 +01:00
|
|
|
;;
|
|
|
|
*)
|
2022-11-30 13:50:25 +01:00
|
|
|
if [ ! -z $1 ] ; then
|
|
|
|
(echo ">>> Try local checkout" && git checkout --quiet "$1" > /dev/null 2>&1) ||
|
|
|
|
(echo ">>> Try remote checkout" && git checkout --quiet -b "$1" origin/"$1" > /dev/null 2>&1 || echo ">>> Unkown branch!")
|
|
|
|
else
|
|
|
|
(git checkout --quiet master > /dev/null 2>&1 && echo '>>> Try checking out master') ||
|
|
|
|
(git checkout --quiet main > /dev/null 2>&1 && echo '>>> Try checking out main') ||
|
|
|
|
(git checkout --quiet release > /dev/null 2>&1 && echo '>>> Try checking out release')
|
|
|
|
fi
|
2021-12-27 12:25:57 +01:00
|
|
|
esac
|
2022-07-25 19:14:38 +02:00
|
|
|
}
|
2023-02-14 10:34:07 +01:00
|
|
|
function glogs {
|
|
|
|
# https://git-scm.com/docs/pretty-formats
|
|
|
|
# https://stackoverflow.com/questions/3631005/git-log-tabular-formatting
|
|
|
|
# https://stackoverflow.com/questions/7736781/how-to-make-git-log-not-prompt-to-continue
|
2023-02-14 14:35:20 +01:00
|
|
|
if [ -z "$1" ]; then
|
|
|
|
ncommits=30;
|
|
|
|
else
|
|
|
|
ncommits="$1";
|
|
|
|
fi;
|
|
|
|
git log --pretty=format:'%C(auto) %<|(16,trunc)%h %Cred %G?%Creset %<|(60,trunc)%s %<(20,trunc)%Cgreen%cr%Creset %<(15,trunc)%Cblue%an%Creset %Cred%D' --graph --all -$ncommits
|
2023-02-14 10:34:07 +01:00
|
|
|
}
|
2023-08-14 09:21:40 +02:00
|
|
|
function gp {
|
|
|
|
git pull "$@"
|
|
|
|
}
|
2023-02-17 10:44:24 +01:00
|
|
|
function mdtoc {
|
|
|
|
grep --recursive --include="*.md" ^# | sort --version-sort --field-separator=":" | awk 'BEGIN {FS=":"}{print $2 "&&" $1}' | column --table --separator "&&" --table-truncate 1,2
|
|
|
|
}
|
2021-11-12 21:07:28 +01:00
|
|
|
### Aliase
|
|
|
|
# tmux
|
|
|
|
alias tmuxa="tmux a -t "
|
|
|
|
alias tmuxn="tmux new -s "
|
|
|
|
alias tmuxl="tmux ls"
|
|
|
|
alias tmuxk="tmux kill-session -t"
|
|
|
|
# abkuerzungen
|
2021-12-21 08:54:15 +01:00
|
|
|
alias se="sudoedit"
|
2022-01-27 13:46:39 +01:00
|
|
|
alias ip="ip --color=auto"
|
2021-11-12 21:07:28 +01:00
|
|
|
alias cls="clear"
|
2022-05-17 11:36:36 +02:00
|
|
|
alias tracert="traceroute"
|
2021-11-12 21:07:28 +01:00
|
|
|
alias df="df -h"
|
|
|
|
alias du="du -h"
|
|
|
|
alias grep="grep -i --color=auto"
|
|
|
|
alias hostname="hostname -f"
|
|
|
|
alias untar="tar -xzf"
|
|
|
|
alias unmount="umount"
|
2022-02-17 18:09:11 +01:00
|
|
|
alias psk="pkill"
|
2023-02-15 20:28:52 +01:00
|
|
|
alias ru="rip url --max-quality 3 --codec fla"
|
2022-06-25 22:46:28 +02:00
|
|
|
alias mkdir="mkdir -p"
|
2022-07-13 16:14:43 +02:00
|
|
|
alias last="last -w"
|
2023-07-13 11:01:18 +02:00
|
|
|
alias ll="ls -lAh"
|
2023-02-10 12:23:47 +01:00
|
|
|
alias tree="tree -a -I **.git**"
|
2021-11-12 21:07:28 +01:00
|
|
|
# git
|
2022-08-12 15:21:06 +02:00
|
|
|
alias gs="git status"
|
2021-12-03 21:33:30 +01:00
|
|
|
alias gf="git fetch"
|
2021-11-23 13:37:22 +01:00
|
|
|
alias gdel="git add . && git stash && git stash clear"
|
2021-11-23 13:55:07 +01:00
|
|
|
alias glast="git log -1 HEAD --stat"
|
|
|
|
alias gd="git diff"
|
2023-04-12 08:04:29 +02:00
|
|
|
alias gsp="git stage -p"
|
2021-11-12 21:07:28 +01:00
|
|
|
# vim
|
|
|
|
alias v="view"
|
|
|
|
# docker
|
|
|
|
alias dcu="docker-compose up"
|
|
|
|
alias dcd="docker-compose down"
|
|
|
|
alias dcr="docker-compose down && docker-compose up -d"
|
|
|
|
alias lzd="docker run --rm -it -v /var/run/docker.sock:/var/run/docker.sock lazyteam/lazydocker"
|
|
|
|
# safeguard
|
|
|
|
alias mv="mv -i "
|
|
|
|
alias cp="cp -i "
|
|
|
|
alias rm="rm -i "
|
2022-06-11 10:30:47 +02:00
|
|
|
# rest
|
2022-07-17 13:23:44 +02:00
|
|
|
alias suspend="~/dotfiles/scripts/pwr.sh -sd"
|
|
|
|
alias hibernate="~/dotfiles/scripts/pwr.sh -hb"
|
|
|
|
alias restart="~/dotfiles/scripts/pwr.sh -r"
|
|
|
|
alias shutdown="~/dotfiles/scripts/pwr.sh -s"
|
2022-07-21 15:23:37 +02:00
|
|
|
alias reboot="~/dotfiles/scripts/pwr.sh -r"
|
2022-09-04 11:52:49 +02:00
|
|
|
# k3s
|
|
|
|
alias k="sudo kubectl"
|
2022-09-18 17:18:34 +02:00
|
|
|
export KUBECONFIG="/etc/rancher/k3s/k3s.yaml"
|