optimizing zsh on macos

Every time I open a terminal on macOS, zsh takes like a second to show the prompt. It’s super annoying!

I profiled using

 1
 2
 3
 4
 5
 6
 7
 8
 9
10

if [ -n "${ZSH_DEBUGRC+1}" ]; then
    zmodload zsh/zprof
fi

# your zsh config

if [ -n "${ZSH_DEBUGRC+1}" ]; then
    zprof
fi
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
$ time ZSH_DEBUGRC=1 zsh -i -c exit
num  calls                time                       self            name
--------------------------------------------------------------------------------
---
 1)    1          36.73    36.73   26.10%     36.73    36.73   26.10%  autoenv_i
nit
 2)    1          22.16    22.16   15.75%     22.16    22.16   15.75%  _mise_hoo
k
 3)   21          28.72     1.37   20.41%     18.10     0.86   12.86%  _omz_sour
ce
 4)    2          15.97     7.99   11.35%     15.97     7.99   11.35%  compaudit
 5)    1          13.75    13.75    9.77%     13.75    13.75    9.77%  (anon) [/
Users/mgreco/.oh-my-zsh/tools/check_for_upgrade.sh:157]
 6)    1          24.00    24.00   17.05%     10.24    10.24    7.28%  handle_up
date
 7)    1           8.93     8.93    6.34%      8.93     8.93    6.34%  zrecompil
e
 8)    1           8.81     8.81    6.26%      8.81     8.81    6.26%  test-ls-a
rgs
 9)    1          19.41    19.41   13.79%      3.44     3.44    2.44%  compinit
10)    1           0.61     0.61    0.43%      0.61     0.61    0.43%  regexp-re
place
11)    1           0.57     0.57    0.41%      0.57     0.57    0.41%  colors
12)    6           0.44     0.07    0.31%      0.44     0.07    0.31%  add-zsh-h
ook
13)    4           0.23     0.06    0.16%      0.23     0.06    0.16%  compdef
14)    2           0.22     0.11    0.16%      0.22     0.11    0.16%  is-at-lea
st
15)    8           0.14     0.02    0.10%      0.14     0.02    0.10%  addToPath
Front
16)    8           0.13     0.02    0.10%      0.13     0.02    0.10%  addToPath
17)    1          36.85    36.85   26.18%      0.12     0.12    0.08%  autoenv_c
d
18)    4           0.07     0.02    0.05%      0.07     0.02    0.05%  addToMyGi
tProjects
19)    3           0.03     0.01    0.02%      0.03     0.01    0.02%  is_theme
20)    2           0.01     0.01    0.01%      0.01     0.01    0.01%  env_defau
lt
21)    1          36.86    36.86   26.20%      0.01     0.01    0.01%  enable_au
toenv
22)    1           0.01     0.01    0.01%      0.01     0.01    0.01%  bashcompi
nit
23)    1          36.85    36.85   26.19%      0.01     0.01    0.00%  cd

--------------------------------------------------------------------------------
---

21)    1          36.86    36.86   26.20%      0.01     0.01    0.01%  enable_au
toenv
       1/1        36.85    36.85   26.19%      0.01     0.01             cd [23]

--------------------------------------------------------------------------------
---

       1/1        36.85    36.85   26.19%      0.01     0.01             enable_
autoenv [21]
23)    1          36.85    36.85   26.19%      0.01     0.01    0.00%  cd
       1/1        36.85    36.85   26.18%      0.12     0.12             autoenv
_cd [17]

--------------------------------------------------------------------------------
---

       1/1        36.85    36.85   26.18%      0.12     0.12             cd [23]
17)    1          36.85    36.85   26.18%      0.12     0.12    0.08%  autoenv_c
d
       1/1        36.73    36.73   26.10%     36.73    36.73             autoenv
_init [1]

--------------------------------------------------------------------------------
---

       1/1        36.73    36.73   26.10%     36.73    36.73             autoenv
_cd [17]
 1)    1          36.73    36.73   26.10%     36.73    36.73   26.10%  autoenv_i
nit

--------------------------------------------------------------------------------
---

 3)   21          28.72     1.37   20.41%     18.10     0.86   12.86%  _omz_sour
ce
       1/1         0.01     0.01    0.01%      0.01     0.01             bashcom
pinit [22]
       2/2         0.01     0.01    0.01%      0.01     0.01             env_def
ault [20]
       2/4         0.09     0.04    0.06%      0.09     0.04             compdef
 [13]
       2/2         0.22     0.11    0.16%      0.22     0.11             is-at-l
east [14]
       4/6         0.31     0.08    0.22%      0.31     0.08             add-zsh
-hook [12]
       1/1         0.57     0.57    0.41%      0.57     0.57             colors
[11]
       1/1         0.61     0.61    0.43%      0.61     0.61             regexp-
replace [10]
       1/1         8.81     8.81    6.26%      8.81     8.81             test-ls
-args [8]

--------------------------------------------------------------------------------
---

 6)    1          24.00    24.00   17.05%     10.24    10.24    7.28%  handle_up
date
       1/1        13.75    13.75    9.77%     13.75    13.75             (anon)
[/Users/mgreco/.oh-my-zsh/tools/check_for_upgrade.sh:157] [5]

--------------------------------------------------------------------------------
---

 2)    1          22.16    22.16   15.75%     22.16    22.16   15.75%  _mise_hoo
k

--------------------------------------------------------------------------------
---

 9)    1          19.41    19.41   13.79%      3.44     3.44    2.44%  compinit
       1/2        15.97    15.97   11.35%      0.18     0.18             compaud
it [4]

--------------------------------------------------------------------------------
---

       1/2        15.97    15.97   11.35%      0.18     0.18             compini
t [9]
       1/2        15.79    15.79   11.22%     15.79    15.79             compaud
it [4]
 4)    2          15.97     7.99   11.35%     15.97     7.99   11.35%  compaudit
       1/2        15.79    15.79   11.22%     15.79    15.79             compaud
it [4]

--------------------------------------------------------------------------------
---

       1/1        13.75    13.75    9.77%     13.75    13.75             handle_
update [6]
 5)    1          13.75    13.75    9.77%     13.75    13.75    9.77%  (anon) [/
Users/mgreco/.oh-my-zsh/tools/check_for_upgrade.sh:157]

--------------------------------------------------------------------------------
---

 7)    1           8.93     8.93    6.34%      8.93     8.93    6.34%  zrecompil
e

--------------------------------------------------------------------------------
---

       1/1         8.81     8.81    6.26%      8.81     8.81             _omz_so
urce [3]
 8)    1           8.81     8.81    6.26%      8.81     8.81    6.26%  test-ls-a
rgs

--------------------------------------------------------------------------------
---

       1/1         0.61     0.61    0.43%      0.61     0.61             _omz_so
urce [3]
10)    1           0.61     0.61    0.43%      0.61     0.61    0.43%  regexp-re
place

--------------------------------------------------------------------------------
---

       1/1         0.57     0.57    0.41%      0.57     0.57             _omz_so
urce [3]
11)    1           0.57     0.57    0.41%      0.57     0.57    0.41%  colors

--------------------------------------------------------------------------------
---

       4/6         0.31     0.08    0.22%      0.31     0.08             _omz_so
urce [3]
12)    6           0.44     0.07    0.31%      0.44     0.07    0.31%  add-zsh-h
ook

--------------------------------------------------------------------------------
---

       2/4         0.09     0.04    0.06%      0.09     0.04             _omz_so
urce [3]
13)    4           0.23     0.06    0.16%      0.23     0.06    0.16%  compdef

--------------------------------------------------------------------------------
---

       2/2         0.22     0.11    0.16%      0.22     0.11             _omz_so
urce [3]
14)    2           0.22     0.11    0.16%      0.22     0.11    0.16%  is-at-lea
st

--------------------------------------------------------------------------------
---

15)    8           0.14     0.02    0.10%      0.14     0.02    0.10%  addToPath
Front

--------------------------------------------------------------------------------
---


18)    4           0.07     0.02    0.05%      0.07     0.02    0.05%  addToMyGitProjects

-----------------------------------------------------------------------------------

19)    3           0.03     0.01    0.02%      0.03     0.01    0.02%  is_theme

-----------------------------------------------------------------------------------

       2/2         0.01     0.01    0.01%      0.01     0.01             _omz_source [3]
20)    2           0.01     0.01    0.01%      0.01     0.01    0.01%  env_default

-----------------------------------------------------------------------------------

       1/1         0.01     0.01    0.01%      0.01     0.01             _omz_source [3]
22)    1           0.01     0.01    0.01%      0.01     0.01    0.01%  bashcompinit
ZSH_DEBUGRC=1 zsh -i -c exit  0.16s user 0.18s system 38% cpu 0.873 total

So, I’ve just disabled:

UV is Shaking Up the Production Game

I’m diving headfirst into using uv in my daily grind to be more efficient in my pile of work. So, I’m throwing myself into all sorts of random scenarios.

On this journey, I’ve stumbled upon some [bugs][uv-bug] and nifty features like a super-powered cache. But, hold up! The real point of this post is how an innovation affects to the production process.

I found and issue on uv: llvmlite

I’ve found an issue with uv while creating a simple venv. Nothing fancy with my dependencies. I’ve condensed everything in this issue:

