[go: up one dir, main page]

Notes

Small posts that doesn't need to be a blog/article.

Coding Otaku

Subscribe: JSON Feed | Atom Feed

Posts

Using en-dash and em-dash in SwayWM with Compose

Profile of Coding Otaku

Published on:

While many think that people who use en-dash or em-dash are using LLMs, it’s pretty easy to do with a keyboard, and I use it quite a lot in my blogs.

Most keyboards available now has a compose key, and even if it doesn’t, the operating system can usually handle it by mapping the compose key to another less-used key.

In my SwayWM configuration, I have the following:

input type:keyboard {
                  xkb_options "ctrl:nocaps, compose:ralt"
                }
                

The first option makes the caps lock key behave as Ctrl key. The second option makes the right Alt key behave as the compose key.

To type an en-dash (–), I have to press and release the right Alt key, then type --. (two dashes followed by a period/full stop/dot).

To type an em-dash (β€”), I have to press and release the right Alt key, then type --- (three dashes).

I’ve been using it for too long that I instinctively try to type it that way on all other systems and be disappointed. Just lookup how to do it in your system, it can usually be done without any configuration or installing anything new!

Dynamic Script Execution with fzf

Profile of Coding Otaku

Published on:

A simple and modular script to organize and run scripts using fzf

I have got a number of scripts in my system to configure thing or to do some common tasks faster. But what’s the point of having scripts if you always need to remember the file name, the path, or even the alias? So this is a small script that will list all executable files in a single directory, and execute them on select.

#!/usr/bin/env sh
                
                name=$(basename "$0")
                path="${1:-$(pwd)}"
                
                while true; do
                    options=$(find "${path}" -maxdepth 1 -executable -type f -not -name "${name}" -exec basename '{}' \; | tr '-' ' ')
                    choice=$(printf '%s\nExit' "${options}" |
                        fzf --height=10 --header='Select What to do' --layout=reverse --prompt='choice > ' |
                        tr '[:upper:]' '[:lower:]' | tr ' ' '-')
                
                    [ -z "${choice}" ] || [ "${choice}" = "exit" ] && exit
                
                    "${path}/${choice}"
                done
                

Save it to $HOME/.local/bin/fexe. You could have scripts arranged in any folder you would like, and you may want to add alias to use them.

I have an alias set like alias fzettings='fexe $HOME/code/shell/fzettings'. and $HOME/code/shell/fzettings has several scripts that configure the system.

One thing to note is to write the script names in kebab-case (hyphenated-file-name-like-this) so that the script can replace hyphens with a space when listing them. If you do not like that behaviour, remove the tr commands (| tr '-' ' ') and (| tr ' ' '-') in the fexe script.

Just like all my other small scripts, it’s very simple, effective, and prone to security issues.

Another Managa App Bites the Dust

Profile of Coding Otaku

Published on:

Kotatsu, the manga app that became famous after Tachiyomi was forced to shut down, has… shut down.

If you now navigate to the project, you will be greeted with the following important message:

In light of recent challenges β€” including threating actions from Kakao Entertainment Corp and upcoming Google’s new sideloading policy β€” we’ve made the difficult decision to shut down Kotatsu and end its support. We’re deeply grateful to everyone who contributed and to the amazing community that grew around this project.

Kotatsu is just one of many specialized browsers that fought through legal challenges to help Manga fans read their favourite manga without distractions. I say specialized browser because that’s what Kotatsu and similar programs do, they just show the website content, cleans up irrelevant stuff, and add a way to easily navigate between chapters/pages. People who actually read the Manga and Comic from bot official and unofficial websites will also block/remove the distractions in one or the other way to enjoy what they want to read.

The same goes for Anime too. The reason for both Anime and manga being popular outside Japan is because of fans translating and aggregating them. Not because of the official Dub or the official translations that worsens over time.

As the world is becoming increasingly hostile to almost everything that could improve the daily life, it is no surprise that apps like Kotatsu and Tachiyomi who live in a gray area can’t survive.

So what now? Kotatsu shutting down does not mean that the Manga fans will just stop reading Manga, they will all just flock to some other app or website. What lacks in the industry is a true official Aggregator platform. Nobody wants to subscribe to yet another service to read just one or two Manga or watch a few Anime. So it is just a matter of time before we find an alternative.

Shameless plug, I am working on Ani-GUI, a GUI client inspired from ani-cli. Make sure to fork it πŸ˜‰.

Setting Charge Level Threshold in Lenovo Laptops

Profile of Coding Otaku

Published on:

You can find this documented in many places on the internet. This note is just a backup for the future me.

Looking at /sys/class/power_supply/BAT0/capacity_level, I see that the capacity is stored in 0-100 percentage values. This makes things easier.

What we need to modify are the following:

  1. Set when to stop charging: /sys/class/power_supply/BAT0/charge_stop_threshold
  2. Set until when the battery should start charging when plugged in: /sys/class/power_supply/BAT0/charge_start_threshold

The charge_start_threshold used to confuse me. So a table would help.

Assume that charge_start_threshold is 50, and charge_stop_threshold is 100.

Current Battery LevelCurrent Battery StatusNew Battery Status
45DischargingCharging
45ChargingCharging
55DischargingNot Charging
55ChargingCharging

The key one is the last two rows, if the battery level is above the charge_stop_threshold and is unplugged, it would not charge the battery. But If the batter was already charging and hit the charge_start_threshold, it would continue to charge until charge_stop_threshold is met.

I also noticed that when the charge_start_threshold needs to be changed, the kernel would not allow setting it above charge_stop_threshold. The reverse is also true.

Keeping it all in mind, I will set three battery profiles.

ProfileCharge startCharge stop
Home4550
Away7580
Full95100

