dotfiles/.bash_extra

189 lines
5 KiB
Bash
Raw Normal View History

#!/bin/bash
### PS1
# 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
2021-10-06 11:16:17 +02:00
export PS1='\n\[\e[34m\]\u@\[\e[34m\]\h \[\e[94m\]\w\[\e[33m\]$(__git_ps1) \[\e[94m\]\n> \[\e[39m\]'
2021-08-20 22:47:38 +02:00
2021-10-06 11:16:17 +02:00
#\e[34m \u @ \e[34m \h \e[37m \e[94m \w \e[33m $(__git_ps1) \e[94m \n> \e[39m
#Blau User @ Bue Hostname Light Gray LightBlue Verzeichnis Yellow Git-Script LightBlue Zeilenumbruch Standard-Vordergrund-Farbe
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
# 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
2021-08-20 22:47:38 +02: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-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 11:56:46 +01:00
# bash history bei mehreren Session
shopt -s histappend
2021-11-12 11:56:46 +01:00
# typo bei cd entfernen
shopt -s cdspell
2021-11-12 11:56:46 +01:00
# enable colors
eval "`dircolors -b`"
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'
### Funktionen
function sgc {
case "$1" in
--help)
echo "Suche in der kompletten git-history nach "\$1""
echo "sgc = search git commit"
echo "sgc <suchbegriff>"
;;
"")
echo "Suchbegriff fehlt..."
;;
*)
git grep "$1" $(git rev-list --all)
esac
}
function m2m {
if [[ "$1" == "--help" ]]; then
echo "Sende Datei "\$2" per Mail; Betreff = "\$1""
echo "m2m = mail2me"
echo "m2m <Pfad zu Datei> <Betreff>"
else
if [ ! -f "$2" ]; then
echo "Dateipfad fehlt..."
else
if [ -z "$1" ]; then
echo "Betreff fehlt..."
else
echo "$1" | mail -s "$1" -A "$2" michael.grote@posteo.de
fi
fi
fi
}
function psk {
if [[ "$1" == "--help" ]]; then
echo "Beende Prozess "\$1""
echo "psk = ps kill"
echo "psk <prozessname>"
else
if [ -z "$1" ]; then
echo "Prozessname fehlt..."
else
ps -ef | grep "$1" | grep -v grep | awk '{ print $2 }' | xargs kill -9
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 ""
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
echo "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
2021-11-29 10:08:47 +01:00
rg --files -g *"$1"* --hidden
else
2021-11-29 10:08:47 +01:00
echo "ripgrep ist nicht installiert... suche mit 'find'"
find . -type f -name *"$1"*
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 ""
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
echo "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
2021-11-29 10:08:47 +01:00
rg -i "$1"
else
2021-11-29 10:08:47 +01:00
echo "ripgrep ist nicht installiert... suche mit 'grep'"
grep -r -n -i "$1" .
fi
}
function ssh {
# benennt das aktuelle tmux-windows nach dem ssh-ziel
# baut ssh-verbindung auf
if [ -n "${TMUX}" ]; then
tmux rename-window ""${@: -1}""
fi
command ssh "$@"
}
2021-11-23 13:55:07 +01:00
function gcm {
2021-11-23 13:58:23 +01:00
# übergibt alle argumente an git commit -m als commit nachricht
2021-11-26 12:09:59 +01:00
git commit -m "$*"
2021-11-23 13:55:07 +01:00
}
2021-12-27 12:25:57 +01:00
function gc {
case "$1" in
--help)
echo "git checkout <branch>"
echo "versucht erst einen lokalen checkout, danach von dem Remote-Repository"
echo "gc <branch>"
;;
"")
echo "Branch fehlt..."
;;
*)
git checkout $1 || git checkout -b $1 origin/$1
esac
2021-12-16 19:46:21 +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"
alias cls="clear"
alias df="df -h"
alias du="du -h"
alias grep="grep -i --color=auto"
2021-12-20 14:44:40 +01:00
alias ll="exa --long --git --all --ignore-glob='.git' --group-directories-first --sort=name --group"
alias hostname="hostname -f"
alias untar="tar -xzf"
alias unmount="umount"
# git
2021-11-24 13:29:37 +01:00
alias gp="git stash && git pull && git stash pop"
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 gsp="git stage -p"
alias gd="git diff"
2021-11-24 14:18:04 +01:00
alias gs="git status"
2021-11-26 21:20:38 +01:00
alias glogs="git log --all --graph --pretty=format:'%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative"
# 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 "