Recently I added two new bash/zsh aliases to make my git experience just a tad better.
trackme #
Most of our work repos were recently migrated to new remote urls, we scriped
out the update to all of the repos, but I was left with a tracking error for
all of my open branches. To easily resolve this I just made an alias so that I
can just run trackme anytime I see this error.
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details
git pull <remote> <branch>
If you wish to set tracking information for this branch you can do so with:
git branch --set-upstream develop origin/<branch>
getting the branch #
The following command will always return the currently checked out branch name.
git symbolic-ref --short HEAD
Injecting this into the suggested git command as a subshell gives us this
alias that when ran with trackme will automatically fix tracking for my
branch.
alias trackme='git branch --set-upstream-to=origin/$(git symbolic-ref --short HEAD)'
rebasemain #
I sometimes get a bit lazy at checking main for changes before submitting any prs, so again I made a quick shell alias that will rebase main into my branch before I open a pr.
alias rebasemain='git pull origin main --rebase'
The Aliases #
Here are both of the alias’s, feel free to steal and modify them into your
dotfiles. If you are uniniatiated a common starting place to put these is
either in your ~/.bashrch or ~/.zshrc depending on your shell of choice.
alias trackme='git branch --set-upstream-to=origin/$(git symbolic-ref --short HEAD)'
alias rebasemain='git pull origin main --rebase'
So many terminal applications bind q to exit, even the python debugger, its
muscle memory for me. But to exit ipython I have to type out exit<ENTER>.
This is fine, but since q is muscle memory for me I get this error a few times
per day.
╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│ <ipython-input-1-2b66fd261ee5>:1 in <module> │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
NameError: name 'q' is not defined
After digging way too deep into how IPython implements its ExitAutoCall I
realized there was a very simple solution here. IPython automatically
imports all the scripts you put in your profile directory, all I needed was to
create ~/.ipython/profile_default/startup/q.py with the following.
q = exit
It was that simple. This is not a game changer by any means, but I will now
see one less error in my workflow. I just press q<Enter> and I am out,
without error.
It’s no secret that I love automation, and lately my templating framework of
choice has been copier. One hiccup I recently ran into was having spaces in my
templated directory names. This makes it harder to run commands against as you
need to escape them, and if they end up in a url you end up with ugly %20 all
over.
Cookiecutter has the solution #
Yes the solution comes from a competing templating framework.
I install copier with pipx, so I need to inject cookiecutter in to my copier environment to use the slugify filter.
pipx inject copier cookiecutter
If you are using a normal virtual environment you can just pip install it.
pip install copier cookiecutter
add the extension to your template #
copier.yml
Now to enable the extension you need to declare it in your copier.yml file in
your template.
_jinja_extensions:
- cookiecutter.extensions.SlugifyExtension
Use it | slugify #
use-it
Now to use it, anywhere that you want to slugify a variable, you just pipe it into slugify.
❯ tree .
.
├── copier.yml
├── README.md
└── {{ site_name|slugify }}
└── markata.toml.jinja
1 directory, 3 files
Here is a slimmed down version of what the copier.yml looks like.
site_name:
type: str
help: What is the name of your site, this shows in seo description and the site title.
default: Din Djarin
_jinja_extensions:
- cookiecutter.extensions.SlugifyExtension
Results #
Running the template looks a bit like this.
straight from their docs #
The next section is straight from the cookiecutter docs
Slugify extension #
The cookiecutter.extensions.SlugifyExtension extension provides a slugify
filter in templates that converts string into its dashed (“slugified”) version:
{% "It's a random version" | slugify %}
Would output:
it-s-a-random-version
It is different from a mere replace of spaces since it also treats some special
characters differently such as ' in the example above. The function accepts
all arguments that can be passed to the slugify function of
python-slugify_. For example to change the output from
it-s-a-random-version to it_s_a_random_version, the separator parameter
would be passed: slugify(separator='_').
Textual has devtools in the upcoming css branch, and its pretty awesome!
It’s still early #
Textual is still very early and not really ready for prime time, but it’s quite amazing how easy some things such as creating keybindings is. The docs are coming, but missing right now so if you want to use textual be ready for reading source code and examples.
On to the devtools #
As @willmcgugan shows in this tweet it’s pretty easy to setup, it requires having two terminals open, or using tmux, and currently you have to use the css branch.
https://twitter.com/willmcgugan/status/1531294412696956930
Why does textual need its own devtools #
Textual is a tui application framework. Unlike when you are building cli applications, when the tui takes over the terminal in full screen there is no where to print statement debug, and breakpoints don’t work.
getting the css branch #
In the future it will likely be in main and not need this, but for now you need to get the css branch to get devtools.
git clone https://github.com/Textualize/textual
git fetch --alll
git checkout css
install in a virtual environment #
Now you can create a virtual environment, feel free to use whatever virtual environment tool you want, venv is built in to most python distributions though, and should just be there.
python3 -m venv .venv --prompt textual
source .venv/bin/activate
pip install .
Now that we have textual installed #
Once textual is installed you can open up the devtools by running textual console.
textual console