Skip to content

Instantly share code, notes, and snippets.

@sebnyberg
Created December 2, 2024 07:03
Show Gist options
  • Save sebnyberg/9fdd402891ca06b4416ad999015f4c4c to your computer and use it in GitHub Desktop.
Save sebnyberg/9fdd402891ca06b4416ad999015f4c4c to your computer and use it in GitHub Desktop.
Random command snippets

Random command snippets

Git

# search for commits with changes to files with name <pattern>
git log -S<pattern> --stat

 # search for commits with changes containing <pattern>
git log -G<pattern>

# show file without changing branch
git show <commitsha>:path/to/file

 # check out old directory to tmp/
git --work-tree tmp/ checkout <commitsha> -- path/to/dir

Grep

$ grep -Rn --color <pattern> <directory>

Python

List poetry/pip packages by size

#!/usr/bin/env bash

poetry run pip list \
  | awk 'NR > 2 {print $1}' \
  | sort -r \
  | awk 'NR > 2 {print $1}' \
  | xargs poetry run pip show  \
  | grep -E 'Location:|Name:' \
  | cut -d ' ' -f 2 \
  | paste -d ' ' - - \
  | awk '{print $2 "/" tolower($1)}' \
  | xargs du -sh 2> /dev/null \
  | sort -hr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment