Skip to navigation

Linux VM Tips and Tricks

Shell Configuration

This works well in $HOME/.bashrc on your Linux VM. It enhances the user experience by setting some nice configuration for each shell.

Bash startup

$HOME/.bashrc
# Some things I like in the PATH (don't judge me)
export PATH="$HOME/bin:./node_modules/.bin:$PATH"
# Set this to what you like for your user@host
_ps_who_at_where="jckell@dev524"
# A few of the color definitions for the terminal
normal="\[$(tput sgr0)\["
red="\[$(tput setaf 1)\]"
green="\[$(tput setaf 2)\]"
blue="\[$(tput setaf 4)\]"
cyan="\[$(tput setaf 6)\]"
# Function to print a colored representation of $? for the prompt
echo_last_status() {
if [ $? -eq 0 ]; then
echo "${green}0${normal}"
else
echo "${red}$?${normal}"
fi
}
# Custom prompt showing last status, who@where, cwd and $ for non-root, # for root
PS1="${normal}(\$(echo_last_status))${blue}$_ps_who_at_where${normal}:${cyan}\w${green}\$${normal} "
# Add color to diff & ip because it got missed
alias diff='diff --color=auto'
alias ip='ip --color=auto'
# Colorize less & man (that horrible mess at the end says which colors)
export LESS='-R --use-color -Dd+51$Du+44$'
# Put me in California for the timezone (Chicago for Central Time)
export TZ=America/Chicago
# npm completions for bash (ask me for this or download from git repo for bash)
[ -s "$HOME/etc/npm-completions.bash" ] && \. "$HOME/etc/npm-completions.bash"
# NVM and NVM completions (Needed to make nvm work (comes with nvm)
export NVM_DIR="$HOME/.nvm"
# This defines all the parts of nvm (shell aliases and functions)
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
# This enables bash completions for nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"

Readline (used by bash to handle what you type)

$HOME/.inputrc
# Rebind ctrl+t (was transpose) to use it for quoted-insert (usually ctrl+v)
"\C-t": quoted-insert

Nicer docker ps output

Add this property to your $HOME/.docker/config.json:

"psFormat": "table {{.ID}}\t{{.Names}}\t{{.Image}}\t{{.Status}}"

Quiet shell startup

Create an empty file called $HOME/.hushlogin (touch $HOME/.hushlogin)

Fewer issues with docker mounts and permissions

Create a folder like $HOME/var/docker/mount and put a folder in there for each service you want to mount things for and put the things you want to mount in those subfolders. So, for example, if you want to mount a file called Config.json in a docker container for the service_bus service you would have it in $HOME/var/docker/mount/service_bus. If anything gets assigned to root you can then take that folder $HOME/var/docker/service_bus and move it to the /tmp folder and create a new one to hold the Config.json file and you will be fine. All files in the /tmp folder get deleted when the Linux VM is restarted.

VSCode Configuration

settings.json

For each of the code sections below we are talking about a set of properties in JSON format that can be added to your settings.json file for vscode. Each section tells a little about the purpose of those properties. These are currently listed in no particular order.

Diff will ignore whitespace by default
"diffEditor.ignoreTrimWhitespace": false
ESLint “fix” will run and fix all problems when you save
"editor.codeActionsOnSave": {
"source.fixAll": "always"
},
"editor.minimap.enabled": false,
"git.autofetch": true,
"git.mergeEditor": true,
Things I like the editor to do when I write code

The inseetSpace… ones are to keep the editor from helping me too much. The autoImport… ones prevent automatic import of node:test because we are not using it. It helps autoimport find vitest instead. And that last one is because I don’t usually mean to do “deconstruct to a new name” like {original: aliased} if I try to rename original. I mean to just change it directly.

"javascript.format.insertSpaceAfterFunctionKeywordForAnonymousFunctions": false,
"javascript.format.insertSpaceAfterOpeningAndBeforeClosingEmptyBraces": false,
"javascript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces": false,
"javascript.preferences.autoImportSpecifierExcludeRegexes": [
"^node:test$"
],
"typescript.preferences.autoImportSpecifierExcludeRegexes": [
"^node:test$"
],
"typescript.preferences.useAliasesForRenames": false,
Launch configurations for debugging (not in container)
"launch": {
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Start",
"runtimeExecutable": "npm",
"cwd": "${workspaceFolder}",
"args": [
"start"
],
"console": "integratedTerminal"
},
{
"type": "node",
"request": "launch",
"name": "Test",
"runtimeExecutable": "npm",
"cwd": "${workspaceFolder}",
"args": [
"test"
],
"console": "integratedTerminal"
}
]
},
"search.exclude": {
"coverage": true,
"**/node_modules/.cache": true,
".env": false,
"**/node_modules": false
},
"search.useIgnoreFiles": false,
Opening a folder opens a new vscode instance
"window.openFoldersInNewWindow": "on",
No “splash” or “editor” open when vscode starts
"workbench.startupEditor": "none"

tasks.json

The example tasks.json file below defines a task that can be used to run ESLint on all the files in the project. One really useful thing about this task is that it will add problem markers to vscode that can show up in the appropriate panel about PROBLEMS. It has one problem per row and they are clickable and take you to the place where the problem was found in the code directly. The task provided by the ESLint plugin works pretty well, but this gives better feedback in my opinion. When there are no problems it will output a “0” to the task output. That way you can tell when it completes the lint check even if there are no problems.

{
"version": "2.0.0",
"tasks": [
{
"label": "Lint All",
"type": "shell",
"command": "eslint . && echo STATUS=$?",
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "dedicated",
"revealProblems": "onProblem",
"showReuseMessage": false,
"clear": true
},
"problemMatcher": [
"$eslint-stylish"
]
}
]
}