Anyways, a couple posts ago I shared how to sort tags in different ways, the truth is I’ve been meaning to do some cleaning up, inspired by Adam’s post.
He used the usual commands such as sed
and grep
, and I decided to quickly write a script to edit the desired tags for any file in a similar manner.
#!/usr/bin/bash
#
file=$1
oldtags=$(cat $1 | grep "tags:" | head -1 | awk '{for (i=2; i<NF; i++) printf $i " "; print $NF}')
echo $oldtags > /tmp/tagedit
vim /tmp/tagedit
newtags=$(cat /tmp/tagedit)
rm -fv /tmp/tagedit
sed -i "s/$oldtags/$newtags/g" "$file"
This code is rather simple, it takes the path of a file, which is given as an argument, running something like
./edit-tags.sh filename
That filename is parsed, using grep, head and awk. a new temporary file containing all existing tags of that file gets opened with vim, containing the existing tags. From there I can add or remove tags as I please, and once saved, I replace the original file accordingly.
It is rather simple, and I think it could be done better. So please, I beg you to give me any suggestions to improve it. I tried my best to understand stuff like getopts
and the like, to have arguments and flags but I just didn’t really get it.
Regardless, this is day 5 of my second attempt at #100DaysToOffload
]]>So I decided to keep both webp and jpg files available. I am not sure of what makes a browser choose one over the other. For now, I pretty much copy pasted the solution used by Simone on his blog, I only added some code to support .gif
files, since WebP supports animation too.
Implementing this was not difficult at all. I created a file inside of my _includes
folder containing the following template:
<figure class="{{ include.class | default: 'img' }}">
<picture>
<source srcset="{{ include.image | replace:'.png','.webp' | replace:'.jpg','.webp' | replace:'.jpeg','.webp' | replace: '.gif','.webp' }}" type="image/webp">
<source srcset="{{ include.image }}" {% if include.image contains '.jpg' or include.image contains '.jpeg' %}type="image/jpeg"{% elsif include.image contains '.png' %}type="image/png" {%elsif include.image contains '.gif'%}type="image/gif"{% endif %}>
<img class="mx-auto" src="{{ include.image }}" alt="{{ include.alt | default: include.caption }}" {{ include.width ? include.width | prepend: 'width="' | append: '"' }} {{ include.height ? include.height | prepend: 'height="' | append: '"' }}>
</picture>
{% if include.caption %}<figcaption class="caption">{{ include.caption }}</figcaption>{% endif -%}
</figure>
Now all I have to do when using an image in a blogpost is provide both a webp and a jpg/png/gif file with the same filename, and use the following template:
{% include img.html image="/path/to/assets/image.jpg" width="512px" alt="Alternate text" caption="A caption" %}
I was already using Jekyll’s includes for a lot of things, such as the comments system, the articles of blogs I follow and other things. Its a really powerful tool that I quite like. However, editing each existing file could take me a long time. I actually did a poll on mastodon to see what people would do. As of the writing of this post, most people say they would handle this by hand. And, to be honest, that’s kinda what I did, but I had some tricks up my sleve.
Using macros with Vim is simply fantastic, I took a while to mention them, for some reason, all I had to do was implement 2 macros for the different kinds of markup I’ve used. Be it plain markdown (![title](source)
) or plain html (<figure><img></img><figcaption></figcaption></figure>
). There were a couple of edge cases, like when I included links inside of the captions and such.
There are many examples and videos that talk about doign Vim macros, so I will just share some videos of how they worked out.
For Markdown, I pretty much look for ![
and then used Vim keybindings to go word for word w
, to the end of the line $
and such, rinse and repeat.
The steps to make a macro for HTML were a bit more complicated, but doable nonetheless.
My macro had some problems, since I was doing dt"
to delete the contents of something until a quote showed up, along other similar things, adding a link to a figcaption
broke my macro in a couple cases. But other than that, it worked alright. I also had to run my macro from a certain position relative to the HTML, or else other things would not work properly.
I guess doing macros is pretty much its own artform, I’ve seen some uses for them that blew me away. If you have not used them for anything before, you might want to give them a try next time you script something!
If I am honest, I still don’t know how I feel about it making use of includes in this way, since making the changes here was kinda annoying. But, thinking about it, it only took me like half an hour to do. I don’t know, maybe simply using something like xclip
or xdotool
to quickly access the plain HTML template would be a lot better to keep my markdown platform agnostic. I will think about it, but for now Jekyll is still my platform of choice.
tar
my whole .config
and copied the file to an external drive.
That works fine, but it’s not the best way to backup the constant changes I usually do to customize the way my programs look or act, and as a customization freak, that happens quite often.
I had seen many different ways to backup dotfiles: git bare repos, yadm, symlinking scripts, and of course, GNU Stow.
All of these methods have their up and downs, but in the end, stow
convinced me, and I decided to give it a try. According to their home page:
GNU Stow is a symlink farm manager which takes distinct packages of software and/or data located in separate directories on the filesystem, and makes them appear to be installed in the same place.
If you don’t really understand it yet, don’t worry, I don’t either! But in this blog, I will do my best to show you the steps to backup your current config files, I hope whoever reads this finds it useful.
The first step to backup your dotfiles, is to create an empty repository in some hosting service, such as GitHub, Codeberg or SourceHut. This is optional if you only want to see how stow
works, but necessary to have an external backup outside your computer. Once you are done, clone the empty repo to your home directory, or in any place you want. (This tutorial will be using the home directory).
To clone a repo, just do:
git clone https://site.com/link/to/repo
In my case, I use Tildegit, a Gitea instance, so my command looks like this.
git clone https://tildegit.org/chrono/dotfiles.git
You can clone my dotfiles if you want to use them, here they are if you are interested.
Before actually backing something up, we need to install stow
, depending on your distribution, you can install it with your package manager of choice. In my case, Endeavor is based on Arch, so I do:
$ sudo pacman -S stow
Lets start by backing up the configuration of a single program. While we can backup our whole .config
folder, that’s not a good idea, since some programs store important information that should stay private, and I think its better to only backup what we have actually configured. For this example, I will backup my picom
configurations.
The first step is to create a new directory to use as a base (if you cloned your empty repo, you’ll be using that). You also have to create a folder structure, depending on where you want the configuration to be stored, this depends on the location the program will read its configuration from. We’ll refer to this folder as dotfiles
.
If you want to add a README
file or other stuff that you is not a config files, you can create another directory inside of dotfiles
, in my case, I have made a stow_home
folder, which will be where we’ll run the stow
command. 1
Lets explain how stow
works. Picom expects its config file in ~/.config/picom/picom.conf
, so, inside of the new home_stow
directory, we recreate that folder structure, but using the program name (picom
) instead of the tilde (~
), which usually refers to the home folder. 2
Lets put all of this together in the terminal.
mkdir dotfiles && cd dotfiles # mkdir only if you didn't clone it
touch README.md other_file.txt # optional
mkdir -p ~/dotfiles/stow_home/picom/.config/picom/
mv ~/.config/picom/ ~/dotfiles/stow_home/picom/.config/
Once you do that, your picom folder is no longer in the .config
directory, but inside of dotfiles/home_stow
, following the same folder structure, as if home_stow
was the /home
directory, followed by the user picom
and the path to the picom configuration files. 3
Now we repeat this process with all of the files and directories we want to back up. Once done, the behavior of the programs you use, such as vim
, should revert to their default configurations, since the user config files are no longer there. So, now its time to fix that! Inside of stow_home
, run the following command:
stow -vt ~ *
This will symlink everything inside of stow_home
4, targetting ~
as the starting point. The -v
flag will let you know of everything being done, so you should see an output like this, depending on the programs you backed up:
# $ stow -vt ~ *
LINK: .config/awesome => ../dotfiles/stow_home/awesome/.config/awesome
LINK: .config/bat => ../dotfiles/stow_home/bat/.config/bat
LINK: .config/dunst => ../dotfiles/stow_home/dunst/.config/dunst
LINK: .config/nvim => ../dotfiles/stow_home/nvim/.config/nvim
LINK: .config/picom => ../dotfiles/stow_home/picom/.config/picom
LINK: .config/rofi => ../dotfiles/stow_home/rofi/.config/rofi
LINK: .config/spectrwm => ../dotfiles/stow_home/spectrwm/.config/spectrwm
If you stumbled upon this guide, you probably know the necesary git
commands to backup everything to the service you chose at the beginning of this guide.
Generally, everytime you do changes you only need to follow these three commands, inside of your dotfiles
folder.
git add *
git commit -m "Added config files"
git push
Remember that the last command will not work if you don’t have an external repository.
The manual of GNU Stow contains a lot more than what I mentioned here, like unlinking and other flags that can be used and might be useful for your use case.
Anyways, that’s all folks, this has been day 54 of #100DaysToOffload, you can check out my dotfiles if you want to see how stow
looks once setup, besides, my Spectrwm configuration is quite sick if I do say so myself.
If you feel like a step is not clear enough, please let me know in the comments or via e-mail.
So, if you read until the end of this blog. I actually did a pretty decent bash script to automate everything here.
All you need to do is configure it to your liking and run it like this
dotstow file_or_folder
The script is as follows, it uses basic tools like cut
and of course, stow
#!/usr/bin/bash
# Dotstow - Backup your chosen dotfiles in one go using stow.
# Run it outside of the folder/file you want to back up
# $ dotstow file-or-program
# This program was made by joelchrono12
STOW_DIR=$HOME/dotfiles/stow_home
DIR=$(pwd | cut -d '/' -f4-)
NEW_DIR=$STOW_DIR/$1/$DIR
mkdir -pv $NEW_DIR
mv -v $1 $NEW_DIR
cd $STOW_DIR
stow -vt ~ $1
The program does not check if a folder already exists or anything like that. So feel free to send any suggestions and changes to it in a comment or using git send-email to my email address.
You can just use dotfiles as is without a folder inside it, but if you want to be able to quickly deploy everything using *
, you must make a folder where README and other files you don’t want to symlink won’t interfere . ↩
Other files, like .bashrc
, are not in the .config
folder, keep in mind that the path to use depends on where the program needs it to be. In this case, it would have to be placed in ~/dotfiles/stow_home/bash/.bashrc
. ↩
You can also move specific files of a configuration folder. For example, tut
, a mastodon client, saves the account data (passwords, etc) inside of another file in its configuration folder. if thats the case. You should move only the files you want, instead of the whole directory. stow
should manage the rest. ↩
If you are unsure about the paths you created, you can run the -n
flag to simulate the output and see exactly where each symlink would be placed. That way you dont end up symlinking in the wrong place and doing weird stuff to your filesystem. ↩
I really, really liked Spectrwm, I might as well go back to it in a few days, since the main reason I am moving away from it might not be that hard to fix. I find the system tray to be quite useful to me, my choice was trayer, since it was good enough. However, I had some problems that made it feel pretty clunky.
wmctrl
Honestly, most of these problems are not a big deal most of the time. But as I said, I am doing this mainly out of boredom, so let me be.
Installing dwm also came to mind, and I decided to give it a try, but right now I can’t wrap my head around it, but I might check it out later.
For quite some time, I have heard good things about Qutebrowser. So I have decided to give it a try. I actually loved it, I really liked the way it works and I found myself extremely comfortable using Vim keybindings on it. I really enjoyed how smooth it was and the keyboard driven workflow.
Its engine is now based on Chromium, which is a bit annoying since I support Firefox’s Gecko. However it now will display most websites better than when it was using WebKit as a base.
So right now I decided to go back to Firefox, and set it up in a similar manner to HexDSL’s configuration, which has tabs on the left side and gets rid of most of the GUI, making it pretty nice looking to me. I will change to Qutebrowser once I set it up properly and get ad-blocking on it.
For now, Firefox + VimVixen will do to give me that Vim-like workflow. I actually can’t believe how handy and nice it is.
After all this, I have also been thinking about changing my distro once again. I have enjoyed void for quite a while, and its great, with no doubt, I might just be a bit inspired while writing this and I might end up not switching after all.
I have been considering something like EndeavourOS, or maybe reinstalling Void, but base only, we will see. I am a bit tempted by the “terminal driven” workflow the claim to have, I already have that on Void, but I am still curious.
Also, I will change my Android rom soon. I haven’t updated it in a while, and I have been looking for a bit more customization than what I already have. I have downloaded CrDroid, which has an official rom available for my Redmi Note 8, so I will give it a try later today.
Syncthing and Migrate are great tools for making backups, and I think I will have to install minimal Gapps due to school stuff, and because I got some paid apps I can’t live without, such as Nova Launcher or Typing Hero. I am working towards changing that, but not right now.
I always feel quite dirty when I have to change rom and reinstall the Google apps, especially when I try to defend FOSS and Android in general, but well, you gotta do what you gotta do.
Anyways, after all of this I gotta say I am quite happy with the changes I’ve done, and I hope the ones I still have to make will be good too. I have had some problems with time management, and I know that it’s kind of a meme the amount of time you invest on setting everything up on Linux to get actual work done. But well, I enjoy it, and I still managed to deliver all of my homework! So I consider this a win. I have exams next week, so let’s see what happens with that.
This has been day 34 of #100DaystoOffload
]]>But that blog helped me to see, and recognize some of problems and annoyances I have with my current workflow.
Recently, I started to use Neovim to make my blogs, like the one you are reading right now. And since I am already trying to be as minimal as possible, I decided to make a script that helped me do the following things
So, doing a script on linux is kinda easy, because of the way UNIX like systems work, I can make use of small utilities that can do small things and wrap everything together to make new useful scripts to automate the little things. In my case, I made something like this.
#! /bin/bash
echo "Type filename"
read name
filename=$(date +"%Y-%m-%d"-$name)
touch /path/to/_posts/$filename.md
printf '%b\n' "$(cat /path/to/_template.md)" >> /path/to/_posts/$filename.md
alacritty -e nvim /path/to/_posts/$filename.md
In this case, echo
allows me to print text, just like printf
, to keep the format of my template.md
file, containing the metadata of the blog, sp I only have to fill it out (I could probably automate this too, honestly).
I used date
to create the and format the filename of the post, as well as add the given title using read
(I cannot use spaces, but I always use dashes -
anyways).
I used touch
to create the markdown file and place it in the right locations.
Finally, I open the file on Neovim in a new terminal window (my choice is alacritty).
And that was it! I actually managed to do it. I am not sure if I could make it even simpler, but I am happy with the result. I can now start my blogs in a better way than before, where I copied and pasted everything from a previous file, that I had to open and close and I also had to be type the path of the file and make it and all of the usual stuff. But hey, now it’s everything automated for me!
Also! I also made some changes to the font sizes of this blog, and other CSS things, just because I felt that everything was a little too big, and I didn’t feel like scrolling that much just to get past the title. I think I still have to tweak it a little bit, but it is a good start.
This was day 23 of #100DaystoOffload, let me know if you found this kinda useful for you too. Or if you have a better script or anything that you use to make your blog workflow better!
]]>Most other editors, like Gedit, which is the GUI editor I use for most simple things, doesn’t really offer any way to check for errors, and even though I try to type correctly, sometimes I just miss a letter, or an accent (Especially because I do most of my homework and note taking in Spanish, English is too easy in comparison).
So anyways, I have decided to try and do this blog using Neovim and only that, with the help of a few external programs to help me deal with the caveats that using terminal editor brings.
I installed a few plugins that I saw in some videos, such as Goyo and Limelight, that are supposed to help focus on typing and only that (I am struggling to get Limelight to work with the Nord color scheme, I will sort it out later). But I have seen a few others that can do more powerful stuff, like prettifying tables made with pipes and such, as well as automatically hiding markdown elements like *italics*
and __boldness__
, as well as [hyperlinks](https://https://joelchrono.xyz)
. But I am currently seeing all of this pretty clearly.
Also, I found a pretty epic terminal utility called Aspell, which is quite a life-saver, since, as its name implies, it is pretty useful to check for mistakes and errors in this text.
All I have to do is install the right dictionaries, and run the following command:
$ aspell -l en_US --mode markdown -c file.md
And that will look for mistakes and correct them in case there are any, as you can see in this screenshot:
To be honest, I just wanted to have something to type right now. Since I have been a little busy with University and was struggling to keep up with my blog.
Now I am going to share a little screenshot of how this setup looks, because why not?
So, yeah this was not that hard to do, there are still some things I have to figure out, luckily, most of these tools will also be useful for my homework workflow so, that’s a win for me! This has been day 21 of #100DaystoOffload
]]>