Skip to content

Latest commit

 

History

History
242 lines (240 loc) · 6.53 KB

notes.org

File metadata and controls

242 lines (240 loc) · 6.53 KB

Configuration

Dotfiles

sudo apt install git stow ripgrep aspell htop
git clone --recursive git@github.com:andschwa/dotfiles.git
cd dotfiles
./install.sh

No password for sudo

sudo sed -i "s/%sudo	ALL=(ALL:ALL)/%sudo	ALL=(ALL) NOPASSWD:/g" /etc/sudoers

Ubuntu

Change LTS to Normal and upgrade

sudo sed -i "s/Prompt=lts/Prompt=normal/g" /etc/update-manager/release-upgrades
sudo do-release-upgrade

Packages

sudo add-apt-repository ppa:git-core/ppa
sudo add-apt-repository ppa:ubuntu-elisp/ppa
sudo apt update
sudo apt install git emacs-snapshot stow ripgrep aspell xorg
sudo apt install dos2unix shellcheck ppa-purge

Install font

E.g. Cascadia Code

mkdir ~/.local/share/fonts
mv Cascadia.ttf ~/.local/share/fonts
fc-cache -f -v

WSL Setup

Bash configuration

~/.local/share/bash/env.bash

# Use X410 Display: https://x410.dev/cookbook/wsl/using-x410-with-wsl2/
export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2; exit;}'):0.0

# Scale Emacs GUI: https://www.emacswiki.org/emacs/SetFonts#toc4
export GDK_SCALE=2 GTK_THEME=Adwaita

# Move all Windows paths to the end of PATH
IFS=':' read -ra paths <<< "$PATH"
for dir in "${paths[@]}"; do
    if [[ $dir == /mnt/* ]]; then
        path_back "$dir"
    fi
done

~/.local/share/bash/interactive.bash

# Fix WSL Time: https://github.com/microsoft/WSL/issues/4245
sudo hwclock -s

X setup

This are needed to support X apps (like Emacs) even though the X server is forwarded. Specifically this fixes the clipboard.

sudo apt install xorg

Filesystem

Swap file

Digial Ocean Guide

sudo swapon --show
sudo fallocate -l 1G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
sudo swapon --show
sudo cp /etc/fstab /etc/fstab.bak
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab

RAM disk

sudo mkdir /mnt/ramdisk
sudo mount -t tmpfs -o rw,size=8G tmpfs /mnt/ramdisk

Git

Checkout original merge conflict

Also undoes git rerere recorded resolution.

git checkout -m

Grep all changes

git log -G<pattern>

List authors

# sorted
git log --format='%aN' | sort -u -k 2
# by commit count
git shortlog -sne

Push to two remote repos at once

Just add a second URL to the desired remote in .git/config.

Ignore changes to tracked files

git update-index --assume-unchanged <file>

Refer to commit by message

git commit --fixup :/foo

Find common ancestor

git merge-base topic master
git merge-base --fork-point topic

Replace HTTP with SSH

[url "ssh://git@github.com/"]
    insteadOf = https://github.com/

History manipulation

git-filter-repo

SSH

Port forwarding

-v
verbose
-N
no command
-T
no TTY

Local (outbound) tunnel

Here we want to access the local port (on the client) and have the traffic tunneled to the remote host and port on the server’s side.

ssh -v -N -T -L <local port>:<remote host>:<remote port> <server>

Remote (inbound) tunnel

Here we want to access the local port (on the server) and have the traffic tunneled to the remote host and port on the client’s side.

ssh -v -N -T -R <local port>:<remote host>:<remote port> <server>
sudo apt install sshguard
sudo journalctl -u sshguard

Debugging

Recovery shell

to TTY
ctrl+alt+(F1|F2|F3)
and back
alt+(F7|F8|F9)

Networking

List all active ports

# New tool:
ss
# Old tool:
netstat -tulpn

Manual DNS lookup

nslookup andschwa.com

IRC

/msg nickserv identify andschwa <password> /msg nickserv release/recover andschwa <password>

Scripting

Bash

Linting

Use ShellCheck or the website. Read the Bash Guide and Bash Pitfalls.

Test for command

# POSIX-compliant
command -v foo >/dev/null 2>&1 || { echo >&2 "Missing foo"; exit 1; }
# Caches path with Bash
hash foo 2>/dev/null || { echo >&2 "Missing foo"; exit 1; }

Compound tests

[[ (-e foo) && ! (-e bar) ]] && echo "foo exists but not bar"

Command-line interface

while :; do
    case $1 in
        -h|--help)
            cat << EOF
Usage:
    foo [-f|--files] <file1,file2,...>
    foo [-h|--help]
        Prints this help.
EOF
            exit
            ;;
        -f|--files)
            if [[ -n $2 ]]; then
                IFS=$',' read -r -a files <<< "$2"
                shift
            else
                exit 2
            fi
            ;;
        --)
            shift
            break
            ;;
        -?*)
            echo "Unknown option: $1"
            exit 1
            ;;
        *)
            break
    esac
    shift
done

Replace multiple pairs

while read from to; do
    find . -name "*.cmake" -or -name "CMakeLists.txt" | xargs sed -i "s/$from/$to/g"
done < replacements.txt

PowerShell

Any-Thing | Get-Member
Get-Command | Select-String "Invoke*"
Any-Thing | where {$_.Property -gt 3}
ls env:
Remove-Module

Build systems

GNU Make

Automatic Variables

$@
The file name of the target of the rule.
$<
The name of the first prerequisite.
$^
The names of all the prerequisites, with spaces between them.

Autotools

Generate configure and build

autoconf -vfi
./configure
make

Fix libraries

Some projects will generate an ld configuration file in /etc/ld.so.conf.d/, so update the cache with sudo ldconfig -v.