lots of updates from old repo

This commit is contained in:
Steffen Vogel 2021-08-26 10:40:51 +02:00
parent 30a9c3419b
commit 80ca9ae189
15 changed files with 225 additions and 147 deletions

View File

@ -1,3 +1,17 @@
# enable color support of ls and also add handy aliases
if hash dircolors 2>/dev/null; then
if [ -r ~/.dircolors ]; then
eval "$(dircolors -b ~/.dircolors)"
else
eval "$(dircolors -b)"
fi
alias ls='ls --color=auto'
alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
fi
# some more ls aliases
alias ll='ls -l'
alias la='ls -A'
@ -24,7 +38,10 @@ alias e=$EDITOR
alias h=helm
alias d=docker
alias r=rancher
alias n="c ~/workspace/notes"
alias n="code ~/workspace/notes"
alias vi=vim
alias nano=vim
# Some shortcuts for me
function jumphost() {
@ -81,24 +98,43 @@ function rdp() {
fi
}
function aws() {
local PASS=$(pass providers/aws)
local AWS=$(which aws)
# Start original aws executable with short-lived keys
AWS_ACCESS_KEY_ID=$(sed -En 's/^Access-Key: (.*)/\1/p' <<< "$PASS") \
AWS_SECRET_ACCESS_KEY=$(sed -En 's/^Secret-Key: (.*)/\1/p' <<< "$PASS") \
$AWS $@
}
function restic() {
local RESTIC=$(which restic)
# Start original restic executable with short-lived keys
AWS_ACCESS_KEY_ID=restic \
AWS_SECRET_ACCESS_KEY=$(pass s3/minio-restic | head -n1) \
RESTIC_PASSWORD="$(pass restic/macbook | head -n1)" \
$RESTIC $@
(
export RESTIC_PASSWORD="$(pass restic/macbook)"
s3 minio-restic
$RESTIC $@
)
}
function backup() {
restic backup --exclude-if-present .resticignore ~
}
# Load S3 credentials from password-store
function s3() {
if [ "${AWS_ACCESS_KEY_PASS}" == $1 ]; then
return
fi
OUT=$(pass s3/$1)
AWS_SECRET_ACCESS_KEY=$(sed -n 1p <<< ${OUT})
AWS_ACCESS_KEY_ID=$(sed -En 's/^User: (.*)/\1/p' <<< ${OUT})
AWS_ACCESS_KEY_PASS=$1
export AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY
}
function backup-phone() {
pushd ~/annex/
git annex sync --no-push --content android
popd
}
function oath() {

View File

@ -2,41 +2,21 @@ if [ -f /usr/share/bash-completion/bash_completion ]; then
source /usr/share/bash-completion/bash_completion
fi
# Homebrew completions
if command -v brew > /dev/null; then
HOMEBREW_PREFIX=$(brew --prefix)
if type brew &>/dev/null; then
for COMPLETION in "$HOMEBREW_PREFIX"/etc/bash_completion.d/*; do
[[ -f $COMPLETION ]] && source "$COMPLETION"
done
if [[ -f ${HOMEBREW_PREFIX}/etc/profile.d/bash_completion.sh ]]; then
source "${HOMEBREW_PREFIX}/etc/profile.d/bash_completion.sh"
fi
fi
fi
for FILE in ~/.bash_completion.d/*; do
source ${FILE}
done
# Add completion to aliases
# See: https://github.com/cykerway/complete-alias
source ~/.homesick/repos/complete-alias/complete_alias
complete -F _complete_alias "${!BASH_ALIASES[@]}"
if type brew > /dev/null 2>&1; then
HOMEBREW_PREFIX=$(brew --prefix)
for COMPLETION in "$HOMEBREW_PREFIX"/etc/bash_completion.d/*; do
[[ -f $COMPLETION ]] && source "$COMPLETION"
done
if [[ -f ${HOMEBREW_PREFIX}/etc/profile.d/bash_completion.sh ]]; then
source "${HOMEBREW_PREFIX}/etc/profile.d/bash_completion.sh"
fi
fi
# Update complations if old
MAX_AGE=$(( 3 * 24 * 60 )) # Minutes
if (( $(find "${HOME}/.bash_completion.d/generated" -mmin +${MAX_AGE} | wc -l) > 0 )) || [ -n "${UPDATE_COMPLETIONS}" ]; then
echo "Start update of completions"
. ~/.homesick/repos/dotfiles/update-completions.sh
# Update complations if outdated
MAX_AGE=$(( 3*24*60*60 )) # Seconds
GENERATED=~/.bash_completion.d/generated
if (( $(date +%s) - $(date +%s -r "${GENERATED}") > ${MAX_AGE} )) || [ -n "${UPDATE_COMPLETIONS}" ]; then
echo "Start updating of completions..."
. ~/.homesick/repos/dotfiles/update-completions.sh ${GENERATED}
echo "Completions updated"
fi
for F in ~/.bash_completion.d/*; do
source $F
done

View File

@ -1,3 +0,0 @@
for COMPLETION in /Applications/Docker.app/Contents/Resources/etc/*.bash-completion; do
[ -f ${COMPLETION} ] && source ${COMPLETION}
done

View File

@ -0,0 +1,3 @@
if type doctl > /dev/null 2>&1; then
source <(doctl completion bash)
fi

View File

@ -0,0 +1,3 @@
if type helm > /dev/null 2>&1; then
source <(helm completion bash)
fi

View File

@ -0,0 +1,3 @@
if [ -f $(brew --prefix)/etc/bash_completion ]; then
. $(brew --prefix)/etc/bash_completion
fi

View File

@ -0,0 +1,3 @@
if type doctl > /dev/null 2>&1; then
source <(doctl completion bash)
fi

View File

@ -0,0 +1,10 @@
function _oath_completion() {
if [ -n "$2" ]; then
WORD=$2
mapfile -t COMPREPLY < <(grep -i $2 ~/.oath_tokens)
else
mapfile -t COMPREPLY < ~/.oath_tokens
fi
}
complete -F _oath_completion oath

13
home/.bash_completion.d/ykman Normal file → Executable file
View File

@ -7,17 +7,6 @@ if type ykman > /dev/null 2>&1; then
_YKMAN_COMPLETE=complete $1 ) )
return 0
}
complete -F _ykman_completion ykman
_ykman_completionetup() {
local COMPLETION_OPTIONS=""
local BASH_VERSION_ARR=(${BASH_VERSION//./ })
# Only BASH version 4.4 and later have the nosort option.
if [ ${BASH_VERSION_ARR[0]} -gt 4 ] || ([ ${BASH_VERSION_ARR[0]} -eq 4 ] && [ ${BASH_VERSION_ARR[1]} -ge 4 ]); then
COMPLETION_OPTIONS="-o nosort"
fi
complete $COMPLETION_OPTIONS -F _ykman_completion ykman
}
_ykman_completionetup;
fi

View File

@ -12,7 +12,7 @@ if [ -d /var/lib/snapd/snap/bin/code ]; then
export PATH="/var/lib/snapd/snap/bin/code:${PATH}"
fi
if [ -d ${KREW_ROOT:-$HOME/.krew}/bin ]; then
if [ -d ${KREW_ROOT:-${HOME}/.krew}/bin ]; then
PATH="${KREW_ROOT:-${HOME}/.krew}/bin:${PATH}"
fi
@ -34,6 +34,8 @@ fi
source ${HOME}/.cargo/env
# OS X stuff if availabe
if type brew > /dev/null 2>&1; then
#eval $(brew shellenv)
#export PATH="$(brew --prefix coreutils)/libexec/gnubin:${PATH}"
@ -48,8 +50,6 @@ if type brew > /dev/null 2>&1; then
export PATH="/usr/local/opt/coreutils/libexec/gnubin:${PATH}"
fi
# OS X stuff if availabe
# MacGPG2
if [ -d /usr/local/MacGPG2/bin/ ]; then
export PATH=/usr/local/MacGPG2/bin/:$PATH

View File

@ -66,6 +66,19 @@
# git always compare HEAD to @{upstream}
# svn always compare HEAD to your SVN upstream
#
# You can change the separator between the branch name and the above
# state symbols by setting GIT_PS1_STATESEPARATOR. The default separator
# is SP.
#
# When there is an in-progress operation such as a merge, rebase,
# revert, cherry-pick, or bisect, the prompt will include information
# related to the operation, often in the form "|<OPERATION-NAME>".
#
# When the repository has a sparse-checkout, a notification of the form
# "|SPARSE" will be included in the prompt. This can be shortened to a
# single '?' character by setting GIT_PS1_COMPRESSSPARSESTATE, or omitted
# by setting GIT_PS1_OMITSPARSESTATE.
#
# By default, __git_ps1 will compare HEAD to your SVN upstream if it can
# find one, or @{upstream} otherwise. Once you have set
# GIT_PS1_SHOWUPSTREAM, you can override it on a per-repository basis by
@ -78,12 +91,19 @@
# contains relative to newer annotated tag (v1.6.3.2~35)
# branch relative to newer tag or branch (master~4)
# describe relative to older annotated tag (v1.6.3.1-13-gdd42c2f)
# tag relative to any older tag (v1.6.3.1-13-gdd42c2f)
# default exactly matching tag
#
# If you would like a colored hint about the current dirty state, set
# GIT_PS1_SHOWCOLORHINTS to a nonempty value. The colors are based on
# the colored output of "git status -sb" and are available only when
# using __git_ps1 for PROMPT_COMMAND or precmd.
# using __git_ps1 for PROMPT_COMMAND or precmd in Bash,
# but always available in Zsh.
#
# If you would like __git_ps1 to do nothing in the case when the current
# directory is set up to be ignored by git, then set
# GIT_PS1_HIDE_IF_PWD_IGNORED to a nonempty value. Override this on the
# repository level by setting bash.hideIfPwdIgnored to "false".
# check whether printf supports -v
__git_printf_supports_v=
@ -118,6 +138,7 @@ __git_ps1_show_upstream ()
done <<< "$output"
# parse configuration values
local option
for option in ${GIT_PS1_SHOWUPSTREAM}; do
case "$option" in
git|svn) upstream="$option" ;;
@ -268,11 +289,43 @@ __git_ps1_colorize_gitstring ()
r="$c_clear$r"
}
# Helper function to read the first line of a file into a variable.
# __git_eread requires 2 arguments, the file path and the name of the
# variable, in that order.
__git_eread ()
{
local f="$1"
shift
test -r "$f" && read "$@" <"$f"
test -r "$1" && IFS=$'\r\n' read "$2" <"$1"
}
# see if a cherry-pick or revert is in progress, if the user has committed a
# conflict resolution with 'git commit' in the middle of a sequence of picks or
# reverts then CHERRY_PICK_HEAD/REVERT_HEAD will not exist so we have to read
# the todo file.
__git_sequencer_status ()
{
local todo
if test -f "$g/CHERRY_PICK_HEAD"
then
r="|CHERRY-PICKING"
return 0;
elif test -f "$g/REVERT_HEAD"
then
r="|REVERTING"
return 0;
elif __git_eread "$g/sequencer/todo" todo
then
case "$todo" in
p[\ \ ]|pick[\ \ ]*)
r="|CHERRY-PICKING"
return 0
;;
revert[\ \ ]*)
r="|REVERTING"
return 0
;;
esac
fi
return 1
}
# __git_ps1 accepts 0 or 1 arguments (i.e., format string)
@ -288,6 +341,8 @@ __git_eread ()
# In this mode you can request colored hints using GIT_PS1_SHOWCOLORHINTS=true
__git_ps1 ()
{
# preserve exit status
local exit=$?
local pcmode=no
local detached=no
local ps1pc_start='\u@\h:\w '
@ -299,10 +354,14 @@ __git_ps1 ()
ps1pc_start="$1"
ps1pc_end="$2"
printf_format="${3:-$printf_format}"
# set PS1 to a plain prompt so that we can
# simply return early if the prompt should not
# be decorated
PS1="$ps1pc_start$ps1pc_end"
;;
0|1) printf_format="${1:-$printf_format}"
;;
*) return
*) return $exit
;;
esac
@ -340,8 +399,8 @@ __git_ps1 ()
# incorrect.)
#
local ps1_expanded=yes
[ -z "$ZSH_VERSION" ] || [[ -o PROMPT_SUBST ]] || ps1_expanded=no
[ -z "$BASH_VERSION" ] || shopt -q promptvars || ps1_expanded=no
[ -z "${ZSH_VERSION-}" ] || [[ -o PROMPT_SUBST ]] || ps1_expanded=no
[ -z "${BASH_VERSION-}" ] || shopt -q promptvars || ps1_expanded=no
local repo_info rev_parse_exit_code
repo_info="$(git rev-parse --git-dir --is-inside-git-dir \
@ -350,14 +409,10 @@ __git_ps1 ()
rev_parse_exit_code="$?"
if [ -z "$repo_info" ]; then
if [ $pcmode = yes ]; then
#In PC mode PS1 always needs to be set
PS1="$ps1pc_start$ps1pc_end"
fi
return
return $exit
fi
local short_sha
local short_sha=""
if [ "$rev_parse_exit_code" = "0" ]; then
short_sha="${repo_info##*$'\n'}"
repo_info="${repo_info%$'\n'*}"
@ -369,6 +424,21 @@ __git_ps1 ()
local inside_gitdir="${repo_info##*$'\n'}"
local g="${repo_info%$'\n'*}"
if [ "true" = "$inside_worktree" ] &&
[ -n "${GIT_PS1_HIDE_IF_PWD_IGNORED-}" ] &&
[ "$(git config --bool bash.hideIfPwdIgnored)" != "false" ] &&
git check-ignore -q .
then
return $exit
fi
local sparse=""
if [ -z "${GIT_PS1_COMPRESSSPARSESTATE}" ] &&
[ -z "${GIT_PS1_OMITSPARSESTATE}" ] &&
[ "$(git config --bool core.sparseCheckout)" = "true" ]; then
sparse="|SPARSE"
fi
local r=""
local b=""
local step=""
@ -377,11 +447,7 @@ __git_ps1 ()
__git_eread "$g/rebase-merge/head-name" b
__git_eread "$g/rebase-merge/msgnum" step
__git_eread "$g/rebase-merge/end" total
if [ -f "$g/rebase-merge/interactive" ]; then
r="|REBASE-i"
else
r="|REBASE-m"
fi
r="|REBASE"
else
if [ -d "$g/rebase-apply" ]; then
__git_eread "$g/rebase-apply/next" step
@ -396,10 +462,8 @@ __git_ps1 ()
fi
elif [ -f "$g/MERGE_HEAD" ]; then
r="|MERGING"
elif [ -f "$g/CHERRY_PICK_HEAD" ]; then
r="|CHERRY-PICKING"
elif [ -f "$g/REVERT_HEAD" ]; then
r="|REVERTING"
elif __git_sequencer_status; then
:
elif [ -f "$g/BISECT_LOG" ]; then
r="|BISECTING"
fi
@ -412,10 +476,7 @@ __git_ps1 ()
else
local head=""
if ! __git_eread "$g/HEAD" head; then
if [ $pcmode = yes ]; then
PS1="$ps1pc_start$ps1pc_end"
fi
return
return $exit
fi
# is it a symbolic ref?
b="${head#ref: }"
@ -427,6 +488,8 @@ __git_ps1 ()
git describe --contains HEAD ;;
(branch)
git describe --contains --all HEAD ;;
(tag)
git describe --tags HEAD ;;
(describe)
git describe HEAD ;;
(* | default)
@ -447,6 +510,7 @@ __git_ps1 ()
local i=""
local s=""
local u=""
local h=""
local c=""
local p=""
@ -460,10 +524,9 @@ __git_ps1 ()
if [ -n "${GIT_PS1_SHOWDIRTYSTATE-}" ] &&
[ "$(git config --bool bash.showDirtyState)" != "false" ]
then
git diff --no-ext-diff --quiet --exit-code || w="*"
if [ -n "$short_sha" ]; then
git diff-index --cached --quiet HEAD -- || i="+"
else
git diff --no-ext-diff --quiet || w="*"
git diff --no-ext-diff --cached --quiet || i="+"
if [ -z "$short_sha" ] && [ -z "$i" ]; then
i="#"
fi
fi
@ -475,11 +538,16 @@ __git_ps1 ()
if [ -n "${GIT_PS1_SHOWUNTRACKEDFILES-}" ] &&
[ "$(git config --bool bash.showUntrackedFiles)" != "false" ] &&
git ls-files --others --exclude-standard --error-unmatch -- '*' >/dev/null 2>/dev/null
git ls-files --others --exclude-standard --directory --no-empty-directory --error-unmatch -- ':/*' >/dev/null 2>/dev/null
then
u="%${ZSH_VERSION+%}"
fi
if [ -n "${GIT_PS1_COMPRESSSPARSESTATE}" ] &&
[ "$(git config --bool core.sparseCheckout)" = "true" ]; then
h="?"
fi
if [ -n "${GIT_PS1_SHOWUPSTREAM-}" ]; then
__git_ps1_show_upstream
fi
@ -487,9 +555,11 @@ __git_ps1 ()
local z="${GIT_PS1_STATESEPARATOR-" "}"
# NO color option unless in PROMPT_COMMAND mode
if [ $pcmode = yes ] && [ -n "${GIT_PS1_SHOWCOLORHINTS-}" ]; then
__git_ps1_colorize_gitstring
# NO color option unless in PROMPT_COMMAND mode or it's Zsh
if [ -n "${GIT_PS1_SHOWCOLORHINTS-}" ]; then
if [ $pcmode = yes ] || [ -n "${ZSH_VERSION-}" ]; then
__git_ps1_colorize_gitstring
fi
fi
b=${b##refs/heads/}
@ -498,8 +568,8 @@ __git_ps1 ()
b="\${__git_ps1_branch_name}"
fi
local f="$w$i$s$u"
local gitstring="$c$b${f:+$z$f}$r$p"
local f="$h$w$i$s$u"
local gitstring="$c$b${f:+$z$f}${sparse}$r$p"
if [ $pcmode = yes ]; then
if [ "${__git_printf_supports_v-}" != yes ]; then
@ -511,4 +581,6 @@ __git_ps1 ()
else
printf -- "$printf_format" "$gitstring"
fi
return $exit
}

View File

@ -1,3 +1,7 @@
if [ -f "$HOME/.bashrc" ]; then
source "$HOME/.bashrc"
if [ -f "${HOME}/.bashrc" ]; then
source "${HOME}/.bashrc"
fi
if [ -f "${HOME}/.iterm2_shell_integration.bash" ]; then
source "${HOME}/.iterm2_shell_integration.bash"
fi

View File

@ -20,23 +20,17 @@ function show_prompt {
local EXIT="$?"
# Time
local pre='\[\e[01;35m\]\A '
local pre='\[\e[01;35m\]\t '
local post
# Check last return value
if [ $EXIT != 0 ]; then
pre+='\[\e[31m\]'
pre+='\[\e[31m\]'
else
pre+='\[\e[32m\]'
pre+='\[\e[32m\]'
fi
case "$TERM" in
xterm*|rxvt*)
echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD}\007"
;;
*)
;;
esac
pre+=' \[\e[;37m\]\j \l '
# Test if root
if [ $EUID -ne 0 ]; then
@ -47,7 +41,11 @@ function show_prompt {
post='\[\e[01;33m\]\w'
fi
post+='\n \[\e[01;30m\]\# \[\e[31m\]\$ \[\e[00m\]'
post+='\[\e[;37m\]\n \[\e[01;30m\]\# \[\e[31m\]\$ \[\e[00m\]'
__git_ps1 "$pre " "$post" '\[\e[01;30m\](%s\[\e[01;30m\]) '
if [[ $(git config --default true --get prompt.show) == "false" ]]; then
PS1="$pre $post"
else
__git_ps1 "$pre " "$post" '\[\e[01;30m\](%s\[\e[01;30m\]) '
fi
}

View File

@ -12,6 +12,9 @@ shopt -s globstar
# append to the history file, don't overwrite it
shopt -s histappend
# Auto "cd" when entering just a path
shopt -s autocd
# don't put duplicate lines or lines starting with space in the history.
# See bash(1) for more options
HISTCONTROL=ignorespace:ignoredups:erasedups
@ -20,7 +23,7 @@ HISTCONTROL=ignorespace:ignoredups:erasedups
HISTSIZE=99999999
HISTFILESIZE=99999999
HOSTFILE=$HOME/.hosts
HOSTFILE=~/.hosts
# make less more friendly for non-text input files, see lesspipe(1)
if [ -x /usr/bin/lesspipe ]; then eval "$(lesspipe)"; fi
@ -28,20 +31,6 @@ if [ -x /usr/bin/lesspipe ]; then eval "$(lesspipe)"; fi
# Homeshick
source ~/.homesick/repos/homeshick/homeshick.sh
# enable color support of ls and also add handy aliases
if hash dircolors 2>/dev/null; then
if [ -r ~/.dircolors ]; then
eval "$(dircolors -b ~/.dircolors)"
else
eval "$(dircolors -b)"
fi
alias ls='ls --color=auto'
alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
fi
source ~/.bash_env
source ~/.bash_prompt
source ~/.bash_aliases

View File

@ -1,25 +1,16 @@
#!/bin/bash
GENERATED=${1:-~/.bash_completion.d/generated}
# Update hostlist
. ~/workspace/snippets/bash/recursive-axfr.sh 0l.de > ~/.hosts.nulll
. ~/workspace/snippets/bash/recursive-axfr.sh k8s.0l.de @kube-dns.kube-system.svc.k8s.0l.de. > ~/.hosts.k8s
python3 ~/workspace/snippets/python/recursive-axfr/recursive-axfr.py > ~/.hosts
# python3 ~/workspace/snippets/python/recursive-axfr/recursive-axfr.py k8s.0l.de @kube-dns.kube-system.svc.k8s.0l.de. > ~/.hosts
echo '$include /etc/hosts.k8s' > ~/.hosts
echo '$include /etc/hosts.nulll' >> ~/.hosts
echo '$include /etc/hosts' >> ~/.hosts
rm ${GENERATED}
# Update slow completions
COMPLETIONS_GENERATED="/Users/stv0g_local/.bash_completion.d/generated"
type kubectl > /dev/null 2>&1 && kubectl completion bash >> ${GENERATED}
type doctl > /dev/null 2>&1 && doctl completion bash >> ${GENERATED}
type helm > /dev/null 2>&1 && helm completion bash >> ${GENERATED}
type ykman > /dev/null 2>&1 && _YKMAN_COMPLETE=source ykman >> ${GENERATED}
rm ${COMPLETIONS_GENERATED}
if type kubectl > /dev/null 2>&1; then
kubectl completion bash >> ${COMPLETIONS_GENERATED}
fi
if type doctl > /dev/null 2>&1; then
doctl completion bash >> ${COMPLETIONS_GENERATED}
fi
if type helm > /dev/null 2>&1; then
helm completion bash >> ${COMPLETIONS_GENERATED}
fi
ykman oath accounts list > ~/.oath_tokens