Skip to content

Blog

Install fonts in Linux

Copy the fonts files to ~/.local/share/fonts/. Then, run fc-cache to rebuild fonts cache.

fc-cache -fv

Git submodule

Frequently used commands for Git submodules.

Add a submodule

TO add the reference to another git project as a submodule:

git submodule add $url $path
git submodule update --init --recursive

Alternatively, you can use GUI tools like or GitHub desktop. They download and initiate submodules automatically.

Add you will see the file .gitmodules with information about the submodule(s). For instance,

.gitmodules
[submodule "themes/DoIt"]
    path = themes/DoIt
    url = https://github.com/HEIGE-PCloud/DoIt.git

Track a specific branch in the submodule

With -b $branch option

git submodule add -b $branch $url $path

Or set-branch -b $branch if you already have added a submodule

git submodule set-branch -b  $branch $path

Update all Git submodules to the latest commit

From a stackOverflow post and Git docs

git submodule update --remote --merge

For automated updates by bots, see automatic dependency update.

Remove a submodule

From Git docs

# Remove submodule from config
git submodule deinit $path
# Delete submodule tracking data
git rm <submodule path> && git commit
# Complete removal
rm -rf $GIT_DIR/modules/$name/

SSH login to GitHub and GitLab

Generate a pair of SSH keys

ssh-keygen -t ed25519 -C "your_email@example.com"

The SSH agent will ask you to enter a location to save the keys. e.g. /home/user/.ssh/id_ed25519. Passphrase is optional.
Then there will be two SSH key files:

  • ~/.ssh/id_ed25519 is the private key. Protect it at all costs.
  • ~/.ssh/id_ed25519.pub is the public key.

Using different keys for GitHub and GitLab access is more secure. However, the same pair of keys is used for this demonstration purposes.

Add remote to the SSH settings

Edit ~/.ssh/config

mkdir -p ~/.ssh
touch ~/.ssh/config
chmod 600 ~/.ssh/config
nano ~/.ssh/config

Add the following content to set the private key as the IdentityFile.

~/.ssh/config
Host GitHub
  HostName github.com
  IdentityFile ~/.ssh/id_ed25519

Host GitLab
  HostName gitlab.com
  IdentityFile ~/.ssh/id_ed25519

Add the SSH key to your GitHub account

According to 📖 Github docs, add the SSH key here

  • Paste the content of the public key, ~/.ssh/id_ed25519.pub to the key field.
  • Add a descriptive label for the new key in the "Title" field.
  • Finally, click the Add SSH key green button. If prompted, confirm your GitHub password.

Add the SSH key to your GitLab account

Add the SSH key here

  • Paste the content of the public key, ~/.ssh/id_ed25519.pub to the key field.
  • Add a descriptive label for the new key in the "Title" field.
  • Select an expiration date.
  • Finally, click the Add key button.

Test your setup

GitHub:

ssh -vT git@github.com

Accept its fingerprint if prompted. If you see "Hi user! You've successfully authenticated, but GitHub does not provide shell access" that means login is successful.

GitLab:

ssh -vT git@gitlab.com

Accept its fingerprint if prompted.

Strip Jupyter Notebook Output

Jupyter notebooks without multimedia outputs are more friendly to source control since git is not good at comparing binary data (e.g., plots, pictures, videos) in jupyter notebooks. And they tend to bloat the size of git repositories.

Environment variables

Linux environment variables

Arch Wiki: environment variables

System-wide

  • /etc/profile is sourced by all POSIX-compatible shells upon login.
  • Files inside the /etc/profile.d/ directory will also be read.

Bash

  • ~/.profile or ~/.bash_profile for login bash instances.
  • ~/.bashrc for every interactive bash instance.

Zsh

  • ~/.zshenv for environment variables in all zsh instances.
  • ~/.zprofile for every login zsh instance.
  • ~/.zshrc for every interactive zsh instance.

Note

zsh does not source ~/.profile by default because of the difference between bash and zsh syntaxes. You can add this line to ~/.zprofile or ~/.zshenv to make zsh shells read `~/.profile correctly.

~/.zshenv
skip_global_compinit=1
test -r ${HOME}/.profile && emulate sh -c 'source ${HOME}/.profile'

X Window

  • ~/.xinitrc is sourced by startx.
  • ~/.xprofile is sourced by display managers (e.g., GDM, SDDM)

Systemd and Wayland

  • ~/.config/environment.d/*.conf: sourced by systemd. Also, they are used in Wayland sessions where xinitrc and xprofile files are not available.

Windows environment variables

Environment variables in Powershell

Session variables

Variables created by set are bound to the current session and not persistent.

$Env:FOO = "example"
$Env:FOO

Persistent variables

  • GUI: Windows Settings -> Advanced system settings -> Set Environment Variables.
  • Powershell: [Environment]::SetEnvironmentVariable('KEY', 'VAL', 'Machine')
  • Cmd: SETX KEY VAL

Removing large binary blobs in the git tree

Git filter-repo is a filter-branch replacement for rewriting history written in a single-file python script.

To wipe large binary files entirely:

git filter-repo --strip-blobs-bigger-than 100M

Bonus: Remove sensitive content

git filter-repo --use-base-name --path id_dsa --path id_rsa --invert-paths
git filter-repo --replace-text passwords.txt