But here is the minimal reproducible example of it:

1
2
3
4
5
6
rm -rf test
uv init test
cd test
uv version
# uv venv && uv pip install numpy statsforecast
uv add numpy statsforecast

For the time being, I’m using the latest release.

Makefile based on uv

Hey there! 👋

This is a revisited version of my previous post about Makefiles, but this time I’m using uv (the shiny new Python package manager that’s faster than a caffeinated cheetah! 🐆).

I was tired of typing the same commands over and over in my Python projects, so I made this super cool Makefile using uv.

Some useful github actions

List of Github action

Automatic Release


name: Publish release

on:
  push:
    branches:
    - "main"

jobs:
    prepare-github-release:
        name: GitHub Release
        runs-on: ubuntu-latest
        outputs:
            version_tag: ${{ steps.calculate_tag_version.outputs.version_tag }}
        steps:

        - name: Checkout repository
          uses: actions/checkout@v4
          with:
            fetch-depth: 0

        - name: Manage semantic versioning
          uses: paulhatch/semantic-version@v5.4.0
          id: calculate_tag_version
          with:
            tag_prefix: ""
            major_pattern: "[MAJOR]"
            minor_pattern: "[MINOR]"
            version_format: "${major}.${minor}.${patch}"
            bump_each_commit: false
            search_commit_body: true
            debug: true

        - name: Bump version and push tag
          id: tag_version
          uses: mathieudutour/github-tag-action@v6.1
          with:
            github_token: ${{ secrets.GH_TOKEN }}
            custom_tag: ${{ steps.calculate_tag_version.outputs.version_tag }}
            tag_prefix: ""

        - name: Create a GitHub release
          uses: ncipollo/release-action@v1.14.0
          with:
            tag: ${{ steps.calculate_tag_version.outputs.version_tag }}
            name: Release ${{ steps.calculate_tag_version.outputs.version_tag }}
            body: ${{ steps.tag_version.outputs.changelog }}

Vim Tips: Running Commands

Let’s explore a few different ways to run commands in our terminal from the comfort of neovim. Trust me, it’s cooler than it sounds! 😎

Here’s a list of commands that I use all the time (and you should too!).

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# run a command
:!sh <cmd>

# execute the line and replace with the output
:.!sh

# execute without replacing
:.w !sh

# execute without replacing selection and it will persist until next selection!
:'<,'>w !sh

# execute a the line 8
:8w !sh

# execute and replace a the line 8
:8 !sh

# execute the selection in python
:'<,'>w !python -c "$(cat)"

# execute and replace the selection in python
:'<,'>!python -c "$(cat)"

Hands-on

Hey! This is my absolute favorite command ever! I use it all the time when I’m writing docs or README files because, let’s face it - who wants to manually copy-paste code outputs? Not me! 😅 Instead of doing things the boring way, I use this neat little trick to get things done quickly. Plus, it’s super handy when you want to format text using other tools too like sql queries!

Docker Compose Env Var Adventures

Let’s dive into the world of Docker Compose and environment variables, where hilarity ensues and variables come alive (or do they?).

We’ve all been there. Playing hide and seek with environment variables in Docker Compose. Let’s see how our dear friend MYVAR enjoys this grand game of Peekaboo!

Makefile

Makefile

Some times you need a good starting point, here is mine:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# variables
PYVER  := 3.10
venv   := .venv
python := $(venv)/bin/python
pip    := $(venv)/bin/pip


##@ Utility
.PHONY: help
help:  ## Display this help
	@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n  make <target>\033[36m\033[0m\n"} /^[a-zA-Z\._-]+:.*?##/ { printf "  \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)


##@ Setup
$(venv):
    @python$(PYVER) -m venv $(venv)


.PHONY: install
install: $(venv)  ## install
	$(pip) install . -r requirements.txt


##@ Development
.PHONY: dev
dev: $(venv) ## install dev mode
	$(pip) install -e .[dev]

.PHONY: test
test: $(venv) ## run tests
	$(python) -m pytest tests

.PHONY: lint
lint: $(venv)  ## run linting check
	$(python) -m ruff ./src

.PHONY: format
format: $(venv)  ## fomat code using ruff
	$(python) -m ruff format src test


.PHONY: requirements.txt
requirements.txt:  ## update requirements.txt, e.g. make requirements.txt
	@test -d /tmp/venv && rm -r /tmp/venv || true
	@$(python) -m venv /tmp/venv
	@/tmp/venv/bin/python -m pip -q install pip -U
	@/tmp/venv/bin/python -m pip -q install . --progress-bar off
	@/tmp/venv/bin/python -m pip freeze > requirements.txt