Unix shell tricks for developing Qt: Difference between revisions

From Qt Wiki
Jump to navigation Jump to search
 
Line 28: Line 28:


<code lang="bash">
<code lang="bash">
alias git-cleanall='git submodule foreach --recursive "git clean -dfx"
alias git-cleanall='git submodule foreach --recursive "git clean -dfx"'
</code>
</code>



Latest revision as of 02:46, 18 May 2017


Here are some aliases and tools that can be useful in a shell session on Linux or macOS (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, for example in /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 "git clean -dfx"'

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'