fix linebreaks

Signed-off-by: Michael Grote <michael.grote@posteo.de>
This commit is contained in:
Michael Grote 2024-01-18 09:22:38 +01:00
parent 72ebf77558
commit 3f22f67fc1

View file

@ -1,284 +1,284 @@
#!/bin/bash #!/bin/bash
### tmux auto attach ### tmux auto attach
# Check if the user ID is not 0 (root) # Check if the user ID is not 0 (root)
if [ "$EUID" -ne 0 ]; then if [ "$EUID" -ne 0 ]; then
if command -v tmux &> /dev/null && [ -z "$TMUX" ]; then if command -v tmux &> /dev/null && [ -z "$TMUX" ]; then
tmux attach -t default || tmux new -s default tmux attach -t default || tmux new -s default
fi fi
fi fi
### keychain ### keychain
eval "$(keychain -q --eval --timeout 60 --agents ssh,gpg)" eval "$(keychain -q --eval --timeout 60 --agents ssh,gpg)"
export GPG_TTY=$(tty) export GPG_TTY=$(tty)
### PS1 ### PS1
# Farben # Farben
BLUE='\[\e[34m\]' BLUE='\[\e[34m\]'
GREEN='\[\e[32m\]' GREEN='\[\e[32m\]'
RED='\[\e[31m\]' RED='\[\e[31m\]'
YELLOW='\[\e[33m\]' YELLOW='\[\e[33m\]'
WHITE='\[\e[97m\]' WHITE='\[\e[97m\]'
BLACK='\[\e[30m\]' BLACK='\[\e[30m\]'
RESET='\[\e[0m\]' RESET='\[\e[0m\]'
ORANGE='\[\e[0;33m\]' ORANGE='\[\e[0;33m\]'
# git-symbole: * unstaged, + staged, $ stashed, % untracked # git-symbole: * unstaged, + staged, $ stashed, % untracked
export GIT_PS1_SHOWUNTRACKEDFILES=1 export GIT_PS1_SHOWUNTRACKEDFILES=1
export GIT_PS1_SHOWDIRTYSTATE=1 export GIT_PS1_SHOWDIRTYSTATE=1
export GIT_PS1_SHOWSTASHSTATE=1 export GIT_PS1_SHOWSTASHSTATE=1
export GIT_PS1_SHOWUPSTREAM="verbose" export GIT_PS1_SHOWUPSTREAM="verbose"
export GIT_PS1_SHOWCONFLICTSTATE="yes" 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> " export PS1="\n${BLUE}\u${GREEN}@${ORANGE}\$(cat /etc/hostname) \$(pwd | sed -E -e "s#/#${RED}/${RESET}${GREEN}#g")${YELLOW}\$(__git_ps1)${RESET}\n> "
# https://unix.stackexchange.com/questions/105958/terminal-prompt-not-wrapping-correctly # https://unix.stackexchange.com/questions/105958/terminal-prompt-not-wrapping-correctly
# alle Farben sind mit \[<wert>\] escaped, sonst kann die shell die länge nicht richtig ausrechnen # alle Farben sind mit \[<wert>\] escaped, sonst kann die shell die länge nicht richtig ausrechnen
# https://github.com/git/git/blob/master/contrib/completion/git-prompt.sh # https://github.com/git/git/blob/master/contrib/completion/git-prompt.sh
# https://gist.github.com/justintv/168835 # https://gist.github.com/justintv/168835
# https://misc.flogisoft.com/bash/tip_colors_and_formatting # https://misc.flogisoft.com/bash/tip_colors_and_formatting
# Zeige letzte Exit-Code: https://stackoverflow.com/questions/16715103/bash-prompt-with-the-last-exit-code # Zeige letzte Exit-Code: https://stackoverflow.com/questions/16715103/bash-prompt-with-the-last-exit-code
### Praktische Dinge ### Praktische Dinge
# Deaktiviere FlowControl # Deaktiviere FlowControl
# https://unix.stackexchange.com/questions/332791/how-to-permanently-disable-ctrl-s-in-terminal # https://unix.stackexchange.com/questions/332791/how-to-permanently-disable-ctrl-s-in-terminal
stty -ixon stty -ixon
# farben fur manpages # farben fur manpages
# https://opensource.com/article/18/5/bash-tricks # https://opensource.com/article/18/5/bash-tricks
export LESS_TERMCAP_mb=$'\E[01;31m' export LESS_TERMCAP_mb=$'\E[01;31m'
export LESS_TERMCAP_md=$'\E[01;33m' export LESS_TERMCAP_md=$'\E[01;33m'
export LESS_TERMCAP_me=$'\E[0m' export LESS_TERMCAP_me=$'\E[0m'
export LESS_TERMCAP_se=$'\E[0m' export LESS_TERMCAP_se=$'\E[0m'
export LESS_TERMCAP_so=$'\E[01;42;30m' export LESS_TERMCAP_so=$'\E[01;42;30m'
export LESS_TERMCAP_ue=$'\E[0m' export LESS_TERMCAP_ue=$'\E[0m'
export LESS_TERMCAP_us=$'\E[01;36m' export LESS_TERMCAP_us=$'\E[01;36m'
# bash history bei mehreren Session # bash history bei mehreren Session
shopt -s histappend shopt -s histappend
# bach History Zeitstempel am Anfang der Zeile # bach History Zeitstempel am Anfang der Zeile
export HISTTIMEFORMAT='[%F_%T] ' export HISTTIMEFORMAT='[%F_%T] '
# typo bei cd entfernen # typo bei cd entfernen
shopt -s cdspell shopt -s cdspell
# less mit maus scrollen # less mit maus scrollen
export LESS='--mouse --wheel-lines=3 eFRX' export LESS='--mouse --wheel-lines=3 eFRX'
# deaktiviere alias von ll # deaktiviere alias von ll
# weiter unten ist die FUnktion ll definiert die entweder exa oder ls ausführt # weiter unten ist die FUnktion ll definiert die entweder exa oder ls ausführt
unalias ll 2>/dev/null unalias ll 2>/dev/null
### Funktionen ### Funktionen
function rgf { function rgf {
if [[ "$1" == "--help" ]]; then if [[ "$1" == "--help" ]]; then
echo "Finde alle Dateien die "\$1" im Namen haben." echo "Finde alle Dateien die "\$1" im Namen haben."
echo "" echo ""
echo " Usage: rgf <string>" echo " Usage: rgf <string>"
return 0 return 0
fi fi
if [ -z "$1" ]; then if [ -z "$1" ]; then
echo "[ERROR] Suchbegriff fehlt..." echo "[ERROR] Suchbegriff fehlt..."
return 1 return 1
fi fi
if command -v rg >/dev/null ; then if command -v rg >/dev/null ; then
rg --ignore-case --files --hidden --glob=!.git/ *"$1"* rg --ignore-case --files --hidden --glob=!.git/ *"$1"*
else else
echo "[INFO] ripgrep ist nicht installiert... suche mit 'find'" echo "[INFO] ripgrep ist nicht installiert... suche mit 'find'"
find . -type f -not -path '*/\.git/*' -name *"$1"* find . -type f -not -path '*/\.git/*' -name *"$1"*
fi fi
} }
function rgi { function rgi {
if [[ "$1" == "--help" ]]; then if [[ "$1" == "--help" ]]; then
echo "Finde alle Dateien die "\$1" im Inhalt haben." echo "Finde alle Dateien die "\$1" im Inhalt haben."
echo "" echo ""
echo " Usage: rgi <string>" echo " Usage: rgi <string>"
return 0 return 0
fi fi
if [ -z "$1" ]; then if [ -z "$1" ]; then
echo "[ERROR] Suchbegriff fehlt..." echo "[ERROR] Suchbegriff fehlt..."
return 1 return 1
fi fi
if command -v rg >/dev/null ; then if command -v rg >/dev/null ; then
rg --ignore-case --hidden --glob=!.git/ "$1" rg --ignore-case --hidden --glob=!.git/ "$1"
else else
echo "[INFO] ripgrep ist nicht installiert... suche mit 'grep'" echo "[INFO] ripgrep ist nicht installiert... suche mit 'grep'"
grep --recursive --line-number --ignore-case --exclude-dir=".git" "$1" . grep --recursive --line-number --ignore-case --exclude-dir=".git" "$1" .
fi fi
} }
function ssh { function ssh {
# benennt das aktuelle tmux-windows nach dem ssh-ziel # benennt das aktuelle tmux-windows nach dem ssh-ziel
# baut ssh-verbindung auf # baut ssh-verbindung auf
if [ -n "${TMUX}" ]; then if [ -n "${TMUX}" ]; then
tmux rename-window "${@: -1}" tmux rename-window "${@: -1}"
fi fi
command ssh "$@" command ssh "$@"
if [ -n "${TMUX}" ]; then if [ -n "${TMUX}" ]; then
tmux rename-window "$(hostname -f)" tmux rename-window "$(hostname -f)"
fi fi
} }
function gcm { function gcm {
if [ -z "$1" ]; then if [ -z "$1" ]; then
echo "Commit-Message fehlt, setze Default-Message..." echo "Commit-Message fehlt, setze Default-Message..."
git commit -s -m "changed Files: $(git diff --name-only --staged)" git commit -s -m "changed Files: $(git diff --name-only --staged)"
else else
# übergibt alle argumente an git commit -m als commit nachricht # übergibt alle argumente an git commit -m als commit nachricht
git commit -s -m "$*" git commit -s -m "$*"
fi fi
} }
function gc { function gc {
case "$1" in case "$1" in
--help | -h) --help | -h)
cat <<EOF cat <<EOF
Description: Description:
"git checkout" on steroids "git checkout" on steroids
Usage: Usage:
gc [--help|--new-branch] [branch] gc [--help|--new-branch] [branch]
Options: Options:
-h, --help Print this help. -h, --help Print this help.
-b, --new-branch Create a new Branch instead changing to an existing branch. -b, --new-branch Create a new Branch instead changing to an existing branch.
Author: Author:
michael.grote@posteo.de - git.mgrote.net michael.grote@posteo.de - git.mgrote.net
EOF EOF
;; ;;
--new-branch | -b) --new-branch | -b)
(git checkout --quiet -b "$2" && git push --set-upstream "$(git remote | head -n 1)" "$2" && echo '>>> Create new branch "'"$2"'"') || (git checkout --quiet -b "$2" && git push --set-upstream "$(git remote | head -n 1)" "$2" && echo '>>> Create new branch "'"$2"'"') ||
(git checkout --quiet "$2" > /dev/null 2>&1 && echo '>>> Branch already exists, checking out... ') (git checkout --quiet "$2" > /dev/null 2>&1 && echo '>>> Branch already exists, checking out... ')
;; ;;
*) *)
if [ ! -z $1 ] ; then if [ ! -z $1 ] ; then
(echo ">>> Try local checkout" && git checkout --quiet "$1" > /dev/null 2>&1) || (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!") (echo ">>> Try remote checkout" && git checkout --quiet -b "$1" origin/"$1" > /dev/null 2>&1 || echo ">>> Unkown branch!")
else else
(git checkout --quiet master > /dev/null 2>&1 && echo '>>> Try checking out master') || (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 main > /dev/null 2>&1 && echo '>>> Try checking out main') ||
(git checkout --quiet release > /dev/null 2>&1 && echo '>>> Try checking out release') (git checkout --quiet release > /dev/null 2>&1 && echo '>>> Try checking out release')
fi fi
esac esac
} }
function glogs { function glogs {
# https://git-scm.com/docs/pretty-formats # https://git-scm.com/docs/pretty-formats
# https://stackoverflow.com/questions/3631005/git-log-tabular-formatting # https://stackoverflow.com/questions/3631005/git-log-tabular-formatting
# https://stackoverflow.com/questions/7736781/how-to-make-git-log-not-prompt-to-continue # https://stackoverflow.com/questions/7736781/how-to-make-git-log-not-prompt-to-continue
if [ -z "$1" ]; then if [ -z "$1" ]; then
ncommits=30; ncommits=30;
else else
ncommits="$1"; ncommits="$1";
fi; 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 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
} }
function gp { function gp {
git pull "$@" git pull "$@"
} }
function mdtoc { function mdtoc {
grep --recursive --include="*.md" ^# | sort --version-sort --field-separator=":" | awk 'BEGIN {FS=":"}{print $2 "&&" $1}' | column --table --separator "&&" --table-truncate 1,2 grep --recursive --include="*.md" ^# | sort --version-sort --field-separator=":" | awk 'BEGIN {FS=":"}{print $2 "&&" $1}' | column --table --separator "&&" --table-truncate 1,2
} }
# "scrolle" durch die commit-history # "scrolle" durch die commit-history
ghist() { ghist() {
local total_commits=$(git rev-list HEAD --count) local total_commits=$(git rev-list HEAD --count)
local current_commit=$total_commits local current_commit=$total_commits
show_commit_diff() { show_commit_diff() {
if [ $current_commit -le $total_commits ] && [ $current_commit -ge 1 ]; then if [ $current_commit -le $total_commits ] && [ $current_commit -ge 1 ]; then
local commit_hash=$(git rev-list --reverse HEAD | sed -n "${current_commit}p") local commit_hash=$(git rev-list --reverse HEAD | sed -n "${current_commit}p")
git --no-pager show $commit_hash git --no-pager show $commit_hash
fi fi
} }
while true; do while true; do
clear # Clear the terminal clear # Clear the terminal
show_commit_diff show_commit_diff
# Display navigation options # Display navigation options
echo "-----------------------------------------------------------" echo "-----------------------------------------------------------"
echo "Navigation: N - Next Commit, P - Previous Commit, Q - Quit" echo "Navigation: N - Next Commit, P - Previous Commit, Q - Quit"
echo "-----------------------------------------------------------" echo "-----------------------------------------------------------"
read -n1 -s option read -n1 -s option
case $option in case $option in
p|P) p|P)
if [ $current_commit -gt 1 ]; then if [ $current_commit -gt 1 ]; then
((current_commit--)) ((current_commit--))
fi fi
;; ;;
n|N) n|N)
if [ $current_commit -lt $total_commits ]; then if [ $current_commit -lt $total_commits ]; then
((current_commit++)) ((current_commit++))
fi fi
;; ;;
q|Q) q|Q)
break break
;; ;;
*) *)
echo "Invalid option" echo "Invalid option"
;; ;;
esac esac
done done
} }
function sar { function sar {
case "$1" in case "$1" in
--help | -h) --help | -h)
cat <<EOF cat <<EOF
Description: Description:
Search and replace recursively. Search and replace recursively.
Usage: Usage:
sar [--help] <search> <replace> sar [--help] <search> <replace>
Options: Options:
-h, --help Print this help. -h, --help Print this help.
Author: Author:
michael.grote@posteo.de - git.mgrote.net michael.grote@posteo.de - git.mgrote.net
EOF EOF
;; ;;
esac esac
if [ "$1" != "-h" ] && [ "$1" != "--help" ] ; then if [ "$1" != "-h" ] && [ "$1" != "--help" ] ; then
if [ $# = 2 ] ; then if [ $# = 2 ] ; then
find . -name '*' -type f -not -path '*/\.git/*' -exec sed -i "s/$1/$2/" {} \; find . -name '*' -type f -not -path '*/\.git/*' -exec sed -i "s/$1/$2/" {} \;
elif [ $# = 1 ] ; then elif [ $# = 1 ] ; then
echo ">>> Not enough arguments..." echo ">>> Not enough arguments..."
elif [ $# -gt 2 ] ; then elif [ $# -gt 2 ] ; then
echo ">>> Too many arguments..." echo ">>> Too many arguments..."
fi fi
fi fi
} }
### Aliase ### Aliase
# tmux # tmux
alias tmuxa="tmux a -t " alias tmuxa="tmux a -t "
alias tmuxn="tmux new -s " alias tmuxn="tmux new -s "
alias tmuxl="tmux ls" alias tmuxl="tmux ls"
alias tmuxk="tmux kill-session -t" alias tmuxk="tmux kill-session -t"
# abkuerzungen # abkuerzungen
alias ip="ip --color=auto" alias ip="ip --color=auto"
alias cls="clear" alias cls="clear"
alias tracert="traceroute" alias tracert="traceroute"
alias df="df -h" alias df="df -h"
alias du="du -h" alias du="du -h"
alias grep="grep -i --color=auto" alias grep="grep -i --color=auto"
alias hostname="hostname -f" alias hostname="hostname -f"
alias untar="tar -xzf" alias untar="tar -xzf"
alias unmount="umount" alias unmount="umount"
alias ru="rip url --max-quality 3 --codec flac" alias ru="rip url --max-quality 3 --codec flac"
alias mkdir="mkdir -p" alias mkdir="mkdir -p"
alias last="last -w" alias last="last -w"
alias ll="ls -lAh" alias ll="ls -lAh"
alias tree="tree -a -I **.git**" alias tree="tree -a -I **.git**"
# git # git
alias gs="git status" alias gs="git status"
alias gf="git fetch" alias gf="git fetch"
alias gdel="git reset --hard ; git clean -f" alias gdel="git reset --hard ; git clean -f"
alias glast="git log -1 HEAD --stat" alias glast="git log -1 HEAD --stat"
alias gd="git diff" alias gd="git diff"
alias gsp="git stage -p" alias gsp="git stage -p"
# docker # docker
alias dcu="docker-compose up" alias dcu="docker-compose up"
alias dcd="docker-compose down" alias dcd="docker-compose down"
alias dcr="docker-compose down && docker-compose up -d" alias dcr="docker-compose down && docker-compose up -d"
# safeguard # safeguard
alias mv="mv -i " alias mv="mv -i "
alias cp="cp -i " alias cp="cp -i "
alias rm="rm -i " alias rm="rm -i "