Skip to content

Instantly share code, notes, and snippets.

@hdevilbiss
Last active November 29, 2025 17:53
Show Gist options
  • Select an option

  • Save hdevilbiss/9ef364f2af6ecfafddecaaf457f8e253 to your computer and use it in GitHub Desktop.

Select an option

Save hdevilbiss/9ef364f2af6ecfafddecaaf457f8e253 to your computer and use it in GitHub Desktop.
Collection of commands. WP CLI, Linux, Git

List of Favorite Computer Programming Commands

Windows cmd

Install programs on drives other than C:\. Useful when hard drives fail and programs need to be reinstalled; the old references block new installation. Also useful when the main C:\ drive is small, and the program installer does not offer the option of choosing the install location.

start someProgramInstaller.exe /DIR="D:\Programs\Folder\On\Another\Drive\ProgramName"

Source: https://knowledgebase.jam-software.com/7573

VSCode

Working with Python in VSCode 🐍

Setting up a new project

  1. Create a new virtual environment, if needed. py -m venv .venv
  2. Change the interpreter path, if needed. CTRL + SHIFT + P
  3. Install pip-tools in the virtual environment, if starting for the first time:
    • .venv/Scripts/activate
    • pip install pip-tools

Working on the project

  1. Start the virtual environment. .venv/Scripts/activate
  2. Compile the requirements using pip. pip-compile requirements.in
  3. Sync the requirements. pip-sync requirements.txt

Shortcuts πŸͺœ

  • πŸ›Έ Select entire line: CTRL+L
  • πŸ›ΈπŸ›ΈπŸ›Έ Select all occurences: CTRL+SHFT+L
  • Collapse the whole file: CTRL + K + 0
  • Expand the whole file: CTRL + J + 0
  • "There is a problem in this file": CTRL + SHIFT + M
  • Comment or Uncomment: CTRL + /
  • Quickly move lines or blocks up: ALT + UP ARROW
  • Quickly move lines or blocks down: ALT + DOWN ARROW
  • Find settings.json on Windows 10: $HOME/AppData/Roaming/Code/User/settings.json

Modify the PowerShell Prompt String πŸ’²

PowerShell is the default terminal at least in my installation of VSCode. My favorite terminal appearance is to show the current folder, in a bold green, followed by the greater than sign, >. To do this, add a prompt function to your PowerShell profile. Choose your own colors, besides green.

Assumption: Get-ExecutionPolicy -List returns RemoteSigned for the current scope.

C:\Users\MyUserName\Documents\WindowsPowerShell\profile.ps1

function prompt {
    $Host.ui.rawui.foregroundcolor = "Green"
    "$([char]27)[1m" + $(Get-Location).Path.Substring((Get-Location).Path.LastIndexOf("\")+1) + " > " 
}

Linux

Linux on Windows

  1. Install Windows Subsystem for Linux to get a Linux shell for Windows.
  2. Enter wsl into PowerShell (or your shell of choice) to get started.

πŸ” Search current directory and subfolders for specific text

The search term font-size: 12px is just an example; replace this text with the search pattern.

grep -Rnw . -e 'font-size: 12px';

Source: rakib and CodeWizard on StackOverflow

Sort Disc Usage for all Folders β‰₯ 1 GB πŸ—„οΈ

du -h --threshold=1G

Sort disc usage by file size ♻️

du -sh -- * | sort -h

Display octal file permissions πŸ”’

Such as 644 or 777.

stat -c "%a %n" *

Adding SSH key(s) πŸ”‘

eval "$(ssh-agent -s)"
ssh-add /mnt/c/Users/Username/.ssh/private_openssh

Remote Sync ⏭

rsync: Sync folders and files between a remote server and a local server.

Examples:

  • Sync from a remote server to a local server.
  • Sync between 2 remote servers.
  • WordPress usage: Sync uploads, themes, and plugins.

Source (Remote): [email protected]:/www/path/public/shared/web/app/uploads/

Destination (Local): /mnt/c/destination/uploads/ (also known as C:\destination\uploads)

Remote Sync Dry-run ⏭❓

rsync -av --dry-run -e 'ssh -i /local/path/to/public_id_rsa -p 22' [email protected]:/source/home/username/domains/example.com/shared/web/app/uploads /mnt/c/destination/uploads/

Remote Sync Regular Run ⏭❗

Remove the --dry-run flag.

rsync -av --progress --delete -e 'ssh -i /path/to/id_rsa -p 22' /mnt/c/source/themes/my-theme/ username@IP:/destination/home/username/domains/example.com/path/to/themes/my-theme/

Notes:

  • Add the --dry-run flag to test the SSH connection from the shell and show which files will be transferred.
  • The $HOME variable will not be the same locally and remotely.
  • The trailing / in uploads/ performs an inner copy, targeting all the files and folders inside of uploads. If the trailing forward slash "/" were omitted, then a new folder would be created inside of the destination uploads folder: /mnt/c/source/uploads/uploads/
  • Consider adding the --progress flag.
  • Carefully consider adding the --delete flag to delete files from the destination, which are not present in the source. Use --delete with caution to avoid losing data!
    • I generally only use --delete to sync development uploads with production so that it exactly matches production.
    • Another common use for --delete is backing up plugin folders before testing new versions. And if the new plugin files need to be overwritten, the --delete flag removes any new files.
  • Use the --exclude tag to exclude files or directories; useful for --exclude={'composer.json', 'composer.lock'} and/or --exclude '.git/'

Git

Push to a remote subtree.

git subtree push --prefix=path/to/subdir remote-name ref

For example: A static site generator uses a separate remote repository for its theme files.

  1. The path/to/subdir theme is installed at themes/theme-name.
  2. The remote-name was established with git remote add -f theme-name https://github.com/username/theme-name.git
  3. The ref could be master, main, or whichever branch on the remote to be targeted.

Modify the Bash Prompt String

Make the Bash prompt string a bold green, followed by a dollar sign.

Edit the ~/.bashrc file using your editor of choice.

Add an export statement to .bashrc, defining:

  • green-text,
  • the most current folder in path,
  • a couple of spaces, and
  • the $ sign.
export PS1="\[\033[01;32m\]\W \\$ \[$(tput sgr0)\]"

WP-CLI

Command Line Interface for WordPress.

Create new .env file with salts

Install this WP-CLI extension: wp-cli-dotenv-command

Use the wp dotenv init command to create a new environment file with salts:

wp dotenv init --template=".env.example" --with-salts

Check which plugins need update

wp plugin update --all --dry-run

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment