From 414602c66a13d4a126d703f385adb2c33f2e4c93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?I=C3=B1aki=20Dom=C3=ADnguez=20Ochoa?= Date: Thu, 9 Apr 2026 18:41:44 +0200 Subject: [PATCH] work setup sync --- README.md | 8 +++-- scripts/hcf/podman_setup | 70 +++++++++++++++++++++++++++++++++++++ tmux/.tmux.conf | 2 +- zsh/.zsh_aliases | 74 ++++++++++++++++++++++++++-------------- zsh/.zshenv | 4 ++- zsh/.zshrc | 15 ++------ zsh/zsh-completions | 2 +- 7 files changed, 131 insertions(+), 44 deletions(-) create mode 100755 scripts/hcf/podman_setup diff --git a/README.md b/README.md index 1ec8daf..2d3f756 100644 --- a/README.md +++ b/README.md @@ -70,6 +70,8 @@ dotfiles/ ### Extras +- podman +- wl-clipboard (Debian only) - secret-tool (Debian only) - fzf - tree-sitter-cli @@ -125,10 +127,10 @@ sudo apt update && sudo apt install terraform ```bash # System packages -sudo apt install alacritty zsh tmux stow zsh-syntax-highlighting less python3-libtmux cbonsai shfmt shellcheck lua-check secret-tool +sudo apt install alacritty zsh tmux stow zsh-syntax-highlighting less python3-libtmux cbonsai shfmt shellcheck lua-check secret-tool wl-clipboard # Homebrew packages -brew install neovim stylua lua-language-server bash-language-server prettier terraform-ls tflint ruff markdownlint-cli2 fzf tree-sitter-cli +brew install neovim stylua lua-language-server bash-language-server prettier terraform-ls tflint ruff markdownlint-cli2 fzf tree-sitter-cli podman # Node packages npm install --save-dev prettier prettier-plugin-go-template @@ -144,7 +146,7 @@ brew unlink python3 brew install curl git alacritty zsh tmux stow zsh-syntax-highlighting lesspipe cbonsai reattach-to-user-namespace # Development tools -brew install neovim stylua lua-language-server bash-language-server prettier terraform-ls tflint ruff +brew install neovim stylua lua-language-server bash-language-server prettier terraform-ls tflint ruff fzf tree-sitter-cli podman # Node packages npm install --save-dev prettier prettier-plugin-go-template diff --git a/scripts/hcf/podman_setup b/scripts/hcf/podman_setup new file mode 100755 index 0000000..856a8d0 --- /dev/null +++ b/scripts/hcf/podman_setup @@ -0,0 +1,70 @@ +#!/bin/bash + +# Script to configure podman for the local environment +# +# ./podman_setup + +set -euo pipefail + +if ! command -v podman &>/dev/null; then + echo "Error: podman is not installed" + exit 1 +fi + +case "$(uname -s)" in + Darwin*) memory=12288 ;; + Linux*) memory=8192 ;; + *) + echo "Unsupported platform" + exit 1 + ;; +esac + +if [[ "$(uname -s)" == Darwin* ]]; then + helper_plist="/Library/LaunchDaemons/com.github.containers.podman.helper-$(whoami).plist" + if [[ ! -f "$helper_plist" ]]; then + echo "Installing podman-mac-helper (requires sudo)..." + sudo podman-mac-helper install + fi +fi + +if ! podman machine inspect &>/dev/null; then + echo "Initializing podman machine with 4 CPUs and $((memory / 1024))GB RAM..." + podman machine init --rootful --cpus 4 --memory "$memory" +fi + +if [[ "$(uname -s)" == Darwin* ]]; then + rosetta=$(podman machine inspect --format '{{.Rosetta}}') + if [[ "$rosetta" != "true" ]]; then + echo "Warning: Rosetta translation is not enabled on this podman machine." + fi +fi + +state=$(podman machine inspect --format '{{.State}}') +case "$state" in + running) + echo "Podman machine is already running." + ;; + stopped) + echo "Starting podman machine..." + podman machine start + ;; + *) + echo "Error: podman machine is in unexpected state: $state" + exit 1 + ;; +esac + +case "$(uname -s)" in + Darwin*) resolved_ip=$(dscacheutil -q host -a name host.docker.internal 2>/dev/null | awk '/^ip_address:/{print $2; exit}') ;; + *) resolved_ip=$(getent hosts host.docker.internal 2>/dev/null | awk '{print $1}') ;; +esac +if [[ -z "$resolved_ip" ]] || ! echo "$resolved_ip" | grep -qE '^(127\.|::1$)'; then + echo "Adding host.docker.internal to /etc/hosts (requires sudo)..." + echo "127.0.0.1 host.docker.internal" | sudo tee -a /etc/hosts >/dev/null +fi + +if [[ ! -e /usr/local/bin/docker ]]; then + echo "Creating docker symlink to avoid issues with projects that do not inherit aliases (requires sudo)..." + sudo ln -s "$(command -v podman)" /usr/local/bin/docker +fi diff --git a/tmux/.tmux.conf b/tmux/.tmux.conf index 2ebd6e0..d34d48b 100644 --- a/tmux/.tmux.conf +++ b/tmux/.tmux.conf @@ -25,7 +25,7 @@ bind '"' split-window -v -c "#{pane_current_path}" bind % split-window -h -c "#{pane_current_path}" ### set-environment -g PATH "$HOMEBREW_PREFIX/bin:$PATH" -bind C-o popup -E -E -d "#{pane_current_path}" -w 90% -h 90% "opencode" +bind o popup -E -E -d "#{pane_current_path}" -w 66% -h 66% bind-key -n C-S-Down next-window bind-key -n C-S-Up previous-window diff --git a/zsh/.zsh_aliases b/zsh/.zsh_aliases index 2421319..136eca2 100644 --- a/zsh/.zsh_aliases +++ b/zsh/.zsh_aliases @@ -7,14 +7,13 @@ alias tmux_secondary_win='tmux new-session -t main -s secondary' # enable color support of ls and also add handy aliases alias ls='ls --color=auto' alias grep='grep --color=auto' -alias fgrep='fgrep --color=auto' -alias egrep='egrep --color=auto' +alias fgrep='grep -F --color=auto' +alias egrep='grep -E --color=auto' + +alias docker=podman alias d='dirs -v' -# shfmt needs to ignore this because it is a zsh specific syntax -# shfmt:ignore:start -for index ({1..9}) alias "c$index"="cd +${index}"; unset index -# shfmt:ignore:end +for index in 1 2 3 4 5 6 7 8 9; do alias "c$index"="cd +${index}"; done; unset index alias kpget="keepassxc-cli show -a Password ${KEEPASS_DB}" alias kptotp="keepassxc-cli show -t ${KEEPASS_DB}" @@ -26,7 +25,7 @@ _KP_KEYCHAIN_SVC="keepassxc-cli-cache" _KP_KEYCHAIN_ACCT="master-password" _kp_pw_store() { - case "$(uname -s)" in + case "$UNAME_STRING" in Darwin) security add-generic-password -U \ -s "$_KP_KEYCHAIN_SVC" -a "$_KP_KEYCHAIN_ACCT" -w "$1" @@ -39,7 +38,7 @@ _kp_pw_store() { } _kp_pw_get() { - case "$(uname -s)" in + case "$UNAME_STRING" in Darwin) security find-generic-password \ -s "$_KP_KEYCHAIN_SVC" -a "$_KP_KEYCHAIN_ACCT" -w 2>/dev/null @@ -52,7 +51,7 @@ _kp_pw_get() { } _kp_pw_clear() { - case "$(uname -s)" in + case "$UNAME_STRING" in Darwin) security delete-generic-password \ -s "$_KP_KEYCHAIN_SVC" -a "$_KP_KEYCHAIN_ACCT" &>/dev/null @@ -87,12 +86,30 @@ function load_gemini() { } function totp() { + local clip=false + [[ "$1" == "-c" ]] && clip=true && shift + + local code case "$1" in - hcf) kptotps "personal/Dev/AWS Console" ;; - aws) kptotps "work/Own/AWS console" ;; - pci) kptotps "work/Own/PCI/AWS Workspaces" ;; - *) echo "Usage: totp {hcf|aws|pci}" >&2; return 1 ;; + hcf) code=$(kptotps "personal/Dev/AWS Console") ;; + aws) code=$(kptotps "work/Own/AWS console") ;; + pci) code=$(kptotps "work/Own/PCI/AWS Workspaces") ;; + *) echo "Usage: totp [-c] {hcf|aws|pci}" >&2; return 1 ;; esac + + echo "$code" + if $clip; then + case "$UNAME_STRING" in + Darwin) echo -n "$code" | pbcopy ;; + Linux) if [[ "$XDG_SESSION_TYPE" == "wayland" ]]; then + echo -n "$code" | wl-copy + else + echo -n "$code" | xclip -selection clipboard + fi ;; + + esac + echo "(copied to clipboard)" + fi } _get_aws_config_path() { @@ -147,16 +164,23 @@ _awsume_cmd() { alias asm="_awsume_cmd" -alias tf="terraform" -alias tfi="tf init" -alias tfp="tf plan -lock=false" -alias tfa="tf apply" -alias tfu="tf get -update" -alias tg="terragrunt" -alias tgi="tg init" -alias tgp="tg plan -lock=false" -alias tga="tg apply" -alias tgu="tg get -update" +_ensure_awsume() { + if [[ -z "$AWSUME_PROFILE" ]]; then + echo "No awsume session found. Starting one..." + _awsume_cmd || return 1 + fi +} + +tf() { _ensure_awsume && terraform "$@"; } +tfi() { _ensure_awsume && terraform init "$@"; } +tfp() { _ensure_awsume && terraform plan -lock=false "$@"; } +tfa() { _ensure_awsume && terraform apply "$@"; } +tfu() { _ensure_awsume && terraform get -update "$@"; } +tg() { _ensure_awsume && terragrunt "$@"; } +tgi() { _ensure_awsume && terragrunt init "$@"; } +tgp() { _ensure_awsume && terragrunt plan -lock=false "$@"; } +tga() { _ensure_awsume && terragrunt apply "$@"; } +tgu() { _ensure_awsume && terragrunt get -update "$@"; } alias curltime="curl -w \"@$HOME/.curl-format.txt\" -o /dev/null -s " @@ -196,7 +220,7 @@ git_push() { local branch branch=$(git branch --show-current) - git push origin "$branch" $@ + git push origin "$branch" "$@" } alias gpush="git_push" @@ -204,7 +228,7 @@ alias gpush="git_push" passgen() { length=${1:-"12"} if [[ "$length" == <-> ]]; then - echo $(cat /dev/urandom| base64 | head -c "$length") + echo $(cat /dev/urandom| base64 -w0 | head -c "$length") else echo "passgen() takes a positive integer as first argument" echo "got $length" diff --git a/zsh/.zshenv b/zsh/.zshenv index f00c6ec..e8ee8a0 100644 --- a/zsh/.zshenv +++ b/zsh/.zshenv @@ -22,6 +22,8 @@ export SSH_ENV="$HOME/.ssh/agent-environment" export GOPRIVATE="gitlab.feedzai.com,git.hcf.zone" +export UNAME_STRING=$(uname -s) + . "$HOME/.cargo/env" # Interactive shells (e.g. new tmux windows): set PATH so we don't need a login shell. @@ -30,7 +32,7 @@ if [[ -t 0 ]]; then export PATH=~/.local/bin:$PATH export PATH=~/.dotnet:$PATH export PATH=$DOTFILES/scripts/hcf/:$PATH - case "$(uname -s)" in + case "$UNAME_STRING" in Linux*) eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)" ;; Darwin*) eval "$(/opt/homebrew/bin/brew shellenv)" diff --git a/zsh/.zshrc b/zsh/.zshrc index 52f2912..10417cc 100644 --- a/zsh/.zshrc +++ b/zsh/.zshrc @@ -1,11 +1,8 @@ -setopt INC_APPEND_HISTORY setopt EXTENDED_HISTORY # Write the history file in the ':start:elapsed;command' format. setopt HIST_EXPIRE_DUPS_FIRST # Expire a duplicate event first when trimming history. setopt HIST_FIND_NO_DUPS # Do not display a previously found event. setopt HIST_IGNORE_ALL_DUPS # Delete an old recorded event if a new event is a duplicate. -setopt HIST_IGNORE_DUPS # Do not record an event that was just recorded again. setopt HIST_IGNORE_SPACE # Do not record an event starting with a space. -unsetopt HIST_SAVE_NO_DUPS # Do not write a duplicate event to the history file. setopt SHARE_HISTORY # Share history between all sessions. bindkey -e @@ -25,15 +22,11 @@ setopt PUSHD_SILENT # Do not print the directory stack after pushd or popd. DISABLE_AUTO_TITLE="true" # install zsh-syntax-highlighting -case "$(uname -s)" in +case "$UNAME_STRING" in Linux*) { source /usr/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh - # make less more friendly for non-text input files, see lesspipe(1) local lesspipe_bin_location - lesspipe_bin_location=$(which lesspipe) - if [ $? -eq 0 ]; then - [ -x $lesspipe_bin_location ] && eval "$(lesspipe)" - fi + (($+commands[lesspipe])) && eval "$(lesspipe)" } ;; Darwin*) { # Use HOMEBREW_PREFIX (set in .zshenv) to avoid slow brew --prefix subprocess on every new shell @@ -137,7 +130,3 @@ function +vi-git-extra() { fi fi } - -### MANAGED BY RANCHER DESKTOP START (DO NOT EDIT) -export PATH="/Users/inaki.dominguez/.rd/bin:$PATH" -### MANAGED BY RANCHER DESKTOP END (DO NOT EDIT) diff --git a/zsh/zsh-completions b/zsh/zsh-completions index 922abfe..8b97eaf 160000 --- a/zsh/zsh-completions +++ b/zsh/zsh-completions @@ -1 +1 @@ -Subproject commit 922abfe7073bc7af2d6950712670ceb5de73d4aa +Subproject commit 8b97eaf521ba04e6fef021f144a2650b0d6aa0da