I spend a lot of time in terminals, and over the years I’ve accumulated a small collection of aliases and functions that save me from typing the same commands over and over.
These are not meant to be a complete dotfiles setup. They’re simply the ones I actually use and find useful.
My current shell configuration lives in my dotfiles repository. You can also browse the much larger dotfiles collection on GitHub.
Shell shortcuts
A few small aliases for everyday navigation and reloading my shell:
alias ls="ls -G --color=auto"
alias ll="ls -lah"
alias la="ls -a"
alias l="ll"
alias shreload="exec $SHELL"
alias shdebug="DOTFILES_DEBUG=1 exec $SHELL"I use ll and la constantly, while shreload is handy after changing my
shell configuration.
The debug version is useful when I’m working on the dotfiles themselves:
shdebugwhich starts a new shell with debugging enabled.
Git
Git is probably where my aliases save the most typing.
Everyday Git
These are the ones I use constantly:
alias g="git"
alias gs="git status -sb"
alias gd="git diff"
alias gds="git diff --staged"
alias gl="git log --pretty=short"
alias gc="git commit -m"
alias gac="git add . && git commit -m"
alias gpom="git push origin main"
alias gpo="git push origin"
alias glo="git pull origin"
alias gb="git checkout"
alias gbn="git checkout -b"So instead of:
git status -sbI use:
gsAnd:
gbn feature/new-thingcreates and switches to a new branch.
Rebasing and cleaning up commits
When I have a few messy commits locally, I usually clean them up before pushing:
alias grm="git rebase -i origin/main"For example:
grmopens an interactive rebase against main.
I also keep a small helper when I want to rebase a specific number of recent commits:
reb() {
git rebase -i "HEAD~$1"
}For example:
reb 4opens an interactive rebase for the last four commits.
For quick corrections to the previous commit:
alias amend="git commit --amend --reuse-message=HEAD"So:
git add .
amendamends the staged changes into the previous commit without changing its message.
Undoing and inspecting
I also keep a few shortcuts for when I need to back up or inspect a repository:
alias gundo="git reset --soft HEAD~1"
alias gres="git reset"
alias glfm="git fetch && git reset origin/main --hard"gundo is useful when I want to undo the last commit but keep the changes
staged.
glfm is deliberately more destructive: it resets the current branch to the
remote main, so I only use it when I’m sure I want to discard the local
state.
Searching Git history
A couple of small helpers make it easier to find things when I only remember part of the history:
fb() {
git branch -a --contains "$1"
}
fm() {
git log --pretty=short --grep="$1"
}For example:
fb abc1234shows branches containing a commit.
And:
fm "docker"searches commit messages for docker.
A few commands I don’t type often enough to alias
Sometimes the normal Git command is clearer:
git branch --all
git remote --verbose
git tag --listI prefer not to turn every command into an alias just because I can.
One alias I use with caution
I keep:
alias gpf="git push -f"because force-pushing is sometimes necessary, but this is one of those shortcuts where the convenience comes with a sharp edge.
Docker
For Docker, I mostly want shorter versions of commands I already know.
alias dps="docker ps -a"
alias dc="docker compose"
alias dcu="dc up -d"
alias dcd="dc down"
alias dcr="dcd && dcu"
alias dcl="dc logs -f"That turns:
docker compose up -dinto:
dcuand:
docker compose logs -finto:
dclI also have a small helper for opening a shell inside a running container:
dsh() {
docker exec -it "$1" /bin/sh
}For example:
dsh my-containerThere is also a helper I use for quickly building and running a Dockerfile:
dbar() {
docker run --rm -it "$(docker build --no-cache -q .)"
}It’s useful when I just want to test what’s currently in a Dockerfile without creating a long-lived container.
Node.js and package managers
When working across different JavaScript projects, I like short aliases for package manager commands:
alias npr="npm run"
alias yar="yarn run"
alias pnpr="pnpm run"So instead of:
pnpm run lintI can use:
pnpr lintI also keep shortcuts for doing a completely fresh dependency install:
alias fresh_npm="rm -rf node_modules package-lock.json && npm install"
alias fresh_yarn="rm -rf node_modules yarn.lock && yarn install"
alias fresh_pnpm="rm -rf node_modules pnpm-lock.yaml && pnpm install"These deliberately remove the lockfile as well, so I only use them when I actually want to regenerate the dependency tree.
For normal dependency problems, deleting node_modules while keeping the
lockfile is usually the safer first step.
Open the current project in VS Code
A very small one:
alias vs="code ."From any project directory:
vsopens the current directory in VS Code.
Networking
A few aliases make checking network information quicker.
Public IP
alias ipv4="curl -4 simpip.com --max-time 1 --proto-default https --silent"
alias ipv6="curl -6 simpip.com --max-time 1 --proto-default https --silent"
alias ip="ipv4; ipv6"So:
ipprints both the public IPv4 and IPv6 addresses when available.
Local IP
On macOS:
alias ip-local="ipconfig getifaddr en0"This is useful when I just need the local address of the active interface.
The little things
A few miscellaneous shortcuts have survived simply because I still use them:
alias screenfetch="neofetch"And because I often want the weather without opening a browser:
alias weather="curl 'https://wttr.in/Gothenburg?format=v2'"The point of aliases
I don’t try to turn every command into an alias.
The useful ones are the commands I run often enough that the shorter version actually improves the workflow.
A good alias should make the common case faster without making the command mysterious.
For anything important or destructive, I still want the full command to be easy to understand.
My dotfiles
The aliases above are part of my larger shell configuration: