Unix shell tricks for developing Qt: Difference between revisions
m (→git-prompt.sh) |
|||
(7 intermediate revisions by 4 users not shown) | |||
Line 1: | Line 1: | ||
[[Category:HowTo]] | [[Category:HowTo]] | ||
[[Category:Developing_with_Qt | [[Category:Developing_with_Qt]] | ||
Here are some aliases and tools that can be useful in a shell session on Linux or | 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== | ==git-prompt.sh== | ||
Many distribution packages of git include this shell script, for example in <tt>/usr/share/git</tt>. 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 <tt>~/.bashrc</tt> | Many distribution packages of git include this shell script, for example in <tt>/usr/share/git</tt>. 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 <tt>~/.bashrc</tt> | ||
<code lang="sh"> | |||
< | source /usr/share/git/git-prompt.sh | ||
</code> | |||
It will create some bash command completions, so you can e.g. type <tt>git l<tab></tt> to complete the <tt>git log</tt> command. It also defines <tt> | It will create some bash command completions, so you can e.g. type <tt>git l<tab></tt> to complete the <tt>git log</tt> command. It also defines <tt>__git_ps1</tt>, 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 | ||
<code lang="sh"> | |||
< | $ echo $(__git_ps1) | ||
(dev>) | (dev>) | ||
</ | </code> | ||
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. | 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. | ||
Line 22: | Line 21: | ||
These are my favorites so far: | These are my favorites so far: | ||
< | <code lang="bash"> | ||
alias git-foreach='git submodule foreach --recursive' | |||
</code> | |||
is convenient for things like <tt>git-foreach 'git pull | is convenient for things like <tt>git-foreach 'git pull --rebase'</tt> to update all submodules to the latest versions of their respective branches (but you could make another alias for that). | ||
< | <code lang="bash"> | ||
alias git-cleanall='git submodule foreach --recursive "git clean -dfx"' | |||
</code> | |||
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. | 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. | ||
< | <code lang="bash"> | ||
alias glog='git log | alias glog='git log --pretty=format:"%C(auto)%h %C(auto)%d %C(reset) \ | ||
</ | %s %C(green)(%cr)%C(blue)[%an]%C(reset)" -n10' | ||
</code> | |||
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. | 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. | ||
Line 39: | Line 43: | ||
For that I have a shell script, <tt>~/bin/glogg</tt>, 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.) | For that I have a shell script, <tt>~/bin/glogg</tt>, 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.) | ||
< | <code lang="bash"> | ||
#!/bin/bash | #!/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' | 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' | |||
</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'