Quickly Edit Posts

Search for a command to run...

No comments yet. Be the first to comment.
I've slowly adding more and more lua functions into my neovim configuration, and recently I noticed a pattern for a class of functions that reach out to run shell commands that can be abstracted away. https://youtu.be/8m5ipBuopPU Telegraph.nvim Check...

Kedro can have a chatty logger. While this is super nice in production so see everything that happened during a pipeline run. This can be troublesome

In 2021 I changed the way I navigate between tmux sessions big time. Now I can create, kill, switch with ease, and generally keep work separated into
People who are quick to toss team members under a bus are not well trusted or highly thought of and it will lead to some toxic team dynamics. Building Steam While collaborating on any project there are going to be decisions made that aren't necessari...

I create this blog with one person in mind, me. There are others like me This is not completely selfish, as there are likely many others out there that think similarly to me. Everyone comes from different backgrounds and varying levels of experience...

Recently I automated starting new posts with a python script. Today I want to work on the next part that is editing those posts quickly.
Quickly Edit PostsRecently I automated starting new posts with a python script. Today I want to work on the next part that is editing tho read more waylonwalker.com |
Check out this post about setting up my posts with python 🐍
For the process of editing a post I just need to open the file in vim quickly. I dont need much in the way of parsing and setting up the frontmatter. I think this is a simple job for a bash script and fzf.
For this, I am going to go with a bash function. This is partly due to being able to track where I was and get back. Also, the line with nvim will run fzf every time you source your ~/.alias file which is not what we want.
Let's set up the boilerplate. It's going to create a function called ep "edit post", track our current directory, create a sub-function _ep. Then call that function and cd back to where we were no matter if _ep fails or
succeeds.
boilerplate
ep () {
_dir=$(pwd)
_ep () {
# open file here
}
_ep && cd $_dir || cd $_dir
}
check out this post for more information about writing reusable bash scripts.
Let's focus in on that _ep function here that is going to do the bulk of the work to edit the post.
cd to where I want to edit from
cd ~/git/waylonwalkerv2/
Next I need to find all markdown pages within my posts directory. There is probably a better way to filter with the find command directly, but I am not worried about perf here and I knew how to do it without google.
find all markdown
find ~/git/waylonwalkerv2/src/pages/ | grep .md$
Now that we can list all potential posts, sending the selected post back to neovim is as easy as piping those files into fzf inside of a command substitution that is called with neovim.
putting together the edit command
$EDITOR $(find ~/git/waylonwalkerv2/src/pages/ | grep .md$ | fzf)
final ep function
ep () {
_dir=$(pwd)
_ep () {
cd ~/git/waylonwalkerv2/
$EDITOR $(find ~/git/waylonwalkerv2/src/pages/ | grep .md$ | fzf)
}
_ep && cd $_dir || cd $_dir
}