Snippets are one of my favorite parts of programming. The shear endless depth of command line
tricks and customizations is so exciting! Here is a collection I maintain for myself to comeback to.
Recently I started using twtxt. I
installed it with brew then setup it up via the quick setup command. The
problem is when you put a config file location other then the default when
you call the command you get a
“✗ Config file not found or not readable. You may want to run twtxt quickstart.”
error. This is super annoying so I aliased the command to always include the location of my
config file.
alias gpf="gp --force"
+ alias tw="twtxt -c ~/.twtxt/config"
Now posting is as easy as:
$ tw tweet "authoring a snippet on how to configure alias twtxt"
Hosting side projects in kubernetes and using gitlab container registry? This
is the command I run to create the needed secret for the cluster to pull the
image:
Half my time in the editor I’m not coding, I’m just browsing the file system trying to understand how things are connected. Trying figure out what needs to change in order to complete my task. This module imports this module which imports this module… There are many ways to navigate the file system and read files. Since I primarily code in VIM there are two main ways I navigate.
One is using the file explorer from plugin, NerdTree. It is great for getting a general overview of folder structure of a project and moving, deleting, or creating new files. Also really good for finding sibling files using the :NerdTreeFind command which I have remapped to . Where is lacks however is opening a nested import for example. When you want to jump to a different file / module directly.
This is where the goto file comes in. Using the following commands in conjunction with moving up and down the jump list, navigation is easy. Here is an example where I use the goto command and a few of its variations.
demo using vim's goto and jumplist commands
The most helpful ones to learn are
<g><f> goto file, same window
<c-w><f> goto file, new split
<c-w><g><f> goto file, new tab
Also don’t forget to use the jump list
<c-o> or in my case remapped to <Leader><i> to jump backwards
Exampled by the errors in my blog posts, spelling is not my strength. Never was. Always felt focusing on spelling limited my vocabulary. So I rely on tech. From the first red squiggly line in MS Word to now.
I recently used this to backup my ~/.pass-storepass
repo. Basically it’s a folder full of .gpg files each encrypting a password. Don’t want to store
it on a remote host so I back it up locally. Create a git bundle then I encrypt the resulting bundle
file and store it somewhere safe.
I’ve used several fuzzy finder utilities in vim over the years like
Command T or
CtrlP. They both have there pluses and
minuses but never found them to be that fast especially with large code bases
I’m often working in. Fzf for me is superior so I was excited to see a plugin
that integrates Fzf so well into vim. Its not just useful for finding files but
works great with buffers, files with git changes, commands, marks, and even
lines in open buffers.
One of my oldest snippets is how to Pretty print JSON
in the shell. This method works great for simple things where you just need to get an idea
of the JSON structure, it has the bonus of using python which you probably already have
installed. The problem is when you want to do more complex tasks it is quite limited in terms of
parsing. Thats where jq comes in
Simply piping to jq pretty prints the JSON
but by passing a query string, ex ".entrypoints .sharedHeader .assets",
you dig into the JSON and easily get what you need. This is easily
combinable with other shell utilities like in the example above which gets a
list of asset URLs than uses ripgrep invert-match to clean out the source map
URLs from the list. This is now my perfered way of working with JSON in the shell.
Something code reviews can be a bit monotonous but I always found emojis spice things up a bit.
Unfortunately my xterm based terminal does not support normal UTF-8 emojis. When pasted directly
from apple emoji keyboard I get nothing. Today I sought out a solution to this and found you can
simply use :wrench: like shortcodes, similar to how emojis are handled in slack. Seems to work
for both gitlab and github!