Like all my other utility scripts, this will also use fzf.

Selecting profile

profile=$(printf 'Home\t45%%\t50%%\nAway\t75%%\t80%%\nFull\t95%%\t100%%' | fzf --height=6 --header="$(printf 'Type\tStart\tMax')" --layout=reverse --prompt='Charge level > ' | cut -f1)
                

This gives me a tabular view of the profiles and charge level in case I forget the values.

Functions to set charge levels

set_start() {
                    echo "${1}" | sudo tee /sys/class/power_supply/BAT0/charge_start_threshold >/dev/null
                }
                
                set_stop() {
                    echo "${1}" | sudo tee /sys/class/power_supply/BAT0/charge_stop_threshold >/dev/null
                }
                

Now that I am looking at this, I probably should remove sudo dependency from the script. But I use it excessively in my daily life, feel free to remove it or replace it with other tools.

Set charge level based on selected profile

if [ "${profile}" = "Home" ]; then
                    set_start 45
                    set_stop 50
                elif [ "${profile}" = "Away" ]; then
                    start=$(head -n 1 /sys/class/power_supply/BAT0/charge_start_threshold)
                    # Handle charge level conflict
                    if [ "${start}" -gt 75 ]; then
                        set_stop 80
                        set_start 75
                    else
                        set_start 75
                        set_stop 80
                    fi
                elif [ "${profile}" = "Full" ]; then
                    set_stop 100
                    set_start 95
                else
                    exit 137
                fi
                

The complete script

Combine them all, and ensure POSIX compatibility.

#!/usr/bin/env sh
                
                profile=$(printf 'Home\t45%%\t50%%\nAway\t75%%\t80%%\nFull\t95%%\t100%%' | fzf --height=6 --header="$(printf 'Type\tStart\tMax')" --layout=reverse --prompt='Charge level > ' | cut -f1)
                
                set_start() {
                    echo "${1}" | sudo tee /sys/class/power_supply/BAT0/charge_start_threshold >/dev/null
                }
                
                set_stop() {
                    echo "${1}" | sudo tee /sys/class/power_supply/BAT0/charge_stop_threshold >/dev/null
                }
                
                if [ "${profile}" = "Home" ]; then
                    set_start 45
                    set_stop 50
                elif [ "${profile}" = "Away" ]; then
                    start=$(head -n 1 /sys/class/power_supply/BAT0/charge_start_threshold)
                
                    if [ "${start}" -gt 75 ]; then
                        set_stop 80
                        set_start 75
                    else
                        set_start 75
                        set_stop 80
                    fi
                elif [ "${profile}" = "Full" ]; then
                    set_stop 100
                    set_start 95
                else
                    exit 137
                fi
                

Using Fuzzel to Manage Clipboard History in Wayland

Profile of Coding Otaku

Published on:

I use Fuzzel for almost everything, but I forgot that I also manage the clipboard also with it until today.

I don’t usually use clipboard manager, in fact, I even forgot that this script existed with a key binding in my window manager.

The required packages are just cliphist and fuzzel.

It provides the option to copy a text/multimedia from the history, delete an item from history, and delete all items from the history.

I bind it to the Mod+C keyboard shortcut in SwayWM, today I accidentally pressed it and instead of Ctrl+C and remembered that I had this set up.

Here is the script:

#!/usr/bin/env sh
                
                tolower() {
                    tr '[:upper:]' '[:lower:]'
                }
                
                delete() {
                    cliphist delete
                }
                
                copy() {
                    cliphist decode | wl-copy
                }
                
                history() {
                    while true; do
                        item=$(cliphist list | fuzzel -d --prompt='History > ')
                        [ -z "${item}" ] && return 130
                
                        choice=$(printf 'Copy\nDelete' | fuzzel -d --prompt='History > ' | tolower)
                        [ -z "${choice}" ] && return 130
                
                        printf '%b' "$item" | "${choice}"
                
                        if [ "${choice}" = 'copy' ]; then
                            return 0
                        fi
                    done
                }
                
                wipe() {
                    choice=$(printf 'Yes\nNo' | fuzzel -d --prompt='Wipe clipboard? ' | tolower)
                    [ -z "${choice}" ] || [ "${choice}" = 'no' ] && return 130
                
                    cliphist wipe
                
                    exit 0
                }
                
                while true; do
                    hist_count=$(cliphist list | wc -l)
                
                    if [ "${hist_count}" -eq 0 ]; then
                        choice=$(printf 'Exit' | fuzzel -d --prompt='Nothing in clipboard history, exit > ' | tolower)
                    else
                        choice=$(printf 'History\nWipe\nExit' | fuzzel -d --prompt='Clip Manager > ' | tolower)
                    fi
                    [ -z "${choice}" ] && exit 130
                    [ "${choice}" = 'exit' ] && exit 0
                
                    if "${choice}"; then
                        exit 0
                    fi
                done
                

It might look long, that’s because I wrote it with POSIX compatibility in mind.

Always Use the Location Flag in Curl

Profile of Coding Otaku

Published on:
Last updated on:

The --location or -L will let curl redirect if the route was changed and the webmaster has set up proper redirects. For example, my curl card was at https://codingotaku.com/cc, after I did my website updates, it is now https://codingotaku.com/static/uploads/9bca2ae5-7643-4a1c-bb0c-fe37136f6cb1/6bed3782-f72c-4bfb-aa14-842bf4d09aa8.bin because that’s how I set up my uploads.

domain.tld/cc is very easy to remember, and I would like to keep it that way. So set up a redirect for it so that people can still access my curl card with curl -sL https://codingotaku.com/cc

Likewise, some of my feeds and old posts also has redirect set up so that people who stored my posts offline can still access them.