Initialize configurations

This commit is contained in:
Arnie 2025-01-03 21:06:04 +01:00
commit a6999d5663
25 changed files with 1288 additions and 0 deletions

19
.zsh/common/00-colors.zsh Executable file
View File

@ -0,0 +1,19 @@
autoload colors; colors
# The variables are wrapped in %{%}. This should be the case for every
# variable that does not contain space.
for COLOR in RED GREEN YELLOW BLUE MAGENTA CYAN BLACK WHITE; do
eval PR_$COLOR='%{$fg_no_bold[${(L)COLOR}]%}'
eval PR_BOLD_$COLOR='%{$fg_bold[${(L)COLOR}]%}'
done
eval RESET='$reset_color'
export PR_RED PR_GREEN PR_YELLOW PR_BLUE PR_WHITE PR_BLACK
export PR_BOLD_RED PR_BOLD_GREEN PR_BOLD_YELLOW PR_BOLD_BLUE
export PR_BOLD_WHITE PR_BOLD_BLACK
# Clear LSCOLORS
unset LSCOLORS
export CLICOLOR=1
export LS_COLORS=exfxcxdxbxegedabagacad
export LS_COLORS='rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=00:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arc=01;31:*.arj=01;31:*.taz=01;31:*.lha=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lrz=01;31:*.lz=01;31:*.lzo=01;31:*.xz=01;31:*.zst=01;31:*.tzst=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.alz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.cab=01;31:*.jpg=01;35:*.jpeg=01;35:*.mjpg=01;35:*.mjpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.m4a=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.oga=00;36:*.opus=00;36:*.spx=00;36:*.xspf=00;36:';

View File

@ -0,0 +1,2 @@
LC_CTYPE=en_US.UTF-8
LC_ALL=en_US.UTF-8

43
.zsh/common/01-setopt.zsh Executable file
View File

@ -0,0 +1,43 @@
# ===== Basics
# If you type foo, and it isn't a command, and it is a directory in your cdpath, go there
setopt AUTO_CD
# Allow comments even in interactive shells (especially for Muness)
# setopt INTERACTIVE_COMMENTS
# ===== History
# Allow multiple terminal sessions to all append to one zsh command history
setopt APPEND_HISTORY
# Add comamnds as they are typed, don't wait until shell exit
setopt INC_APPEND_HISTORY
# Do not write events to history that are duplicates of previous events
setopt HIST_IGNORE_DUPS
# When searching history don't display results already cycled through twice
setopt HIST_FIND_NO_DUPS
# Remove extra blanks from each command line being added to history
setopt HIST_REDUCE_BLANKS
# Include more information about when the command was executed, etc
setopt EXTENDED_HISTORY
# ===== Completion
# Allow completion from within a word/phrase
setopt COMPLETE_IN_WORD
# When completing from the middle of a word, move the cursor to the end of the word
setopt ALWAYS_TO_END
# ===== Prompt
# Enable parameter expansion, command substitution, and arithmetic expansion in the prompt
setopt PROMPT_SUBST
unsetopt MENU_COMPLETE
setopt AUTO_MENU

64
.zsh/common/02-prompt.zsh Executable file
View File

@ -0,0 +1,64 @@
function git_prompt_info {
local ref=$(=git symbolic-ref HEAD 2> /dev/null)
local gitst="$(=git status 2> /dev/null)"
if [[ -f .git/MERGE_HEAD ]]; then
if [[ ${gitst} =~ "unmerged" ]]; then
gitstatus=" %{$fg[red]%}unmerged%{$reset_color%}"
else
gitstatus=" %{$fg[green]%}merged%{$reset_color%}"
fi
elif [[ ${gitst} =~ "Changes to be committed" ]]; then
gitstatus=" %{$fg[blue]%}!%{$reset_color%}"
elif [[ ${gitst} =~ "use \"git add" ]]; then
gitstatus=" %{$fg[red]%}!%{$reset_color%}"
elif [[ -n `git checkout HEAD 2> /dev/null | grep ahead` ]]; then
gitstatus=" %{$fg[yellow]%}*%{$reset_color%}"
else
gitstatus=''
fi
if [[ -n $ref ]]; then
echo "%{$fg[green]%}⎇ %{$fg_bold[green]%}${ref#refs/heads/}%{$reset_color%}$gitstatus"
fi
}
function printUser {
if [[ -n "$SSH_CLIENT" ]] || [[ -n "$SSH_TTY" ]]; then
echo -n "%{$reset_color%}"
echo -n "%{$fg[yellow]%}%n%{$fg_bold[black]%}@"
echo -n "%{$reset_color%}"
case $(hostname) in
dingleberry)
echo -n "%{$fg[cyan]%}"
;;
ladybug)
echo -n "%{$fg_bold[green]%}"
;;
bimbobee)
echo -n "%{$fg_bold[blue]%}"
;;
lcech-mac-veracode)
echo -n "%{$fg[cyan]%}"
;;
*)
echo -n "%{$fg_bold[red]%}"
;;
esac
echo "%M "
fi
}
function printAwsVault {
if [[ -n "$AWS_VAULT" ]]; then
echo -n "%{$reset_color%}"
echo -n "%{$fg_bold[yellow]%}"
echo -n "[aws-vault: ${AWS_VAULT}]"
echo -n "%{$reset_color%}"
echo -n " "
fi
}
PROMPT='${PR_BOLD_BLACK}%* $(printUser)$(printAwsVault)${PR_CYAN}%~%<< $(git_prompt_info)${PR_BOLD_WHITE}>%{${reset_color}%} '

