Short snippets

These short bash commands or code snippets have proven useful. I will try to collect them here, and maybe freeze some of them into a proper .bashrc (and the relevant equivalent on Windows). Alternatively, I could bundle related snippets into blog posts. Or I finally start one of those .dotfiles repositories. But then, I don't want to over-engineer my settings handling. Let's see where this goes.

Convert pictures to lower resolution in subfolder

Using ImageMagick (version 7), this is a handy one-liner, ready to be integrated into an only slightly longer script, moving the result to a fixed, desired output location:


mkdir export && magick mogrify -resize 3000x3000 -quality 80 -path export *.jpg


mkdir (get-item $PWD).Name; magick mogrify -resize 3000x3000 -quality 80 -path (get-item $PWD).Name *.jpg

Git config

First, the full configuration, then some comments by section:

	ui = auto
	defaultBranch = main
	al = "!git config -l | grep "^alias" | cut -c 7-"
	bl = for-each-ref --format='%(align:50,left)%(color:bold green)%(refname:short)%(color:reset)%(end)%0a  %(color:dim green)%(objectname:short)%(color:reset) %(color:dim cyan)%(authordate:short)%(color:reset) %(color:cyan)%(authorname)%(color:reset) %(subject)%0a' --sort=-authordate refs/heads/
	ce = config --global --edit
	d = diff
	dc = diff --cached
	lg = log --pretty=tformat:'%C(dim white)%m%C(dim green)%h %C(dim cyan)%cd %C(reset)%<(50,trunc)%s %C(cyan)%aN%C(reset)%C(auto)%w(0,0,8)%+d%C(reset)' --decorate --graph
	ll = log --pretty=format:'%C(dim white)%m%C(dim green)%h %C(dim cyan)%cd %C(reset)%s %C(cyan)%aN%C(auto)%w(0,0,8)%+d%Creset' --decorate --name-status
	ls = log --pretty=format:'%C(dim white)%m%C(dim green)%h %C(dim cyan)%cd %C(reset)%s %C(cyan)%aN%C(auto)%d%Creset' --decorate --date=short
	nl = "!author_names() { git log --pretty=format:'%aN' -- "${@-.}" | sort | uniq -c | sort -n -r; }; author_names"
	s = status
	tool = vimdiff
	date = format:%Y-%m-%d %H:%M
	graphColors = 1,2,3,4,5,6,7,8,46,63,124,136,148,160,172,184,196,208,201,220,228
	default = simple
	ff = only
	editor = vim


My main workhorse in day-to-day work is the lg (log graph) command, allowing for a quick overview on latest changes with git lg --all after a fetch. In case I want briefer output for a linear slice of commits, I use ls short (no graph). If I want to additionally see the changed files, ll (log long) can be used. Meta-alias al (alias list) does exactly that.

Saying git dc instead of git diff --cached for a commit preview is very nice. I hardly remember the git d instead of git diff, though. But then, typing that out does not hurt too much. Newcomer: bl (branch list) lists all local branches, together with its latest commit. It's designed to look similar to the output of lg. I might extend it to output remotes in red; it already can list them by calling git bl refs/remotes.

The nl (name list) lists all commit authors for the current state (HEAD). The optional argument allows to specify a directory or file, by default it operates on the current working directory (.). Quite useful to quickly determine the contributors for a particular component.

See chapter 2.7 Git Basics - Git Aliases from the Git Book for other generally useful aliases. I kind of like unstage, but have already embraced the concept behind reset HEAD, so I am too late for that alias.


It's easier on the (ok, my) brain to switch from tool to tool without having to transfer from CLI to GUI window. But that's just opinion.


My preferred ISO-inspired default date format, but without the unneeded precision of seconds. Date and time are split by a space, not the standard T which makes 20010214T2359 easier to parse, but harder to read. The graphColors allow to specify which of the (typically) 256 terminal colours are used to differentiate between different branches. Here I recommend using much more than the (randomly) chosen 5 values I have shown here.

snippets.txt · Zuletzt geändert: 2022/11/03 09:45 von ojdo