cover

Manage Windows with dotfiles

sorcererxw

I recently got a new Windows device and had to reinstall all the tools I use daily and customize some projects. The whole process was quite troublesome. On the one hand, I had to remember all the various software I had installed on my original device; on the other hand, even after installing the software, I couldn't recall every detail of the configurations.

Therefore, it is essential to dataize this configuration process. This leads to the concept of a dotfile. If you have experience using Linux, you will notice that if you execute the command ls -a ~, you will find a large number of configuration files in the form of .xxx in the directory. So, a dotfile represents a configuration file. On Windows, many software use local configurations to store settings, so all you need to do is back up this file, and you can quickly restore it when migrating devices.

Git + Soft Link

Configuration files are usually in text format, which is very suitable for storage management using Git. However, a problem arises. If I modify the software configuration, do I still need to manually copy it to the Repository directory for backup?

The answer is no need. You can use symbolic links to create a file mapping, which can be understood as a shortcut on Windows. You only need to modify the configuration file in the repository, then the software can directly read this configuration.

On Linux, you can use the ln command, and there are also corresponding implementations on Windows. However, PowerShell has already provided a command New-Item, which can be used to create various types of files, including symbolic link files.

New-Item -Path <软连接文件位置> -Value <原始文件位置> -ItemType SymbolicLink -Force

Set the file type to SymbolicLink through -ItemType, symbolic links are also known as soft links.

By using -Force, you can force creation. If the corresponding file already exists, it will be overwritten.

In the future, all you need to do is pull this repository on a new device and execute the above commands, and you can quickly apply the configuration files to the corresponding software.

It should be noted that this operation requires administrator privileges, which can be obtained using the sudo tool.

Some files suitable for management with dotfiles

PowerShell style files

The default appearance of PowerShell is quite unattractive. If you want to use it, you either have to use a third-party Shell or beautify PowerShell yourself. On devices with lower performance, using the native PowerShell is a better choice.

You can use the tool concfg to quickly export and import the styles of PowerShell, including fonts, font sizes, window styles, color schemes, etc. For initial configuration, you can first use ColorTool to set up the color scheme, and then configure other properties in the PowerShell properties. Then execute concfg export , in the future, you just need to reverse the process and import it.

Here, I used the Sarasa-Gothic font and then made it bold. The color scheme was imported through ColorTool using the molokai color scheme.

PowerShell startup script

When Windows PowerShell starts, it can execute a script file to perform some custom preset configurations. The location of this file can be checked in PowerShell by executing $profile.

Similarly, from the image at the top of this article, you can see that you only need to configure this file through a symbolic link to set up the PowerShell runtime environment.

New-Item -Path $profile -Value ~/repo/dotfiles/ps_profile.ps1 -ItemType SymbolicLink -Force

The font configuration file of Telegram

The font performance of Telegram for PC version on Windows is very poor. You can replace the font through a plugin called TGFont. However, the default font replaced by TGFont is Microsoft YaHei, which does not support bold fonts within the software, and further customization is needed.

New-Item -Path "~\AppData\Roaming\Telegram Desktop\TGFont.json" -Value ~/repo/dotfiles/TGFont.json -ItemType SymbolicLink -Force

VSCode configuration file

Although the Settings Sync plugin for VSCode can already synchronize VSCode configurations through Gist, I still prefer to use Git for synchronization, which can keep consistent with the synchronization workflow of other applications.

Whether it's the installed version or the portable version of VSCode, the configuration file is ~\AppData\Roaming\Code\User\settings.json. Therefore, you only need to back up this file to synchronize across multiple devices.

New-Item -Path "~\AppData\Roaming\Code\User\settings.json" -Value ~/repo/dotfiles/vscode_settings.json -ItemType SymbolicLink -Force

One-click configuration script

When you get a new device, it's inevitable that you'll need to use the command line to configure various environments, install software with package management, configure SSH, copy configuration files, etc. Therefore, writing an initialization script, combined with various configuration files in the same repository, can quickly complete the initial configuration of the device.

Summary

Everyone has their own usage habits, and exploring your own configuration is where the efficiency and fun of this method lies.

Finally, here is the link to my dotfiles repository for your reference.