69
.zsh/common/03-completion.zsh Executable file
View File

@ -0,0 +1,69 @@
# add in zsh-completions
fpath=(~/zsh/completions $fpath)
autoload -U compinit && compinit
zmodload -i zsh/complist
# man zshcontrib
zstyle ':vcs_info:*' actionformats '%F{5}(%f%s%F{5})%F{3}-%F{5}[%F{2}%b%F{3}|%F{1}%a%F{5}]%f '
zstyle ':vcs_info:*' formats '%F{5}(%f%s%F{5})%F{3}-%F{5}[%F{2}%b%F{5}]%f '
zstyle ':vcs_info:*' enable git #svn cvs
# Enable completion caching, use rehash to clear
zstyle ':completion::complete:*' use-cache on
zstyle ':completion::complete:*' cache-path ~/.zsh/cache/$HOST
# Fallback to built in ls colors
zstyle ':completion:*' list-colors ''
# Make the list prompt friendly
zstyle ':completion:*' list-prompt '%SAt %p: Hit TAB for more, or the character to insert%s'
# Make the selection prompt friendly when there are a lot of choices
zstyle ':completion:*' select-prompt '%SScrolling active: current selection at %p%s'
# Add simple colors to kill
zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#) ([0-9a-z-]#)*=01;34=0=01'
# list of completers to use
zstyle ':completion:*::::' completer _expand _complete _ignored _approximate
zstyle ':completion:*' menu select=1 _complete _ignored _approximate
# insert all expansions for expand completer
# zstyle ':completion:*:expand:*' tag-order all-expansions
# match uppercase from lowercase
zstyle ':completion:*' matcher-list 'm:{a-z}={A-Z}'
# offer indexes before parameters in subscripts
zstyle ':completion:*:*:-subscript-:*' tag-order indexes parameters
# formatting and messages
zstyle ':completion:*' verbose yes
zstyle ':completion:*:descriptions' format '%B%d%b'
zstyle ':completion:*:messages' format '%d'
zstyle ':completion:*:warnings' format 'No matches for: %d'
zstyle ':completion:*:corrections' format '%B%d (errors: %e)%b'
zstyle ':completion:*' group-name ''
# ignore completion functions (until the _ignored completer)
zstyle ':completion:*:functions' ignored-patterns '_*'
zstyle ':completion:*:scp:*' tag-order files users 'hosts:-host hosts:-domain:domain hosts:-ipaddr"IP\ Address *'
zstyle ':completion:*:scp:*' group-order files all-files users hosts-domain hosts-host hosts-ipaddr
zstyle ':completion:*:ssh:*' tag-order users 'hosts:-host hosts:-domain:domain hosts:-ipaddr"IP\ Address *'
zstyle ':completion:*:ssh:*' group-order hosts-domain hosts-host users hosts-ipaddr
zstyle '*' single-ignored show
# ZAW styles
zstyle ':filter-select:highlight' matched fg=yellow,standout
zstyle ':filter-select' max-lines 10 # use 10 lines for filter-select
zstyle ':filter-select' max-lines -10 # use $LINES - 10 for filter-select
zstyle ':filter-select' rotate-list yes # enable rotation for filter-select
zstyle ':filter-select' case-insensitive yes # enable case-insensitive search
zstyle ':filter-select' extended-search no # see below
# Docker autocompletion
zstyle ':completion:*:*:docker:*' option-stacking yes
zstyle ':completion:*:*:docker-*:*' option-stacking yes

150
.zsh/common/03-manydots.zsh Executable file
View File

