From 0fb18993227b03aa68df9fb1c906bcac24cd72ca Mon Sep 17 00:00:00 2001 From: cronekorkn Date: Thu, 25 May 2023 10:57:39 +0200 Subject: [PATCH] macbook more managed --- .envrc | 32 +++----------------------------- bundles/macbook/files/bundlewrap | 6 ++++++ bundles/macbook/files/gnu | 8 ++++++++ bundles/macbook/files/pyenv | 9 +++++++++ bundles/macbook/files/ssh | 3 +++ bundles/macbook/files/venv | 23 +++++++++++++++++++++++ bundles/macbook/files/zshrc | 28 ++++++++++++++++++++++++++++ bundles/macbook/items.py | 17 +++++++++++++++++ 8 files changed, 97 insertions(+), 29 deletions(-) create mode 100644 bundles/macbook/files/bundlewrap create mode 100644 bundles/macbook/files/gnu create mode 100644 bundles/macbook/files/pyenv create mode 100644 bundles/macbook/files/ssh create mode 100644 bundles/macbook/files/venv create mode 100644 bundles/macbook/files/zshrc diff --git a/.envrc b/.envrc index 3cf9eac..656f765 100644 --- a/.envrc +++ b/.envrc @@ -1,31 +1,5 @@ #!/usr/bin/env bash -if test -f .venv/bin/python && test "$(realpath .venv/bin/python)" != "$(realpath "$(pyenv which python)")" -then - echo "rebuilding venv für new python version" - rm -rf .venv -fi - -python3 -m venv .venv -source .venv/bin/activate -PATH_add .venv/bin -PATH_add bin -python3 -m pip --require-virtualenv --quiet install --upgrade pip wheel -python3 -m pip --require-virtualenv --quiet install --upgrade -r requirements.txt - -# git deploy cache -export BW_GIT_DEPLOY_CACHE=".cache/bw/git_deploy" -CREATED_AT=$(stat -f "%Sa" "$BW_GIT_DEPLOY_CACHE" | xargs -I{} date -f '%b %d %H:%M:%S %Y' -j "{}" '+%s') -NOW_AT=$(date +%s) -SECONDS_SINCE=$(expr "$NOW_AT" - "$CREATED_AT") -if [[ "$SECONDS_SINCE" > 86400 ]] -then - rm -rf "$BW_GIT_DEPLOY_CACHE" -fi -mkdir -p "$BW_GIT_DEPLOY_CACHE" - -export EXPERIMENTAL_UPLOAD_VIA_CAT=1 -export BW_ITEM_WORKERS=32 -export BW_NODE_WORKERS=12 -export DISK_CACHE_DIR=.cache/cache_to_disk -unset PS1 +source_env ~/.local/share/direnv/pyenv +source_env ~/.local/share/direnv/venv +source_env ~/.local/share/direnv/bundlewrap diff --git a/bundles/macbook/files/bundlewrap b/bundles/macbook/files/bundlewrap new file mode 100644 index 0000000..17e365a --- /dev/null +++ b/bundles/macbook/files/bundlewrap @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +cd "$OLDPWD" + +export BW_ITEM_WORKERS=$(expr $(nproc) '*' 2) +export BW_NODE_WORKERS=$(expr 256 '/' "$BW_ITEM_WORKERS") diff --git a/bundles/macbook/files/gnu b/bundles/macbook/files/gnu new file mode 100644 index 0000000..6833adc --- /dev/null +++ b/bundles/macbook/files/gnu @@ -0,0 +1,8 @@ +#!/usr/bin/env bash + +cd "$OLDPWD" + +GNU_PATH="$HOME/.local/gnu_bin" +mkdir -p "$GNU_PATH" +test -f "$GNU_PATH/sed" || ln -s "$(which gsed)" "$GNU_PATH/sed" +PATH_add "$GNU_PATH" diff --git a/bundles/macbook/files/pyenv b/bundles/macbook/files/pyenv new file mode 100644 index 0000000..770cfec --- /dev/null +++ b/bundles/macbook/files/pyenv @@ -0,0 +1,9 @@ +#!/usr/bin/env bash + +cd "$OLDPWD" + +if test -f .venv/bin/python && test "$(realpath .venv/bin/python)" != "$(realpath "$(pyenv which python)")" +then + echo "rebuilding venv für new python version" + rm -rf .venv +fi diff --git a/bundles/macbook/files/ssh b/bundles/macbook/files/ssh new file mode 100644 index 0000000..ce14e25 --- /dev/null +++ b/bundles/macbook/files/ssh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +cd "$OLDPWD" diff --git a/bundles/macbook/files/venv b/bundles/macbook/files/venv new file mode 100644 index 0000000..73e4711 --- /dev/null +++ b/bundles/macbook/files/venv @@ -0,0 +1,23 @@ +#!/usr/bin/env bash + +cd "$OLDPWD" + +python3 -m venv .venv +source ./.venv/bin/activate +PATH_add .venv/bin + +NOW=$(date +%s) +if test -e .pip_upgrade_timestamp +then + LAST=$(cat .pip_upgrade_timestamp) +else + LAST=0 +fi +DELTA=$(expr "$NOW" - "$LAST") +echo "last pip upgrade $DELTA seconds ago" +if test "$DELTA" -gt 86400 +then + python3 -m pip --require-virtualenv install pip wheel --upgrade + python3 -m pip --require-virtualenv install -r requirements.txt --upgrade + date +%s > .pip_upgrade_timestamp +fi diff --git a/bundles/macbook/files/zshrc b/bundles/macbook/files/zshrc new file mode 100644 index 0000000..021af20 --- /dev/null +++ b/bundles/macbook/files/zshrc @@ -0,0 +1,28 @@ +export PATH=~/.bin:$PATH +export ZSH=~/.zsh/oh-my-zsh +ZSH_THEME="ckn" +HIST_STAMPS="yyyy/mm/dd" +plugins=( + zsh-autosuggestions + git +) +source $ZSH/oh-my-zsh.sh + +ulimit -S -n 24000 + +sshn() { + ssh "$(tr '.' ' ' <<< "$1" | tac -s ' ' | xargs | tr ' ' '.').smhss.de" +} +pingn() { + ping "$(tr '.' ' ' <<< "$1" | tac -s ' ' | xargs | tr ' ' '.').smhss.de" +} + +antivir() { + printf 'scanning for viruses' && sleep 1 && printf '.' && sleep 1 && printf '.' && sleep 1 && printf '.' && +sleep 1 && echo '\nyour computer is safe!' +} + +eval "$(rbenv init -)" +eval "$(pyenv init -)" +eval "$(direnv hook zsh)" +eval "$(op completion zsh)"; compdef _op op diff --git a/bundles/macbook/items.py b/bundles/macbook/items.py index b59bac7..6103551 100644 --- a/bundles/macbook/items.py +++ b/bundles/macbook/items.py @@ -1,9 +1,26 @@ directories['/Users/mwiegand/.config/bundlewrap/lock'] = {} +# home + +files['/Users/mwiegand/.zshrc'] = { + 'source': 'zshrc', + 'mode': '0644', +} + +# updater + files['/Users/mwiegand/.bin/macbook-update'] = { 'mode': '755', } +# direnv + +directories['/Users/mwiegand/.local/share/direnv'] = {} +files['/Users/mwiegand/.local/share/direnv/gnu'] = {} +files['/Users/mwiegand/.local/share/direnv/pyenv'] = {} +files['/Users/mwiegand/.local/share/direnv/venv'] = {} +files['/Users/mwiegand/.local/share/direnv/bundlewrap'] = {} + ################## for element in [*files.values(), *directories.values()]: