Categories
Angular Opinions Tutorials

TIL Week 27 2023: Stow, fzf, Angular Router gotchas

This is regular week update, of things I have discovered in my daily workflow. Its a nice place to come back in future. I also share because this might help other developers. They might come across similiar situation.

Stow – Manage config file

Up until this point I was only working on single machine to develop. All the config files for editors, shell, terminal commands were either created by program or I might have created once and forget about it.

After second machine, I found it redundant and not proper to copy and paste files. I thought a repo with all the files hosted somewhere online is a safe place. Which worked. I would change the nvim config files on one machine and would sync it with other machine.

If you are only using one piece of software that this method works but If you need share the config files for other tools in your daily life. Then you need a different mechanism. Because each app will use different folder structure for default configuration.

Stow is just the right tool, it looks for structure in your, lets say .dotfiles repo and creates symbolic link accordingly.

├── alacritty
│   └── .config
│       └── alacritty
├── nvim
│   └── .config
│       └── nvim
├── ohmyposhv3-v2.json
├── package.json
├── zellij
│   └── .config
│       └── zellij
└── zsh
    └── .zshrc

As you can see above the alacritty, zellij, nvim goes inside the .config folder inside user folder. and zsh goes lives on the root level of user folder ( aka ~ folder).

In Action

Let’s see how stow commands works as we can see below

    stow -nvt ~ nvim
UNLINK: .config/nvim stow -vDt ~ nvim
UNLINK: .config/nvim

Let’s break down what the command

  • -n : Use in simulation mode or dry run the command
  • v: Verbose
  • t: target folder to apply the configuration
  • nvim: name of the application. We can * to target all the app in our dotfiles repo

Once you are sure, you can run the command with out the n flag. It will symbolically do the linking.

     stow -vDt ~ nvim
UNLINK: .config/nvim

fuzzy search file and open it – fzf

In one of my project I was using leaflet.js as dependency. My editor was giving me it’s type definition. I thought to read the file directly. I thought of using ripgrep but it follows the .gitignore and would ignore anything inside node_modules

Incomes the fzf. As soon as you type fzf in your terminal there will be interactive prompt. Where you can enter file and it will narrow the search as bellow

using fzf file to search for leaflet.js file inside the project

This will just list the file as below

    node_modules/leaflet/dist/leaflet-src.js

But we can do more to even file in the editor of our choice

    nvim -o `fzf`

// for visual studio code
code -g `fzf`

RIP rather than rm -rf

rm removes the non-directory files. If you process it with -rf flag that it becomes dangerous as you won’t get any confirmation prompts.

    rm -rf node_modules
// will recursively remove all the files and folders

And the fun part is that it is not recoverable, easily. Maybe backup would help but in my case it, I didn’t had the back. So work is lost, permanently

In comes rip an ergonomic and safer command line utility. It creates a tmp/graveyard folder with user name and creates the exact folder structure from where the file is deleted.

The good thing is that you can undo the action

     rip -s
/tmp/graveyard-$username/Users/$username/file/to/path/file.json

routerLinkActiveOptions

Since we are at the version 16 or angular (at the time of writing this article). Standalone components are pretty stable. In order for below link to work

    <a routerLink="/user/bob" routerLinkActive="active-link" [routerLinkActiveOptions]="{exact:
true}">Bob</a>

We need to import RouterLink and RouterLinkActive. This will throw an error in the lines of

routerLinkActiveOptions is not a property of a.

That’s because routerLinkActiveOptions isn’t available as a separate import. At least I couldn’t found. In order to solve it, you can remove the other Router imports and replace it with RouterModule

Conclusion

That’s it for this week. I still have to setup some parts of machine. I am lately in to this command line stuff. I prefer using the external specific tools rather than make the editors. I would like to explore this area more.

I am also working on Angular library and recent features of v16 and I would to write about them more.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.