@ -0,0 +1,150 @@
# -*- mode: sh -*-
#
# manydots-magic - zle tweak for emulating "..."=="../.." etc.
#
# Copyright (c) 2011, 2012 Akinori MUSHA
# Licensed under the 2-clause BSD license.
#
# This tweek helps input ancestor directories beyond the parent (`..')
# in a handy way. You can just type triple dots to input `../..',
# quadruple dots to `../../..', etc..
#
# % .. [Hit <.>]
# % ../.. [Hit <.>]
# % ../../.. [Hit <^H>]
# % ../.. [Hit <^H>]
# % ..
#
# As you see above, each of the `/..' parts complemented by this tweak
# can be deleted by a single invocation of the backward-delete-char
# command, only if invoked right after the magic happens.
#
# % .. [Hit </><.><.>]
# % ../.. [Hit <^H>]
# % ../.
#
# Usage:
# autoload -Uz manydots-magic
# manydots-magic
#
manydots-magic.self-insert() {
emulate -L zsh
local self_insert_function magic_count
zstyle -s ':manydots-magic' self-insert-function self_insert_function
if [[ "$KEYS" == .* && "$LBUFFER" != *...* && "$LBUFFER" == *.. ]] && {
local -a words
words=("${(@Q)${(z)LBUFFER}}")
# `...` is a wildcard operator in go
[[ ${${(@)words[1,-2]}[(I)go]} = 0 ]] &&
[[ $words[-1] == (|*[/=]|[\<\>=]\().. ]]
}
then
[[ "$LASTWIDGET" == (self-insert|backward-delete-char) ]] &&
zstyle -s ':manydots-magic' magic-count magic_count
zstyle ':manydots-magic' magic-count $((magic_count+1))
LBUFFER="$LBUFFER/."
zle "$self_insert_function"
return
fi
# cancel expansion if it does not seem right
if [[ "$KEYS" != [=/,:\;\|\&\<\>\(\)\[\]{}^~\'\"\`[:space:]]* &&
"$LASTWIDGET" == (self-insert|backward-delete-char) && "$LBUFFER" == *../.. ]] && {
zstyle -s ':manydots-magic' magic-count magic_count
[[ "$magic_count" -gt 0 ]]
}
then
repeat $magic_count LBUFFER="${LBUFFER%/..}"
repeat $magic_count LBUFFER="$LBUFFER."
fi
zstyle ':manydots-magic' magic-count 0
zle "$self_insert_function"
}
manydots-magic.backward-delete-char() {
emulate -L zsh
local backward_delete_char_function
zstyle -s ':manydots-magic' backward-delete-char-function backward_delete_char_function
if [[ "$LASTWIDGET" == (self-insert|backward-delete-char) && "$LBUFFER" == *../.. ]] && {
local magic_count
zstyle -s ':manydots-magic' magic-count magic_count
[[ "$magic_count" -gt 0 ]]
}
then
zstyle ':manydots-magic' magic-count $((magic_count-1))
LBUFFER="${LBUFFER%..}"
else
zstyle ':manydots-magic' magic-count 0
fi
zle "$backward_delete_char_function"
}
manydots-magic.on() {
emulate -L zsh
local self_insert_function="${$(zle -lL | awk \
'$1=="zle"&&$2=="-N"&&$3=="self-insert"{print $4;exit}'):-.self-insert}"
[[ "$self_insert_function" == manydots-magic.self-insert ]] &&
return 0
# For url-quote-magic which does not zle -N itself
zle -la "$self_insert_function" || zle -N "$self_insert_function"
zstyle ':manydots-magic' self-insert-function "$self_insert_function"
zle -A manydots-magic.self-insert self-insert
local backward_delete_char_function="$(zle -lL | awk \
'$1=="zle"&&$2=="-N"&&$3=="backward-delete-char"{print $4;exit}')"
if [[ -n "$backward_delete_char_function" ]]
then
zle -la "$backward_delete_char_function" || zle -N "$backward_delete_char_function"
else
zle -A backward-delete-char manydots-magic.orig.backward-delete-char
backward_delete_char_function=manydots-magic.orig.backward-delete-char
fi
zstyle ':manydots-magic' backward-delete-char-function "$backward_delete_char_function"
zle -A manydots-magic.backward-delete-char backward-delete-char
zstyle ':manydots-magic' magic-count 0
return 0
}
manydots-magic.off() {
emulate -L zsh
local self_insert_function backward_delete_char_function
zstyle -s ':manydots-magic' self-insert-function self_insert_function
[[ -n "$self_insert_function" ]] &&
zle -A "$self_insert_function" self-insert
zstyle -s ':manydots-magic' backward-delete-char-function backward_delete_char_function
[[ -n "$backward_delete_char_function" ]] &&
zle -A "$backward_delete_char_function" backward-delete-char
zstyle ':manydots-magic' magic-count 0
return 0
}
zle -N manydots-magic.self-insert
zle -N manydots-magic.backward-delete-char
zle -N manydots-magic.on
zle -N manydots-magic.off
manydots-magic() {
manydots-magic.on
}
[[ -o kshautoload ]] || manydots-magic "$@"

16
.zsh/common/04-bindkeys.zsh Executable file
View File

@ -0,0 +1,16 @@
# To see the key combo you want to use just do:
# cat > /dev/null
# And press it
bindkey "^K" kill-whole-line # ctrl-k
# bindkey "^R" history-incremental-search-backward # ctrl-r
#bindkey "^A" beginning-of-line # ctrl-a
#bindkey "^E" end-of-line # ctrl-e
# bindkey "[B" history-search-forward # down arrow
# bindkey "[A" history-search-backward # up arrow
# bindkey "^D" delete-char # ctrl-d
# bindkey "^F" forward-char # ctrl-f
# bindkey "^B" backward-char # ctrl-b
bindkey "^[[1;5D" backward-word # ctrl-left arrow
bindkey "^[[1;5C" forward-word # ctrl-right arrow
bindkey -e # Default to standard emacs bindings, regardless of editor string

70
.zsh/common/05-functions.zsh Executable file
View File

@ -0,0 +1,70 @@
function zsh_recompile {
autoload -U zrecompile
rm -f ~/.zsh/*.zwc
[[ -f ~/.zshrc ]] && zrecompile -p ~/.zshrc
[[ -f ~/.zshrc.zwc.old ]] && rm -f ~/.zshrc.zwc.old
for f in ~/.zsh/**/*.zsh; do
[[ -f $f ]] && zrecompile -p $f
[[ -f $f.zwc.old ]] && rm -f $f.zwc.old
done
[[ -f ~/.zcompdump ]] && zrecompile -p ~/.zcompdump
[[ -f ~/.zcompdump.zwc.old ]] && rm -f ~/.zcompdump.zwc.old
source ~/.zshrc
}
function extract {
echo Extracting $1 ...
if [ -f $1 ] ; then
case $1 in
*.tar.bz2) tar xjf $1 ;;
*.tar.gz) tar xzf $1 ;;
*.bz2) bunzip2 $1 ;;
*.rar) unrar x $1 ;;
*.gz) gunzip $1 ;;
*.tar) tar xf $1 ;;
*.tbz2) tar xjf $1 ;;
*.tgz) tar xzf $1 ;;
*.zip) unzip $1 ;;
*.Z) uncompress $1 ;;
*.7z) 7z x $1 ;;
*) echo "'$1' cannot be extracted via extract()" ;;
esac
else
echo "'$1' is not a valid file"
fi
}
function trash () {
local path
for path in "$@"; do
# ignore any arguments
if [[ "$path" = -* ]]; then :
else
local dst=${path##*/}
# append the time if necessary
while [ -e ~/.Trash/"$dst" ]; do
dst="$dst "$(date +%H-%M-%S)
done
/bin/mv "$path" ~/.Trash/"$dst"
fi
done
}
function strip_diff_leading_symbols {
local color_code_regex="(\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K])"
# simplify the unified patch diff header
sed -r "s/^($color_code_regex)diff --git .*$//g" | \
sed -r "s/^($color_code_regex)index .*$/\n\1$(rule)/g" | \
sed -r "s/^($color_code_regex)\+\+\+(.*)$/\1+++\5\n\1$(rule)\x1B\[m/g" |\
# actually strips the leading symbols
sed -r "s/^($color_code_regex)[\+\-]/\1 /g"
}
## Print a horizontal rule
rule () {
printf "%$(tput cols)s\n"|tr " " "─"}}

