Unix shell tricks for developing Qt

From Qt Wiki
Revision as of 09:09, 10 March 2015 by Shawnrutledge (talk | contribs) (moved from the hyphenated version)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search


Here are some aliases and tools that can be useful in a shell session on Linux or Mac OSX (or Windows if you are using the version of bash that comes with the git installation).

git-prompt.sh

Many distribution packages of git include this shell script, possibly /usr/share/git. It may or may not be installed in such a way that it gets parsed in every new login shell; if not, you can add to your own ~/.bashrc

source /usr/share/git/git-prompt.sh

It will create some bash command completions, so you can e.g. type git l<tab> to complete the git log command. It also defines _git_ps1, which can be used as part of your customized shell prompt (preferably including ANSI colors, the time, current directory, the Qt version currently chosen for qtchooser, etc.); you can test it like this

$ echo $(''_git_ps1)
(dev>)

The output means that I'm on "dev" branch and have committed all of my local changes which have not yet been integrated. However, this can slow down your shell when changing directories, because quite some disk activity is necessary to generate that single final character of status.

Aliases

These are my favorites so far:

alias git-foreach='git submodule foreach ?recursive'

is convenient for things like git-foreach 'git pull ?rebase' to update all submodules to the latest versions of their respective branches (but you could make another alias for that).

alias git-cleanall='git submodule foreach ?recursive '#39;'git clean -dfx'#39;

I use git-cleanall at the top of the repository cloned from qt5.git to ensure that there are no leftover object files before starting a clean build. However, it's better to use shadow builds (run configure and make in a different directory so that the build output stays out of your source tree); the main reasons are that you can use one source tree to build debug and release builds (even for multiple platforms) separately, and your source tree is always clean. But sometimes I still build examples and tests in the source tree, selectively.

alias glog='git log ?pretty=format:"%C (auto)%h %C (auto)%d %C (reset) %s %C (green)(%cr)%C (blue)[%an]%C (reset)" -n10'

glog is for showing a short log of the last 10 changes, and highlighting the point at which your local changes diverge from the integrated changes that you got from the remote.

Logging changes in all submodules at once

For that I have a shell script, ~/bin/glogg, like glog but with an extra 'g' to indicate that it does more ;-) (BTW "gløgg" is also a nice Norwegian onomatopoeic word for warm, spiced wine, something like wassail; so using this command gives you a warm Christmas feeling.)

#!/bin/bash
git submodule foreach --recursive --quiet 'echo --- $name  `git rev-parse --abbrev-ref HEAD`; git log --pretty=oneline --decorate=short --abbrev-commit --date=relative @{u}...HEAD --boundary'