6
.zsh/common/06-history.zsh Executable file
View File

@ -0,0 +1,6 @@
# HISTORY
HISTSIZE=10000
SAVEHIST=10000
HISTFILE=~/.zsh_history
# bindkey '^R' zaw-history

22
.zsh/common/07-zsh_hooks.zsh Executable file
View File

@ -0,0 +1,22 @@
function precmd {
# vcs_info
# Put the string "hostname::/full/directory/path" in the title bar:
echo -ne "\e]2;$PWD\a"
# Put the parentdir/currentdir in the tab
echo -ne "\e]1;$PWD:h:t/$PWD:t\a"
}
function set_running_app {
#print "\e]1; $PWD:t:$(history $HISTCMD | cut -b7- ) \a"
print -Pn $'\e]1; $PWD:t:$(history $HISTCMD | cut -b7- ) \a'
}
function preexec {
set_running_app
}
function postexec {
set_running_app
}

16
.zsh/common/09-zsh_aliases.zsh Executable file
View File

@ -0,0 +1,16 @@
# Allow usage of aliases when using sudo
alias sudo='sudo '
alias ls='ls --color'
alias less='less -R'
alias curlTiming="curl -w \" time_namelookup: %{time_namelookup}s\n time_connect: %{time_connect}s\n time_appconnect: %{time_appconnect}s\n time_pretransfer: %{time_pretransfer}s\n time_redirect: %{time_redirect}s\n time_starttransfe
r: %{time_starttransfer}s\n ----------\n time_total: %{time_total}s\n\" -o /dev/null"
dbase64() {
echo -n "${1}" | base64 -d
}
function appConnections()
{
ss -tpla | grep -v Recv-Q | awk '{print $5 $6}' | sed -e 's#\(.*\)users:((\"\(\w\+\)\".*#\2 - \1#' | sort | uniq
}
alias conns=appConnections

66
.zsh/common/10-adminer.zsh Executable file
View File

@ -0,0 +1,66 @@
function adminer() {
command -v kubectl >/dev/null 2>&1 || { echo >&2 "kubectl is required for portforwarding"; return 1; }
local ctx="${1}"
local ns="${2}"
local label="${3}"
local remotePort=${4}
local localPort=
[[ "${ctx}" == "" ]] && {echo >&2 "please provide name of the kubeconfig context\n\navailable contexts:"; kubectl config get-contexts --no-headers -o name >&2; return 1; }
[[ "${ns}" == "" ]] && ns="devops"
[[ "${label}" == "" ]] && label="app.kubernetes.io/name=adminer"
[[ "${remotePort}" == "" ]] && remotePort="8080"
kubectl config get-contexts --no-headers -o name | grep -q -- "^${ctx}$"
if [[ $? -ne 0 ]]; then
echo >&2 "context ${ctx} not found in kubectl\n\navailable contexts:\n"
kubectl config get-contexts --no-headers -o name >&2
return 1
fi
echo -n "specify a local port [8080]: "
read localPort
[[ "${localPort}" == "" ]] && localPort="8080"
local pod=$(kubectl --context "${ctx}" -n "${ns}" get pods --no-headers -l "${label}" -o name)
[[ "${pod}" == "" ]] && { echo >&2 "could not find the adminer pod using context '${ctx}' and namespace '${ns}' and label '${label}'"; return 1; }
kubectl --context "${ctx}" -n "${ns}" port-forward "${pod}" "${localPort}":"${remotePort}" &
local pfPid=$!
local attempt=0
echo "waiting for connection to open..."
while kill -0 $pfPid > /dev/null 2>&1; do
timeout 1 bash -c "</dev/tcp/127.0.0.1/${localPort}" > /dev/null 2>&1
if [[ $? -eq 0 ]]; then
xdg-open "http://adminer${localPort}:${localPort}"
break
fi
attempt=$((attempt+1))
[[ ${attempt} -eq 10 ]] && { echo &>2 "Connection took too long to establish"; break; }
sleep 1
done
fg %kubectl > /dev/null 2>&1
}
function adminer-local() {
local localPort=
echo -n "specify a local port [8080]: "
read localPort
[[ "${localPort}" == "" ]] && localPort="8080"
local contName="local-adminer-${localPort}"
sudo docker run --name $contName --rm -d --net host adminer
#sudo docker run --name $contName --rm -d -p $localPort:8080 adminer
[[ $? -ne 0 ]] && echo "Could not start adminer" && exit 1
xdg-open "http://adminer:${localPort}"
sudo docker attach $contName
}

View File

@ -0,0 +1,9 @@
alias dockerVolumeSizes="for vol in \$(docker volume ls -q); do sudo du -hs \$(docker volume inspect --format \"{{.Mountpoint}}\" \$vol); done"
alias dockerstats="docker stats \$(docker ps --format \"{{.Names}}\")"
alias dockerRemove="docker rmi -f \$(docker images | grep none | awk '{print \$3}')"
function bcrypt() {
nix-shell -p apacheHttpd --run "echo -n '${1}' | htpasswd -i -nB -C ${2:-12} '' | tr -d ':'"
}

71
.zsh/common/10-git_aliases.zsh Executable file
View File

@ -0,0 +1,71 @@
# Git
alias c="git commit -m"
alias s="git status"
alias gtagl="git fetch --tags && git tag -l -n9 --sort=-v:refname"
alias d="git diff"
alias d-s="git diff --staged"
alias a="git add"
alias n="git checkout -b"
alias m="git merge --no-ff"
alias gitSquash="git rebase --root -i"
gtag() {
git tag -a $1 -m "$2"
}
gtagReplace() {
local msg
msg=$(git tag -l -n9 $1 | sed "s/$1\s\+//g")
git tag -d $1 && \
git push origin :refs/tags/$1 && \
git tag -a $1 -m "${msg}" && \
git push origin $1
}
gtagRemoveMinor() {
if [[ $1 = "" ]]; then
echo "How does the tag begin?"
fi
local remove
local tags=$(git tag -l | grep "^${1}\.")
echo "${tags}"
echo -n "Remove these tags? (y/n) "
read remove
if [[ ${remove} != "y" ]] && [[ ${remove} != "yes" ]]; then
echo "Ok then!"
return 2
fi
while read -r tag; do
git tag -d ${tag}
git push origin :refs/tags/${tag}
done <<< "${tags}"
}
gdiff() {
local awkFormat='{ $2=on $2 off }; 1'
local masterDiff=$(git cherry -v develop master | awk -v on="\033[31;33m" -v off="\033[0m" ${awkFormat})
local develDiff=$(git cherry -v master develop | awk -v on="\033[31;33m" -v off="\033[0m" ${awkFormat})
if [[ "${masterDiff}" != "" ]]; then
echo "\033[1;31;32mOnly in master:\033[0m"
echo
echo "${masterDiff}"
fi
if [[ "${develDiff}" != "" ]]; then
echo "\033[1;31;33mOnly in develop:\033[0m"
echo
echo "${develDiff}"
fi
}
alias gitRemoveMerged="git branch --merged origin/master | grep -v '* master' | xargs git branch -d"

View File

@ -0,0 +1,18 @@
function klogs() {
local ctx="$1"
local namespace="$2"
local label="$3"
if [[ "$ctx" == "" || "$namespace" == "" || "$label" == "" ]]; then
echo "Usage: klogs context namespace label"
echo "\nContexts:"
kubectl config get-contexts -o name | sed 's/^/\t/g'
echo "Label examples:"
echo "\tapp.kubernetes.io/name=..."
echo "\teks.amazonaws.com/component=..."
return 1
fi
kubectl --context "$context" logs -f -n "$namespace" -l "$label"
}

View File

@ -0,0 +1,124 @@
init-nix-flake() {
local tpl=$1
local name=$2
local flakePath="$(pwd)/flake.nix"
local envrcPath="$(pwd)/.envrc"
[[ -f "${flakePath}" ]] && echo "${flakePath} already present" && return 1
[[ -f "${envrcPath}" ]] && echo "${envrcPath} already present" && return 1
if [[ "$tpl" == "yp" ]]; then
cat <<EOF > "${flakePath}"
{
inputs = {
nix.url = "git+ssh://git@bitbucket.org/yourpass/nix";
};
outputs = { self, nix }: {
formatter = nix.formatter;
devShells = nix.lib.forAllSystems (pkgs: {
default = pkgs.devshell.mkShell {
name = "yp-${name}";
packages = with pkgs; [
];
commands = [];
};
});
};
}
EOF
echo "use flake" > "${envrcPath}"
direnv allow
elif [[ "$tpl" == "investbay" ]]; then
cat <<EOF > "${flakePath}"
{
inputs = {
nix.url = "git+ssh://git@git.investbay.dev/morosystems/investbay/devops/nix?branch=main";
};
outputs = { self, nix }: {
formatter = nix.formatter;
devShells = nix.lib.forAllSystems (pkgs: {
default = pkgs.devshell.mkShell {
name = "investbay-${name}";
packages = with pkgs; [
];
commands = [];
};
});
};
}
EOF
echo "use flake" > "${envrcPath}"
direnv allow
elif [[ "$tpl" == "c3c" ]]; then
cat <<EOF > "${flakePath}"
{
inputs = {
nix.url = "git+ssh://git@git.c3c.cz/C3C/nix";
};
outputs = { self, nix }: {
formatter = nix.formatter;
devShells = nix.lib.forAllSystems (pkgs: {
default = nix.lib.mkDevenvShell {
inherit pkgs;
inputs = {
self = self;
nixpkgs = pkgs;
};
modules = [
{
packages = with pkgs; [
];
scripts = {
menu = {
description = "Print this menu";
exec = ''
echo "Commands:"
echo -n '\${
builtins.toJSON (
builtins.mapAttrs (s: value: value.description) self.devShells.\${pkgs.system}.default.config.scripts
)
}' | \
\${pkgs.jq}/bin/jq -r 'to_entries | map(" \(.key)\n" + " - \(if .value == "" then "no description provided" else .value end)") | "" + .[]'
'';
};
fix = {
exec = ''
\${nix.lib.cd_root}
nix fmt ./*.nix
\${pkgs.golangci-lint}/bin/golangci-lint run --sort-results --out-format tab --config \${nix.lib.golangci-config-file} --fix --issues-exit-code 0 ./...
stylua ./src
'';
};
};
}
];
};
});
};
}
EOF
echo "use flake . --impure" > "${envrcPath}"
direnv allow
else
echo "Wrong template as first arg: [yp/investbay/c3c]"
return 1
fi
}

View File

@ -0,0 +1,5 @@
alias awsKubeconfig="aws eks --region eu-central-1 update-kubeconfig --name "
alias loginToSkodaECR="aws --profile skoda-prod --region eu-central-1 ecr get-login-password | sudo docker login 943160431142.dkr.ecr.eu-central-1.amazonaws.com -u AWS --password-stdin"
alias loginToSkodaScholarisECR="aws --profile skoda-sch-dev --region eu-central-1 ecr get-login-password | sudo docker login 442913623981.dkr.ecr.eu-central-1.amazonaws.com -u AWS --password-stdin"
alias loginToYpECR="aws-vault exec yp aws --region eu-central-1 ecr get-login-password | sudo docker login 060714730522.dkr.ecr.eu-central-1.amazonaws.com -u AWS --password-stdin"
alias loginToInvestBayECR="aws-vault exec InvestBay-AccountManagement aws --region eu-central-1 ecr get-login-password | sudo docker login 297503416491.dkr.ecr.eu-central-1.amazonaws.com -u AWS --password-stdin"

9
.zsh/common/11-aws.zsh Normal file
View File

@ -0,0 +1,9 @@
export AWS_VAULT_BACKEND=secret-service
export AWS_VAULT_SECRET_SERVICE_COLLECTION_NAME=default
alias argoyp='argo --context yp:060714730522:eu-west-1/yp-dev -n argo'
function awsS3cpWithPublic {
local expires=$(date '+%a, %d %b %Y 00:00:00 GMT' -d "$(date +%Y-%m-%d) + 365 day")
aws s3 cp --acl "public-read" --expires "${expires}" --cache-control "max-age=31536000" --metadata-directive REPLACE $@
}

View File

@ -0,0 +1,125 @@
# Docker
alias drone="source /self/storage/.circuitry/.secret/drone.shinc && /usr/local/bin/drone"
alias drone-ys="source /self/storage/.circuitry/.secret/drone-ys.shinc && /usr/local/bin/drone@1"
alias gitPruneRemote="~/circuitry/scripts/pruneGit remote"
alias gitPruneLocal="~/circuitry/scripts/pruneGit local"
#
# LVM
#
lvBackup() {
if [[ $(sudo lvs | grep root | wc -l) -gt 1 ]]; then
echo "There are several mentions of root volume"
return
fi
DEVICE=$(sudo lvs | grep root | awk '{print $2}')
VOL_NAME=$(sudo lvs | grep root | awk '{print $1}')
if [[ ${DEVICE} != "" ]]; then
sudo lvcreate -s -n backup -L4.75G /dev/${DEVICE}/${VOL_NAME}
else
echo "Could not find the root device"
fi
}
lvBackupRemove() {
if [[ $(sudo lvs | grep backup | wc -l) -gt 1 ]]; then
echo "There are several mentions of backup volume"
return
fi
DEVICE=$(sudo lvs | grep backup | awk '{print $2}')
VOL_NAME=$(sudo lvs | grep backup | awk '{print $1}')
if [[ ${DEVICE} != "" ]]; then
sudo lvremove /dev/${DEVICE}/${VOL_NAME}
else
echo "Could not find the backup device"
fi
}
convertSubtitles() {
local subtitleFile="${1}"
iconv -f windows-1250 -t utf-8 "${subtitleFile}" > "${subtitleFile}.utf8" && \
rm "${subtitleFile}" && \
mv "${subtitleFile}.utf8" "${subtitleFile}"
}
function scanMultiPdf() {
local keepScanning=1
local scanNumber=1
local filename="$1"
local inputFilenames=()
local prefix=$(dd if=/dev/urandom count=1 bs=128 status=none | md5sum -b | cut -d ' ' -f 1)
local currentFile
if [[ "${filename}" == "" ]]; then
echo "You must provide a filename as first argument"
return 1
fi
# This initializes devices if freshly connected
echo "Scanning for devices, please wait..."
scanimage --list-devices > /dev/null 2>&1
while [[ 1 ]]; do
currentFile="/tmp/scan.${prefix}.${scanNumber}.pdf"
scanToPdf "${currentFile}"
if [[ ! -f "${currentFile}" ]]; then
echo "Failed to scan, try again? [(y)/n]"
read CONTINUE
if [[ "${CONTINUE}" != "" ]] && [[ "${CONTINUE}" != "y" ]]; then
break
fi
continue
fi
inputFilenames+=("${currentFile}")
echo "Continue scanning? [(y)/n]"
read CONTINUE
if [[ "${CONTINUE}" != "" ]] && [[ "${CONTINUE}" != "y" ]]; then
break
fi
scanNumber=$((scanNumber+1))
done
if [[ ${#inputFilenames[@]} -gt 0 ]]; then
pdfunite ${inputFilenames[@]} "${filename}"
fi
rm -f "/tmp/scan.${prefix}."*
}
function scanToPdf()
{
local output=$1
local tempOutput="/tmp/scan.pnm"
if [[ $output == "" ]]; then
output="scan.pdf"
fi
# scan and rotate to fix the scanner rotation using pnmrotate and pnmcut
scanimage -x 216 -y 297 > "${tempOutput}" && \
#pnmrotate -1 "${tempOutput}" > "${tempOutput}.rotated" && \
#pnmcut -top=42 -bottom=-45 -left=62 -right=-64 "${tempOutput}.rotated" > "${tempOutput}" && \
convertPnmToPdf "${tempOutput}" && \
mv output.pdf ${output}
rm -f "${tempOutput}.rotated"
rm -f "${tempOutput}"
}
function convertPnmToPdf()
{
local tempOutput="/tmp/concat.pdf"
convert $@ "${tempOutput}" && \
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen -dNOPAUSE -dQUIET -dBATCH -sOutputFile=output.pdf "${tempOutput}"
rm -f "${tempOutput}"
}

View File

@ -0,0 +1,3 @@
export GTK_IM_MODULE=ibus
export XMODIFIERS=@im=ibus
export QT_IM_MODULE=ibus

View File

@ -0,0 +1,2 @@
alias joinYsAws="sudo openvpn ~/circuitry/vpn/ys-aws.conf"
alias deployEpa="drone deploy Cech-iS/Epa"

View File

@ -0,0 +1,109 @@
{
config,
pkgs,
...
}:
let
username = "becky";
homedir = "/home/${username}";
zshSourceCommon = ../.zsh/common;
zshSourceUser = ../.zsh/dingleberry;
in
{
# Let Home Manager install and manage itself.
programs.home-manager.enable = true;
home.username = username;
home.homeDirectory = homedir;
home.stateVersion = "24.11";
home.packages = with pkgs; [
# TODO: Move from system to nix
# awscli2
# k9s
# kubectl
# nixd
];
programs.direnv = {
enable = true;
nix-direnv.enable = true;
};
programs.zsh = {
enable = true;
dirHashes = {
mac = "${homedir}/storage/.macshare";
circuitry = "${homedir}/storage/.circuitry";
dev = "${homedir}/storage/.devstack";
ai = "${homedir}/storage/.devstack/ai";
life = "${homedir}/storage/.life";
vysokyujezd = "${homedir}/storage/.life/stavby/vysoky-ujezd";
work = "/mnt/yosuke/share/arnie/work";
smarthome = "/mnt/yosuke/share/arnie/smarthome";
# Hardware
v2-red = "${homedir}/storage/.hardware/3d-print/v2-red-V2-2201270017";
"3dprint" = "${homedir}/storage/.hardware/3d-print";
# Development
projects = "${homedir}/storage/.devstack/projects";
yp = "${homedir}/storage/.devstack/projects/yp";
ys = "${homedir}/storage/.devstack/projects/ys";
investbay = "${homedir}/storage/.devstack/projects/investbay";
resource = "${homedir}/storage/.devstack/resource";
cechis = "${homedir}/storage/.devstack/projects/dev.cechis.cz";
gh = "${homedir}/storage/.devstack/projects/github/Sharsie";
rpi = "${homedir}/storage/.devstack/projects/hardware/rpi";
c4 = "/mnt/yosuke/share/arnie/smarthome/control4/drivers";
};
initExtra = ''
for file in ${zshSourceCommon}/*.zsh; do
source "$file"
done
for file in ${zshSourceUser}/*.zsh; do
source "$file"
done
autoload -U +X bashcompinit && bashcompinit
source <(kubectl completion zsh)
complete -C '/usr/local/bin/aws_completer' aws
'';
};
programs.git = {
enable = true;
userName = "Arnie";
userEmail = "i@cechis.cz";
ignores = [
".vscode"
".direnv"
".devenv"
".envrc"
];
extraConfig = {
core = {
autocrlf = "input";
# TODO: Provide through nix
hooksPath = "~/.git/hooks";
editor = "vim";
};
pull.rebase = false;
init.defaultBranch = "main";
};
};
home.sessionVariables = {
EDITOR = "vim";
GO111MODULE = "on";
};
}

View File

@ -0,0 +1,81 @@
{
config,
pkgs,
...
}:
let
username = "lcech";
homedir = "/Users/${username}";
zshSourceCommon = ../.zsh/common;
in
{
# Let Home Manager install and manage itself.
programs.home-manager.enable = true;
home.username = username;
home.homeDirectory = homedir;
home.stateVersion = "24.11";
home.packages = with pkgs; [
awscli2
k9s
kubectl
nixd
];
programs.direnv = {
enable = true;
nix-direnv.enable = true;
};
programs.zsh = {
enable = true;
dirHashes = {
mac = "${homedir}/.macshare";
};
initExtra = ''
for file in ${zshSourceCommon}/*.zsh; do
source "$file"
done
autoload -U +X bashcompinit && bashcompinit
source <(kubectl completion zsh)
complete -C '/usr/local/bin/aws_completer' aws
'';
};
programs.git = {
enable = true;
userName = "Lukas Cech";
userEmail = "lcech@veracode.com";
ignores = [
".vscode"
".direnv"
".devenv"
".envrc"
];
extraConfig = {
core = {
autocrlf = "input";
editor = "vim";
};
pull.rebase = false;
init.defaultBranch = "main";
};
};
home.sessionVariables = {
EDITOR = "vim";
GO111MODULE = "on";
};
}

69
flake.lock Normal file
View File

@ -0,0 +1,69 @@
{
"nodes": {
"home-manager": {
"inputs": {
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1735900408,
"narHash": "sha256-U+oZBQ3f5fF2hHsupKQH4ihgTKLHgcJh6jEmKDg+W10=",
"owner": "nix-community",
"repo": "home-manager",
"rev": "1c8d4c8d592e8fab4cff4397db5529ec6f078cf9",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "home-manager",
"type": "github"
}
},
"nix-darwin": {
"inputs": {
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1735685839,
"narHash": "sha256-62xAPSs5VRZoPH7eRanUn5S5vZEd+8vM4bD5I+zxokc=",
"owner": "LnL7",
"repo": "nix-darwin",
"rev": "6a1fdb2a1204c0de038847b601cff5012e162b5e",
"type": "github"
},
"original": {
"owner": "LnL7",
"repo": "nix-darwin",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1735821806,
"narHash": "sha256-cuNapx/uQeCgeuhUhdck3JKbgpsml259sjUQnWM7zW8=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "d6973081434f88088e5321f83ebafe9a1167c367",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixpkgs-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"home-manager": "home-manager",
"nix-darwin": "nix-darwin",
"nixpkgs": "nixpkgs"
}
}
},
"root": "root",
"version": 7
}

120
flake.nix Normal file
View File

@ -0,0 +1,120 @@
{
description = "nix system flake";
inputs = {
# Not manager by home manager, to update: nix flake lock --update-input <input>
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
nix-darwin.url = "github:LnL7/nix-darwin";
nix-darwin.inputs.nixpkgs.follows = "nixpkgs";
home-manager.url = "github:nix-community/home-manager";
home-manager.inputs.nixpkgs.follows = "nixpkgs";
};
outputs = inputs@{ self, nix-darwin, nixpkgs, home-manager }:
let
darwin-common = { pkgs, ... }:
let
custom-key-mapping = {
# AI Instructions
# I need a mapping that switches my keyboard keys in the following way:
# the key above TAB and left of number 1 (lets call this key NEWTILDE has a code 30064771172)
# the key between left shift and Z (lets call this key NEWPIPE has a code 30064771125)
# the key above right shift and left of the big enter key (lets call this key NEWPLUSMINUS has a code 30064771121)
#
# Write the mapping in such a way that:
# NEWTILDE switches with NEWPIPE
# NEWPIPE overrides NEWPLUSMINUS
UserKeyMapping = [
{
HIDKeyboardModifierMappingSrc = 30064771125;
HIDKeyboardModifierMappingDst = 30064771172;
}
{
HIDKeyboardModifierMappingSrc = 30064771172;
HIDKeyboardModifierMappingDst = 30064771121;
}
];
};
in
{
# List packages installed in system profile. To search by name, run:
# $ nix-env -qaP | grep wget
environment.systemPackages = with pkgs; [
git
vim
];
launchd.user.agents = {
"custom-key-mapping" = {
script = ''
/usr/bin/hidutil property --set '${builtins.toJSON custom-key-mapping}' > /dev/null
'';
serviceConfig = {
RunAtLoad = true;
};
};
};
# The platform the configuration will be used on.
nixpkgs.hostPlatform = "aarch64-darwin";
# Necessary for using flakes on this system.
nix.settings.experimental-features = "nix-command flakes";
# Set Git commit hash for darwin-version.
system.configurationRevision = self.rev or self.dirtyRev or null;
# Used for backwards compatibility, please read the changelog before changing.
# $ darwin-rebuild changelog
system.stateVersion = 5;
system.defaults = {
finder = {
_FXShowPosixPathInTitle = true; # show full path in finder title
AppleShowAllExtensions = true; # show all file extensions
FXEnableExtensionChangeWarning = false; # disable warning when changing file extension
QuitMenuItem = true; # enable quit menu item
ShowPathbar = true; # show path bar
ShowStatusBar = true; # show status bar
};
};
};
in
{
homeConfigurations = {
# init with
# nix run home-manager/master -- switch --flake ~/.config/nix
# update with
# home-manager switch --flake ~/.config/nix
"becky@dingleberry" = home-manager.lib.homeManagerConfiguration {
pkgs = nixpkgs.legacyPackages.x86_64-linux;
modules = [
./devices/becky-dingleberry.nix
];
};
};
darwinConfigurations = {
# init with
# nix run nix-darwin -- switch --flake ~/.config/nix
# update with
# darwin-rebuild switch --flake ~/.config/nix
lcech-mac-veracode = nix-darwin.lib.darwinSystem {
system = "aarch64-darwin";
modules = [
darwin-common
home-manager.darwinModules.home-manager
{
home-manager = {
useGlobalPkgs = true;
useUserPackages = true;
users.lcech = import ./devices/lcech-mac-veracode.nix;
};
users.users.lcech.home = "/Users/lcech";
}
];
};
};
};
}